Esempio n. 1
0
    def create_Floors(self):
        """Function to create a list of CurveLoop from given room boundaries."""
        __comment__ = """Keep 2 transactions below or otherwise revit will crash without giving 
                         any error tracebacks or whatsoever. It just shuts it down without saying anything...
                         Just keep them unless you want some headache :) - Erik Frits"""

        #>>>>>>>>>> ROOM BOUNDARIES
        floor_shape = self.room_boundaries[0]
        openings = list(
            self.room_boundaries)[1:] if len(self.room_boundaries) > 1 else []

        #>>>>>>>>>> CREATE FLOOR
        with ef_Transaction(doc, 'Create Floor'):
            curveLoopList = CurveArray()
            for seg in floor_shape:
                curveLoopList.Append(seg.GetCurve())

            new_floor = doc.Create.NewFloor(curveLoopList, self.floor_type,
                                            self.active_view_level, False)

        # >>>>>>>>>> CREATE FLOOR OPENINGS
        if openings:
            with ef_Transaction(doc, "Create Openings"):
                for opening in openings:
                    opening_curve = CurveArray()
                    for seg in opening:
                        opening_curve.Append(seg.GetCurve())

                    floor_opening = doc.Create.NewOpening(
                        new_floor, opening_curve, True)
        return new_floor
Esempio n. 2
0
    def align_legend(self, MainSheet):
        """Function to align Legend if it's the same to MainSheet's legend."""
        # VIEWPORTS
        main_legend_viewport = MainSheet.legend
        other_legend_viewport = self.legend

        if main_legend_viewport and other_legend_viewport:
            # VIEWS
            main_legend = doc.GetElement(main_legend_viewport.ViewId)
            other_legend = doc.GetElement(other_legend_viewport.ViewId)

            if main_legend.Name == other_legend.Name:
                # ╔═╗╦  ╦╔═╗╔╗╔  ╦  ╔═╗╔═╗╔═╗╔╗╔╔╦╗
                # ╠═╣║  ║║ ╦║║║  ║  ║╣ ║ ╦║╣ ║║║ ║║
                # ╩ ╩╩═╝╩╚═╝╝╚╝  ╩═╝╚═╝╚═╝╚═╝╝╚╝═╩╝ ALIGN LEGEND
                #==================================================
                with ef_Transaction(doc, "Align Legends"):

                    try:
                        other_legend_viewport.SetBoxCenter(
                            main_legend_viewport.GetBoxCenter())
                    except:
                        import traceback
                        print(traceback.format_exc())
                        print("***Could not align Legend on {}***".format(
                            self.sheet.SheetNumber))
            else:
                print(
                    "***The legend is not matching the MainSheet. It will not be aligned on the given sheet - {} .***"
                    .format(self.SheetNumber))
Esempio n. 3
0
    def ensure_titleblock_on_zero(self, MainSheet, apply_same=False):
        """Method to ensure that TitleBlocks's origin is XYZ(0,0,0). If not, align it!"""
        # ╔╦╗╦╔╦╗╦  ╔═╗  ╔╗ ╦  ╔═╗╔═╗╦╔═
        #  ║ ║ ║ ║  ║╣   ╠╩╗║  ║ ║║  ╠╩╗
        #  ╩ ╩ ╩ ╩═╝╚═╝  ╚═╝╩═╝╚═╝╚═╝╩ ╩ TITLE BLOCK
        # ==================================================
        main_titleblock = MainSheet.titleblock
        other_titleblock = self.titleblock

        if not main_titleblock or not other_titleblock:
            return

        # ORIGINS
        main_origin = main_titleblock.Location.Point
        other_origin = other_titleblock.Location.Point
        zero_origin = XYZ(0, 0, 0)

        # SET TITLEBLOCK LOCATION TO 0 IF NOT
        with ef_Transaction(doc, "Seting TitleBlock to XYZ(0,0,0)"):
            # MAIN
            if str(main_origin) != str(zero_origin):
                MainSheet.titleblock.Location.Point = zero_origin

            # OTHER
            if str(other_origin) != str(zero_origin):
                self.titleblock.Location.Point = zero_origin

            # MATCH OTHER's TITLEBLOCK
            if apply_same:
                main_titleblock_type_id = main_titleblock.get_Parameter(
                    BuiltInParameter.ELEM_TYPE_PARAM).AsElementId()
                other_titleblock.get_Parameter(
                    BuiltInParameter.ELEM_TYPE_PARAM).Set(
                        main_titleblock_type_id)
