예제 #1
0
def setUpModule():
    logger.title('SETTING UP TESTS...')
    logger.title('REVIT {}'.format(version))
    collector = DB.FilteredElementCollector(doc)
    walls = collector.OfClass(DB.Wall).ToElements()
    if walls:
        t = DB.Transaction(doc, 'Delete Walls')
        t.Start()
        for wall in walls:
            doc.Delete(wall.Id)
        t.Commit()
    collector = DB.FilteredElementCollector(doc)
    level = collector.OfClass(DB.Level).FirstElement()
    pt1 = DB.XYZ(0, 0, 0)
    pt2 = DB.XYZ(20, 20, 0)
    wall_line = DB.Line.CreateBound(pt1, pt2)

    t = DB.Transaction(doc, 'Add Wall')
    t.Start()
    wall = DB.Wall.Create(doc, wall_line, level.Id, False)
    t.Commit()
    global wall_int
    wall_int = wall.Id.IntegerValue
    logger.debug('WALL CREATED.')

    collector = DB.FilteredElementCollector(doc)
    desk = collector.OfCategory(
        DB.BuiltInCategory.OST_Furniture).FirstElement()
    if desk:
        with rpw.Transaction('Delete Desk'):
            f = desk.Family
            doc.Delete(f.Id)

    ##################################################
    # Load Fixture Family and Place Instances
    ##################################################
    logger.debug('LOADING SYMBOl')
    family_path = os.path.join(test_dir, 'fixtures', 'desk.rfa')
    if not os.path.exists(family_path):
        raise Exception('Could not find fixture: {}'.format(family_path))

    logger.debug('LOADING SYMBOl')
    family = clr.Reference[DB.Family]()
    with rpw.Transaction('Load Family'):
        doc.LoadFamily(family_path, family)
        family = family.Value
        symbols = []
        for family_symbol in family.Symbols:
            symbols.append(family_symbol)
    with rpw.Transaction('Place Instances'):
        level = DB.FilteredElementCollector(doc).OfClass(
            DB.Level).WhereElementIsNotElementType().FirstElement()
        doc.Create.NewFamilyInstance(DB.XYZ(5, 0, 0), symbols[0], level,
                                     DB.Structure.StructuralType.NonStructural)
        doc.Create.NewFamilyInstance(DB.XYZ(10, 4, 0), symbols[0], level,
                                     DB.Structure.StructuralType.NonStructural)
        doc.Create.NewFamilyInstance(DB.XYZ(15, 8, 0), symbols[1], level,
                                     DB.Structure.StructuralType.NonStructural)
예제 #2
0
def create_finish_wall(room, wall_type, wall_height):
    offset_distance = wall_type.parameters['Width'].AsDouble() * 0.5
    boundary_loops = get_boundaries(room)
    # print(boundary_loops)
    for boundary in boundary_loops:
        curveloop = curveloop_from_boundary(boundary)

        offset_curveloop = CurveLoop.CreateViaOffset(curveloop, offset_distance,
                                                     curveloop.GetPlane().Normal)
        if not is_inside_room(offset_curveloop, room):
            offset_curveloop = CurveLoop.CreateViaOffset(curveloop, -offset_distance,
                                                         curveloop.GetPlane().Normal)
        new_walls = []
        with rpw.db.Transaction('Create Finish Wall'):
            for curve in offset_curveloop:
                new_wall = Wall.Create(doc, curve, wall_type.Id, room.LevelId,
                                       wall_height/304.8, 0, False, False)
                new_walls.append(new_wall)
        with rpw.db.Transaction('Join old-new walls'):
            for idx, new_wall in enumerate(new_walls):
                old_wall = doc.GetElement(boundary[idx].ElementId)
                if old_wall:
                    try:
                        JoinGeometryUtils.JoinGeometry(doc, old_wall, new_wall)
                    except Exception as e:
                        print(e)
        with rpw.db.Transaction('Delete short walls'):
            for new_wall in new_walls:
                length = new_wall.LookupParameter('Length').AsDouble() * 304.8
                if length < 50:
                    doc.Delete(new_wall.Id)