Esempio n. 4
0
 def change_region_linestyles(self):
     """Function to change LineStyles of selected regions."""
     # >>>>>>>>>> APPLY SELECTED LINESTYLE
     with ef_Transaction(doc, __title__):
         for region in self.selected_filled_regions:
             with try_except():
                 region.SetLineStyleId(self.selected_line_style.Id)
Esempio n. 5
0
 def rename_elements(self):
     """Function to rename selected Groups/GroupTypes."""
     with ef_Transaction(self.doc, __title__):
         for room in self.selected_elements:
             with try_except():
                 current_name = room.get_Parameter(
                     BuiltInParameter.ROOM_NAME).AsString()
                 new_name = self.prefix + current_name.replace(
                     self.find, self.replace) + self.suffix
                 if new_name and new_name != current_name:
                     room.Name = new_name
Esempio n. 6
0
    def button_run(self, sender, e):
        self.selected_text_type = self.get_selected_text_type()
        self.Close()

        # CREATE OVERVIEWS
        with ef_Transaction(doc, __title__, debug=True):
            if self.UI_checkbox_linestyles.IsChecked:
                self.overview_linestyles()
            if self.UI_checkbox_linepatterns.IsChecked:
                self.overview_linepatterns()
            if self.UI_checkbox_lineweights.IsChecked:
                self.overview_lineweights()
            if self.UI_checkbox_regions.IsChecked: self.overview_regions()
            if self.UI_checkbox_drafting_patterns.IsChecked:
                self.overview_drafting_patterns()
            if self.UI_checkbox_materials.IsChecked: self.overview_materials()

        if self.new_views:
            with ef_Transaction(doc,
                                "py_Placing Overviews on Sheet",
                                debug=True):
                self.place_views_on_sheet()
Esempio n. 7
0
    def button_run(self, sender, e):
        self.Close()
        selected_param_id = self.get_selected_parameter_id()

        # LOOP THROUGH SELECTED SHEETS
        selected_sheets = self.get_selected_sheets()
        if not selected_sheets:
            forms.alert('No Sheets selected. Please Try Again.',
                        title=__title__,
                        exitscript=True)

        print("Total: {} sheets selected.".format(len(selected_sheets)))
        with ef_Transaction(doc, __title__, debug=True):
            for sheet in selected_sheets:
                with try_except(debug=True):
                    # GET PARAMETER
                    sheet_params = sheet.Parameters
                    selected_param = [
                        p for p in sheet_params if p.Id == selected_param_id
                    ][0]

                    # GET PARAMETER VALUE
                    p_value = None
                    if str(selected_param.StorageType) == "String":
                        p_value = str(selected_param.AsString())
                    elif str(selected_param.StorageType) == "Integer":
                        p_value = str(selected_param.AsInteger())
                    elif str(selected_param.StorageType) == "Double":
                        p_value = str(selected_param.AsDouble())
                    else:
                        raise (
                            "Selected Parameter has unsupported StorageType.")

                    # REVISION NAME + DATE
                    rev_description = self.UI_prefix.Text + p_value + self.UI_suffix.Text
                    rev_date = self.UI_date.Text
                    rev_type = None

                    # CREATE and ADD REVISION TO SHEET
                    revision = create_revision(
                        description=rev_description,
                        date=rev_date,
                        revision_type=RevisionNumberType.None)
                    add_revision_to_sheet(sheet=sheet, revision_id=revision.Id)
                    print("Revision [{}] added on the sheet [{}]".format(
                        sheet.SheetNumber, rev_description))