예제 #3
0
 def make_wall():
     walls = []
     wallfaces = self.RoomFaceWall()
     # l:EdgeLoop->[List<CurveLoop>]  n:edgeNormal w:_WallId
     for l, n, w in zip(wallfaces[0], wallfaces[1], wallfaces[2]):
         transform = DB.Transform.CreateTranslation(
             self.WallFinishType.Width / 2 * (-n))
         newLines = List[DB.Curve]()
         for i in l:
             newCurveLoop = DB.CurveLoop.CreateViaTransform(
                 i, transform)
             CurveInterator = newCurveLoop.GetCurveLoopIterator()
             for c in CurveInterator:
                 newLines.Add(c)
         OldWall = doc.GetElement(w)
         #TODO There are some proble
         try:
             NewWall = DB.Wall.Create(doc, newLines,
                                      self.WallFinishTypeId,
                                      self.RoomLevelId, None)
             NewWall.get_Parameter(
                 DB.BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(0)
         except:
             NewWall = None
         try:
             DB.JoinGeometryUtils.JoinGeometry(doc, NewWall, OldWall)
             walls.append(NewWall)
         except:
             if NewWall != None:
                 doc.Delete(NewWall.Id)
             walls.append(None)
     return walls
예제 #4
0
def ResetColumnToInstance(Element):
    for element in Element:
        try:
            level = doc.GetElement(element.LevelId)

            baseLevel = element.Parameter[
                DB.BuiltInParameter.FAMILY_BASE_LEVEL_PARAM]
            topLevel = element.Parameter[
                DB.BuiltInParameter.FAMILY_TOP_LEVEL_PARAM]
            baseOffset = element.Parameter[
                DB.BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM]
            topOffset = element.Parameter[
                DB.BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM]

            elementLocation = element.Location.Point
            elementSymbol = element.Symbol

            #elementFamily = elementSymbol.Family

            newElementInstance = doc.Create.NewFamilyInstance(
                elementLocation, elementSymbol, level,
                DB.Structure.StructuralType.Column)

            newElementInstance.Parameter[
                DB.BuiltInParameter.FAMILY_BASE_LEVEL_PARAM].Set(
                    baseLevel.AsElementId())
            newElementInstance.Parameter[
                DB.BuiltInParameter.FAMILY_TOP_LEVEL_PARAM].Set(
                    topLevel.AsElementId())
            newElementInstance.Parameter[
                DB.BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM].Set(
                    baseOffset.AsDouble())
            newElementInstance.Parameter[
                DB.BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM].Set(
                    topOffset.AsDouble())
            #topOffset.Set(newElementInstance.Id)
            print("ID{}Done".format(element.Id))
            doc.Delete(element.Id)

        except Exception as e:
            print("ID{}Wrong".format(element.Id))
예제 #5
0
def ResetBeamToInstance(Element):
    for element in Element:
        try:
            level = doc.GetElement(element.LevelId)

            referenceLevel = element.Parameter[
                DB.BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM]
            startLevelOffset = element.Parameter[
                DB.BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION]
            endLevelOffset = element.Parameter[
                DB.BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION]

            elementLocation = element.Location.Curve
            elementSymbol = element.Symbol

            #elementFamily = elementSymbol.Family

            newElementInstance = doc.Create.NewFamilyInstance(
                elementLocation, elementSymbol, level,
                DB.Structure.StructuralType.Beam)

            newElementInstance.Parameter[
                DB.BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM].Set(
                    referenceLevel.AsElementId())
            newElementInstance.Parameter[
                DB.BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION].Set(
                    startLevelOffset.AsDouble())
            newElementInstance.Parameter[
                DB.BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION].Set(
                    endLevelOffset.AsDouble())
            #topOffset.Set(newElementInstance.Id)
            print("ID{}Done".format(element.Id))
            doc.Delete(element.Id)

        except Exception as e:
            print(e)
            print("ID{}Wrong".format(element.Id))
예제 #6
0
    # Duplicating wall type
    tmp = duplicate_wall_type(new_wall.wall_type)

    # Creating wall
    for new_wall in new_walls:
        make_wall(new_wall, tmp)

    # Changing wall type back
    for n in wallz:
        #changetype(n,new_wall.wall_type)
        n.ChangeTypeId(new_wall.wall_type.Id)
        n.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM).Set(3)

    # Deleting temp wall type
    doc.Delete(tmp.Id)

    #Joining finishing walls with it's host objects
    for wall1 in new_wall.bound_walls:
        for wall2 in wallz:
            try:
                Autodesk.Revit.DB.JoinGeometryUtils.JoinGeometry(
                    doc, wall1, wall2)
            except:
                pass
    for n in wallz:
        for m in wallz:
            try:
                Autodesk.Revit.DB.JoinGeometryUtils.JoinGeometry(doc, n, m)
            except:
                pass
예제 #7
0
        for gen_mod in local_gen:
            bbx_ft_tuple = gen_mod.LookupParameter("Creating_bbox").AsString()
            bbox_not_obsolete = query_bbox_exists_in_cache(
                bbx_ft_tuple, bbx_ft_cache_remote)
            if not bbox_not_obsolete:
                gen_mod.LookupParameter("Comments").Set(
                    "void_obsolete: {}".format(time_stamp))
                print("not found -> obsolete: {}, coord: {}".format(
                    gen_mod.Id.IntegerValue, bbx_ft_tuple))
                obsolete_counter += 1

            # expand void antennas
            expand_contract_void(gen_mod, raw_lvl_elevations, expand=True)

        # remove temporary link
        doc.Delete(rvt_link.Id)
        doc.Delete(rvt_link_type.ElementId)