Esempio n. 8
0
    def rename_elements(self):
        """Function to rename selected Groups/GroupTypes."""
        with ef_Transaction(self.doc, __title__):
            for symbol in self.selected_elements:
                with try_except():
                    try:
                        temp = self.doc.GetElement(
                            symbol.get_Parameter(
                                BuiltInParameter.ELEM_TYPE_PARAM).AsElementId(
                                ))
                        if temp:
                            symbol = temp
                    except:
                        pass
                    current_name = symbol.get_Parameter(
                        BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()
                    new_name = self.prefix + current_name.replace(
                        self.find, self.replace) + self.suffix

                    if new_name and new_name != current_name:
                        symbol.Name = new_name
Esempio n. 9
0
        selected_group_types,
        title=__title__,
        label='Select AttachedGroups to Duplicate:',
        uidoc=uidoc,
        version=__version__,
        exit_if_none=True)
    selected_attached_group_names = [
        g.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()
        for g in selected_attached_groups
    ]
    GUI = FindReplace(title=__title__,
                      label='New Name for Attached Groups:',
                      button_name="Duplicate")

    # DUPLICATE
    with ef_Transaction(doc, __title__, debug=True):
        group_types = [
            doc.GetElement(group_type_id)
            for group_type_id in selected_group_type_ids if group_type_id
        ]
        for group_type in group_types:
            # GET ATTACHED GROUPS
            for a_group_id in group_type.GetAvailableAttachedDetailGroupTypeIds(
            ):
                a_group = uidoc.Document.GetElement(a_group_id)

                # CHECK IF IT IS IN SELECTED ATTACHED GROUPS
                orig_a_group_name = a_group.get_Parameter(
                    BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()
                if orig_a_group_name not in selected_attached_group_names:
                    continue
Esempio n. 10
0
 def create_regions(self):
     """Function to loop through selected rooms and create floors from them."""
     # >>>>>>>>>> LOOP THROUGH ROOMS
     with ef_Transaction(doc, __title__, debug=True):
         for r in self.selected_rooms:
             new_region = RoomToOutline(room = r, line_style = self.selected_line_style)
Esempio n. 11
0
    def check_if_main_aligned(self, MainSheet):
        """Function to check if multiple ViewPlans on MainSheet are aligned."""
        def XYZ_to_str(XYZ_obj):
            """Convert XYZ object into readable string for further comparison."""
            return "{},{},{}".format(XYZ_obj.X, XYZ_obj.Y, XYZ_obj.Z)

        if not MainSheet.viewport_viewplan:
            return False

        # SINGLE VIEWPORT
        elif len(MainSheet.viewport_viewplan) == 1:
            return True

        # NO VIEWPORTS
        elif len(MainSheet.viewport_viewplan) == 0:
            print("***There are no Viewports on the MainSheet - {}***".format(
                MainSheet.SheetNumber))
            return False

        # MULTIPLE VIEWPORTS
        elif len(MainSheet.viewport_viewplan) > 1:
            if not self.overlap:
                print(
                    "***There are multiple Viewports on MainSheet and Overlap is set to False - {}***"
                    .format(MainSheet.SheetNumber))
                return

            # MainSheet's Viewports
            viewports = MainSheet.viewport_viewplan[:]

            # [CHECK: 1] - CROP ACTIVATED ON ALL
            for viewport in viewports:
                # CROP ACTIAVTED
                if not viewport.get_Parameter(
                        BuiltInParameter.VIEWER_CROP_REGION).AsInteger():
                    print(
                        "***All Viewports on MainSheet should have crop activated.***"
                    )
                    return

            # [CHECK: 2] - SAME SCALE
            scale = None
            for viewport in viewports:
                if not scale:
                    scale = viewport.get_Parameter(
                        BuiltInParameter.VIEWPORT_SCALE).AsString()
                    continue
                if scale != viewport.get_Parameter(
                        BuiltInParameter.VIEWPORT_SCALE).AsString():
                    print(
                        "***There are ViewPorts with different scale on MainSheet - {} ***"
                        .format(MainSheet.SheetNumber))

            # [CHECK: 3] - SAME CROPBOX
            cropboxes = [
                doc.GetElement(viewport.ViewId).CropBox
                for viewport in viewports
            ]
            crop_max_points = [
                XYZ_to_str(cropbox.Max) for cropbox in cropboxes
            ]
            crop_min_points = [
                XYZ_to_str(cropbox.Min) for cropbox in cropboxes
            ]

            if len(set(crop_max_points)) > 1 or len(set(crop_min_points)) > 1:
                print(
                    "***There are different CropBoxes/ScopBoxes assigned to viewports on MainSheet - {}.***"
                    .format(MainSheet.SheetNumber))
                return

            # [CHECK: 4] - SAME POSITION ON SHEET (with same cropbox)
            with ef_Transaction(doc,
                                "Check if MainSheet's viewports aligned."):
                viewports = MainSheet.viewport_viewplan[:]

                # TEMP HIDE ELEMENTS ON VIEWPORTS
                for main_viewport in viewports:
                    view = doc.GetElement(main_viewport.ViewId)
                    main_view_elements = FilteredElementCollector(
                        doc,
                        view.Id).WhereElementIsNotElementType().ToElementIds(
                        )  #todo combine all viewports into single filter
                    view.HideElementsTemporary(main_view_elements)

                # COMPARE VIEWPORT's POSITIONS (works only if same CropBox/ScopeBox )
                positions = [
                    XYZ_to_str(viewport.GetBoxCenter())
                    for viewport in viewports
                ]
                if len(set(positions)) > 1:
                    # TEMP UNHIDE VIEWS
                    for main_viewport in viewports:
                        main_view = doc.GetElement(main_viewport.ViewId)
                        main_view.DisableTemporaryViewMode(
                            TemporaryViewMode.TemporaryHideIsolate)

                    print(
                        "***There are multiple Viewports on MainSheet and they are not aligned. Main - {}.***\n ***Viewports will not be aligned!***"
                        .format(MainSheet.SheetNumber))
                    return False
            return True
Esempio n. 12
0
    def align_viewports(self,
                        MainSheet,
                        apply_CropScopeBox=False,
                        overlap=False):
        """Method to align Viewports."""
        # CHECK OVERLAP ARGUMENT
        if len(self.viewport_viewplan) > 1 and not overlap:
            print(
                "***Multiple Viewports and Overlap set to False on Sheet - {}***"
                .format(self.SheetNumber))
            return

        # ╔╦╗╔═╗╦╔╗╔  ╔═╗╦ ╦╔═╗╔═╗╔╦╗
        # ║║║╠═╣║║║║  ╚═╗╠═╣║╣ ║╣  ║
        # ╩ ╩╩ ╩╩╝╚╝  ╚═╝╩ ╩╚═╝╚═╝ ╩ MAIN SHEET
        main_viewport = MainSheet.viewport_viewplan[0]
        main_view = doc.GetElement(main_viewport.ViewId)
        main_scopebox_id = main_view.get_Parameter(
            BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).AsElementId()
        main_cropbox_manager = main_view.GetCropRegionShapeManager(
        ).GetCropShape()
        main_cropbox = None

        # GET CROPBOX / ACTIVATE CROP IF CROPBOX NOT FOUND
        try:
            if main_cropbox_manager:
                main_cropbox = main_cropbox_manager[
                    0]  #IT WILL TAKE ONLY SINGLE CURVELOOP.
            else:
                view_crop_param = main_view.get_Parameter(
                    BuiltInParameter.VIEWER_CROP_REGION)
                if not view_crop_param.AsInteger():
                    with ef_Transaction(doc, "Actiavte Crop"):
                        view_crop_param.Set(1)
                        main_cropbox = main_view.GetCropRegionShapeManager(
                        ).GetCropShape()[0]
        except:
            msg = "Please activate CropBox or ScopeBox on your views that are placed on MainSheet[{}]. \nPlease Try again.\n If error still persist, please contact me in LinkedIn.".format(
                self.SheetNumber)
            forms.alert(msg, title=__title__, exitscript=True)

        # ╦  ╔═╗╔═╗╔═╗  ╔╦╗╦ ╦╦═╗╔═╗╦ ╦╔═╗╦ ╦  ╔═╗╔╦╗╦ ╦╔═╗╦═╗╔═╗
        # ║  ║ ║║ ║╠═╝   ║ ╠═╣╠╦╝║ ║║ ║║ ╦╠═╣  ║ ║ ║ ╠═╣║╣ ╠╦╝╚═╗
        # ╩═╝╚═╝╚═╝╩     ╩ ╩ ╩╩╚═╚═╝╚═╝╚═╝╩ ╩  ╚═╝ ╩ ╩ ╩╚═╝╩╚═╚═╝

        for other_viewport in self.viewport_viewplan:
            other_view = doc.GetElement(other_viewport.ViewId)

            # ╔═╗╦═╗╔═╗╔═╗╔╗ ╔═╗═╗ ╦       ╔═╗╔═╗╔═╗╔═╗╔═╗╔╗ ╔═╗═╗ ╦
            # ║  ╠╦╝║ ║╠═╝╠╩╗║ ║╔╩╦╝  ───  ╚═╗║  ║ ║╠═╝║╣ ╠╩╗║ ║╔╩╦╝
            # ╚═╝╩╚═╚═╝╩  ╚═╝╚═╝╩ ╚═       ╚═╝╚═╝╚═╝╩  ╚═╝╚═╝╚═╝╩ ╚═ CROPBOX / SCOPEBOX
            # ==================================================
            if apply_CropScopeBox:

                with ef_Transaction(doc, 'Crop View - True'):
                    # SET CROP VIEW TO TRUE
                    crop_param = other_view.get_Parameter(
                        BuiltInParameter.VIEWER_CROP_REGION)
                    if not crop_param.AsInteger():
                        try:
                            crop_param.Set(1)
                        except:
                            pass

                with ef_Transaction(doc, "Apply Crop/Scope Box"):
                    # SCOPE BOX
                    try:
                        # SET SCOPE BOX
                        param_scopebox = other_view.get_Parameter(
                            BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP)
                        param_scopebox.Set(main_scopebox_id)
                    except:
                        pass

                    # CROPBOX
                    if main_scopebox_id == ElementId(-1):
                        crop = other_view.GetCropRegionShapeManager()
                        crop.SetCropShape(main_cropbox)

            with ef_Transaction(doc, "Align viewport"):
                # ╔╦╗╔═╗╔╦╗╔═╗  ╦ ╦╦╔╦╗╔═╗
                #  ║ ║╣ ║║║╠═╝  ╠═╣║ ║║║╣
                #  ╩ ╚═╝╩ ╩╩    ╩ ╩╩═╩╝╚═╝ TEMP HIDE
                #==================================================
                #MAIN
                main_view_elements = FilteredElementCollector(
                    doc,
                    main_view.Id).WhereElementIsNotElementType().ToElementIds(
                    )
                main_view.HideElementsTemporary(main_view_elements)
                #OTHER
                other_view_elements = FilteredElementCollector(
                    doc,
                    other_view.Id).WhereElementIsNotElementType().ToElementIds(
                    )
                other_view.HideElementsTemporary(other_view_elements)

                # ╔═╗╦  ╦╔═╗╔╗╔  ╦  ╦╦╔═╗╦ ╦╔═╗╔═╗╦═╗╔╦╗╔═╗
                # ╠═╣║  ║║ ╦║║║  ╚╗╔╝║║╣ ║║║╠═╝║ ║╠╦╝ ║ ╚═╗
                # ╩ ╩╩═╝╩╚═╝╝╚╝   ╚╝ ╩╚═╝╚╩╝╩  ╚═╝╩╚═ ╩ ╚═╝ ALIGN VIEWPORTS
                #==================================================
                try:
                    other_viewport.SetBoxCenter(main_viewport.GetBoxCenter())
                except:
                    print("***Could not align Viewport on {}***".format(
                        self.sheet.SheetNumber))

                # ╔╦╗╔═╗╔╦╗╔═╗  ╦ ╦╔╗╔╦ ╦╦╔╦╗╔═╗
                #  ║ ║╣ ║║║╠═╝  ║ ║║║║╠═╣║ ║║║╣
                #  ╩ ╚═╝╩ ╩╩    ╚═╝╝╚╝╩ ╩╩═╩╝╚═╝ TEMP UNHIDE
                #==================================================
                other_view.DisableTemporaryViewMode(
                    TemporaryViewMode.TemporaryHideIsolate)
                for main_viewport in MainSheet.viewport_viewplan:
                    main_view = doc.GetElement(main_viewport.ViewId)
                    main_view.DisableTemporaryViewMode(
                        TemporaryViewMode.TemporaryHideIsolate)

                # [DEBUG] - RESTORE CROP
                if main_scopebox_id == ElementId(
                        -1) and main_cropbox.IsRectangular(
                            main_cropbox.GetPlane()):
                    crop.RemoveCropRegionShape()