# report for user
print(50 * "-")
print(str(types_created) + " new void size types created.")
print("{} voids found in linked model.".format(str(found_counter).zfill(4)))
print("{} voids were created.".format(str(created_counter).zfill(4)))
print("{} voids already existed.".format(
    str(existed_already_counter).zfill(4)))
print("{} voids are obsolete.".format(str(obsolete_counter).zfill(4)))
print("HdM_pyRevit nestedRevitDurchbruchCutter run in: ")

stopwatch.Stop()
timespan = stopwatch.Elapsed
print(timespan)
예제 #8
0
                                void_height,
                                lvl_cat.OKRB_elevations,
                                expand_levels=(raw_lvl_above, raw_lvl_below))

            dprint("-found closest raw levels: {}\n{}\n{}".format(
                closest_raw_lvl.Name,
                raw_lvl_above.Name,
                raw_lvl_below.Name,
            ))

            gen_mod.LookupParameter("Closest_raw_level").Set(
                closest_raw_lvl.Name)
        else:
            expand_void_antenna(gen_mod, void_height, lvl_cat.OKRB_elevations)

    doc.Delete(link_inst.Id)
    doc.Delete(rvt_link_type.ElementId)
    output.update_progress(prog_bar_total, prog_bar_total)

dprint(70 * "-")
dprint("{} coordinates of obsolete voids:".format(
    counter["voids_existing_obsolete"]))
for coord in obsolete_coords:
    dprint(coord)

print(70 * "-")
print("ids of {} obsolete voids:".format(counter["voids_existing_obsolete"]))
for void_id in obsolete_ids:
    print(output.linkify(void_id))
print(70 * "-")
print("new voids that did not cut anything:")
예제 #9
0
def DeleteFamilyInstance(FamilyInstanceId):
    doc.Delete(FamilyInstanceId)
예제 #10
0
# -*- coding: utf-8 -*-
'''
Delete single rebar bars in active view
'''
__title__ = 'Delete\nSingle Rebars'
__author__ = 'htl'

import clr
clr.AddReference('RevitAPI')

import Autodesk

import rpw
from rpw import doc

single_rebars = rpw.db.Collector(of_class=Autodesk.Revit.DB.Structure.Rebar,
                                 view=doc.ActiveView,
                                 where=lambda x: x.LayoutRule == Autodesk.Revit
                                 .DB.Structure.RebarLayoutRule.Single)

with rpw.db.Transaction('Delete single rebars'):
    for bar in single_rebars:
        doc.Delete(bar.Id)
예제 #11
0
 def tearDown(self):
     collector = rpw.Collector()
     levels = rpw.Collector(of_class=DB.Level).elements
     with rpw.Transaction('Delete Test Levels'):
         for level in levels[1:]:
             doc.Delete(level.Id)
예제 #12
0
 def tearDownClass(cls):
     doc.Delete(cls.column.Id)
     doc.Delete(cls.axis.Id)
예제 #13
0
                               cropbox_width_px, cropbox_height_px)
    new_img_path = crop_image(img_path, rectangle_crop)

    # New Image Options
    import_options = ImageImportOptions()
    import_options.Placement = BoxPlacement.Center
    import_options.RefPoint = get_bbox_center_pt(element_bbox)
    import_options.Resolution = img_resolution

    # Create New Image in Revit
    with rpw.db.Transaction('Crop Image'):
        new_img_element = StrongBox[Element]()
        doc.Import(new_img_path, import_options , doc.ActiveView, new_img_element)
        new_img_width = new_img_element.get_Parameter(bip_width_ft)
        new_img_width.Set(cropbox_width_ft)
        doc.Delete(img_element.Id)
        doc.Delete(element.Id)



    print('Img Width: {} ft'.format(img_width))
    print('Img Height: {} ft'.format(img_height))
    print('Img Pxl Width: {} px'.format(img_width_px))
    print('Img Pxl Height: {} px'.format(img_height_px))
    print('Img Resolution: {} DPI'.format(img_resolution))
    print('='*50)
    print('Crop Width FT: {} ft'.format(cropbox_width_ft))
    print('Crop Height FT: {} ft'.format(cropbox_height_ft))
    print('Crop Width PIXEL: {} px'.format(cropbox_width_px))
    print('Crop Height PIXEL: {} px'.format(cropbox_height_px))
    print('Upper_left Crop Pt: XYZ [{},{}]'.format(up_left_crop_pt.X, up_left_crop_pt.Y))