def post_command(command_id): """Request Revit to run a command Args: command_id (str): command identifier e.g. ID_REVIT_SAVE_AS_TEMPLATE """ HOST_APP.post_command(command_id)
def __init__(self, param_def, param_binding=None, param_ext_def=False): super(ProjectParameter, self).__init__() self.param_def = param_def self.param_binding = param_binding self.param_binding_type = self._determine_binding_type() self.shared = False self.param_ext_def = None self.param_guid = '' if param_ext_def: self.shared = True self.param_ext_def = param_ext_def self.param_guid = self.param_ext_def.GUID.ToString() self.name = self.param_def.Name # Revit <2017 does not have the Id parameter self.param_id = getattr(self.param_def, 'Id', None) # Revit >2021 does not have the UnitType property if HOST_APP.is_newer_than(2021, or_equal=True): self.unit_type = self.param_def.GetSpecTypeId() else: self.unit_type = self.param_def.UnitType # Revit >2022 does not have the ParameterType property if HOST_APP.is_newer_than(2022, or_equal=True): self.param_type = self.param_def.GetDataType() else: self.param_type = self.param_def.ParameterType self.param_group = self.param_def.ParameterGroup
def reorient(): face = revit.pick_face() if face: with revit.Transaction('Orient to Selected Face'): # calculate normal if HOST_APP.is_newer_than(2015): normal_vec = face.ComputeNormal(DB.UV(0, 0)) else: normal_vec = face.Normal # create base plane for sketchplane if HOST_APP.is_newer_than(2016): base_plane = \ DB.Plane.CreateByNormalAndOrigin(normal_vec, face.Origin) else: base_plane = DB.Plane(normal_vec, face.Origin) # now that we have the base_plane and normal_vec # let's create the sketchplane sp = DB.SketchPlane.Create(revit.doc, base_plane) # orient the 3D view looking at the sketchplane revit.active_view.OrientTo(normal_vec.Negate()) # set the sketchplane to active revit.uidoc.ActiveView.SketchPlane = sp revit.uidoc.RefreshActiveView()
def colorvg(r, g, b, projline_only=False, xacn_name=None): color = DB.Color(r, g, b) wireframe_color = DB.Color(r - 20 if r - 20 >= 0 else 0, g - 20 if g - 20 >= 0 else 0, b - 20 if b - 20 >= 0 else 0) with revit.Transaction(xacn_name or 'Set Color VG override'): for el in selection: if isinstance(el, DB.Group): for mem in el.GetMemberIds(): selection.append(revit.doc.GetElement(mem)) ogs = DB.OverrideGraphicSettings() ogs.SetProjectionLineColor(wireframe_color) ogs.SetCutLineColor(wireframe_color) if not projline_only: if HOST_APP.is_newer_than(2018): ogs.SetSurfaceForegroundPatternColor(color) ogs.SetCutForegroundPatternColor(color) else: ogs.SetProjectionFillColor(color) ogs.SetCutFillColor(color) solid_fpattern = find_solid_fillpat() if solid_fpattern: if HOST_APP.is_newer_than(2018): ogs.SetCutForegroundPatternId(solid_fpattern.Id) ogs.SetSurfaceForegroundPatternId(solid_fpattern.Id) else: ogs.SetProjectionFillPatternId(solid_fpattern.Id) ogs.SetCutFillPatternId(solid_fpattern.Id) else: logger.warning('Can not find solid fill pattern in model' 'to assign as projection/cut pattern.') revit.doc.ActiveView.SetElementOverrides(el.Id, ogs)
def save_options(self, sender, args): # base self._config.halftone = self.halftone.IsChecked self._config.transparency = self.transparency.IsChecked # projection lines self._config.proj_line_color = self.proj_line_color.IsChecked self._config.proj_line_pattern = self.proj_line_pattern.IsChecked self._config.proj_line_weight = self.proj_line_weight.IsChecked # projection forground pattern self._config.proj_fill_color = self.proj_fill_color.IsChecked self._config.proj_fill_pattern = self.proj_fill_pattern.IsChecked self._config.proj_fill_pattern_visibility = \ self.proj_fill_pattern_visibility.IsChecked # projection background pattern (Revit >= 2019) if HOST_APP.is_newer_than(2019, or_equal=True): self._config.proj_bg_fill_color = \ self.proj_bg_fill_color.IsChecked self._config.proj_bg_fill_pattern = \ self.proj_bg_fill_pattern.IsChecked self._config.proj_bg_fill_pattern_visibility = \ self.proj_bg_fill_pattern_visibility.IsChecked # cut lines self._config.cut_line_color = self.cut_line_color.IsChecked self._config.cut_line_pattern = self.cut_line_pattern.IsChecked self._config.cut_line_weight = self.cut_line_weight.IsChecked # cut forground pattern self._config.cut_fill_color = self.cut_fill_color.IsChecked self._config.cut_fill_pattern = self.cut_fill_pattern.IsChecked self._config.cut_fill_pattern_visibility = \ self.cut_fill_pattern_visibility.IsChecked # cut background pattern (Revit >= 2019) if HOST_APP.is_newer_than(2019, or_equal=True): self._config.cut_bg_fill_color = \ self.cut_bg_fill_color.IsChecked self._config.cut_bg_fill_pattern = \ self.cut_bg_fill_pattern.IsChecked self._config.cut_bg_fill_pattern_visibility = \ self.cut_bg_fill_pattern_visibility.IsChecked # dim overrides self._config.dim_override = self.dim_override.IsChecked self._config.dim_textposition = self.dim_textposition.IsChecked self._config.dim_above = self.dim_above.IsChecked self._config.dim_below = self.dim_below.IsChecked self._config.dim_prefix = self.dim_prefix.IsChecked self._config.dim_suffix = self.dim_suffix.IsChecked script.save_config() self.Close()
def _produce_ui_stacks(ui_maker_params): """ Args: ui_maker_params (UIMakerParams): Standard parameters for making ui item """ parent_ui_panel = ui_maker_params.parent_ui stack_parent = ui_maker_params.parent_cmp stack_cmp = ui_maker_params.component ext_asm_info = ui_maker_params.asm_info # if sub_cmp is a stack, ask parent_ui_item to open a stack # (parent_ui_item.open_stack). # All subsequent items will be placed under this stack. Close the stack # (parent_ui_item.close_stack) to finish adding items to the stack. try: parent_ui_panel.open_stack() mlogger.debug('Opened stack: %s', stack_cmp.name) if HOST_APP.is_older_than('2017'): _component_creation_dict[SPLIT_BUTTON_POSTFIX] = \ _produce_ui_pulldown _component_creation_dict[SPLITPUSH_BUTTON_POSTFIX] = \ _produce_ui_pulldown # capturing and logging any errors on stack item # (e.g when parent_ui_panel's stack is full and can not add any # more items it will raise an error) _recursively_produce_ui_items( UIMakerParams(parent_ui_panel, stack_parent, stack_cmp, ext_asm_info, ui_maker_params.create_beta_cmds)) if HOST_APP.is_older_than('2017'): _component_creation_dict[SPLIT_BUTTON_POSTFIX] = \ _produce_ui_split _component_creation_dict[SPLITPUSH_BUTTON_POSTFIX] = \ _produce_ui_splitpush try: parent_ui_panel.close_stack() mlogger.debug('Closed stack: %s', stack_cmp.name) return stack_cmp except PyRevitException as err: mlogger.error('Error creating stack | %s', err) except Exception as err: mlogger.error('Can not create stack under this parent: %s | %s', parent_ui_panel, err)
def report_env(): """Report python version, home directory, config file, etc.""" # run diagnostics system_diag() # get python version that includes last commit hash mlogger.info('pyRevit version: %s - </> with :growing_heart: in %s', envvars.get_pyrevit_env_var(envvars.VERSION_ENVVAR), about.get_pyrevit_about().madein) if user_config.rocket_mode: mlogger.info('pyRevit Rocket Mode enabled. :rocket:') if HOST_APP.is_newer_than(2017): full_host_name = \ HOST_APP.version_name.replace(HOST_APP.version, HOST_APP.subversion) else: full_host_name = HOST_APP.version_name mlogger.info('Host is %s (build: %s id: %s)', full_host_name, HOST_APP.build, HOST_APP.proc_id) mlogger.info('Running on: %s', sys.version) mlogger.info('User is: %s', HOST_APP.username) mlogger.info('Home Directory is: %s', HOME_DIR) mlogger.info('Session uuid is: %s', get_session_uuid()) mlogger.info('Runtime assembly is: %s', runtime.RUNTIME_ASSM_NAME) mlogger.info('Config file is (%s): %s', user_config.config_type, user_config.config_file)
def prepare_colors(groups_dict): """Prepare a list of vg overrides for each group type""" groups_colors = {} count = sum( [len(groups) for groups in groups_dict.values() if len(groups) > 1]) colors = [DB.Color(x[0], x[1], x[2]) for x in generate_colors(count)] color_gray = DB.Color(128, 128, 128) j = 0 for gt_id in groups_dict.keys(): if len(groups_dict[gt_id]) == 1: color = color_gray else: color = colors[j] j += 1 if HOST_APP.is_newer_than(2019, or_equal=True): groups_colors[gt_id] = ( DB.OverrideGraphicSettings().SetProjectionLineColor(color). SetProjectionLineWeight(6).SetSurfaceBackgroundPatternColor( color).SetCutLineColor(color).SetCutLineWeight( 6).SetCutBackgroundPatternColor(color)) else: groups_colors[gt_id] = (DB.OverrideGraphicSettings( ).SetProjectionLineColor(color).SetProjectionLineWeight( 6).SetProjectionFillColor(color).SetCutLineColor( color).SetCutLineWeight(6).SetCutFillColor(color)) return groups_colors
def setup_runtime_vars(): """Setup runtime environment variables with session information.""" # set pyrevit version pyrvt_ver = versionmgr.get_pyrevit_version().get_formatted() envvars.set_pyrevit_env_var(PYREVIT_VERSION_ENVVAR, pyrvt_ver) # set app version env var if HOST_APP.is_newer_than(2017): envvars.set_pyrevit_env_var(PYREVIT_APPVERSION_ENVVAR, HOST_APP.subversion) else: envvars.set_pyrevit_env_var(PYREVIT_APPVERSION_ENVVAR, HOST_APP.version) # set ironpython engine version env var attachment = user_config.get_current_attachment() if attachment and attachment.Clone: envvars.set_pyrevit_env_var(PYREVIT_IPYVERSION_ENVVAR, attachment.Engine.Version) # set cpython engine version env var cpyengine = user_config.get_active_cpython_engine() if cpyengine: envvars.set_pyrevit_env_var(PYREVIT_CSPYVERSION_ENVVAR, cpyengine.Version)
def init_doc_colorizer(usercfg): """Initialize document colorizer from settings""" uiapp = HOST_APP.uiapp if HOST_APP.is_newer_than(2018): current_tabcolorizer = \ envvars.get_pyrevit_env_var(envvars.TABCOLORIZER_ENVVAR) new_theme = get_tabcoloring_theme(usercfg) # cancel out the colorizer from previous runtime version if current_tabcolorizer: # TODO: adopt the previous slots state # prev_theme = current_tabcolorizer.TabColoringTheme # if prev_theme: # new_theme.InitSlots(prev_theme) current_tabcolorizer.StopGroupingDocumentTabs() # start or stop the document colorizer types.DocumentTabEventUtils.TabColoringTheme = new_theme if usercfg.colorize_docs: types.DocumentTabEventUtils.StartGroupingDocumentTabs(uiapp) else: types.DocumentTabEventUtils.StopGroupingDocumentTabs() # set the new colorizer envvars.set_pyrevit_env_var(envvars.TABCOLORIZER_ENVVAR, types.DocumentTabEventUtils)
def report_env(): # log python version, home directory, config file, ... # get python version that includes last commit hash pyrvt_ver = versionmgr.get_pyrevit_version().get_formatted() system_diag() mlogger.info('pyRevit version: %s - </> with :growing_heart: in %s', pyrvt_ver, about.get_pyrevit_about().madein) if user_config.core.get_option('rocketmode', False): mlogger.info('pyRevit Rocket Mode enabled. :rocket:') if HOST_APP.is_newer_than(2017): full_host_name = \ HOST_APP.version_name.replace(HOST_APP.version, HOST_APP.subversion) else: full_host_name = HOST_APP.version_name mlogger.info('Host is %s (build: %s id: %s)', full_host_name, HOST_APP.build, HOST_APP.proc_id) mlogger.info('Running on: %s', sys.version) mlogger.info('User is: %s', HOST_APP.username) mlogger.info('Home Directory is: %s', HOME_DIR) mlogger.info('Session uuid is: %s', get_session_uuid()) mlogger.info('Base assembly is: %s', BASE_TYPES_ASM_NAME) mlogger.info('Config file is (%s): %s', user_config.config_type, user_config.config_file)
def cleanup_selection(self, rvt_elements, for_model=True): geom_curves = [] adjusted_fillgrids = [] for element in rvt_elements: if isinstance(element, acceptable_lines): geom_curves.append(self.grab_geom_curves(element)) elif isinstance(element, DB.FilledRegion): bg_fillpat = \ revit.query.get_fillpattern_from_element(element) fg_fillpat = None # check for version otherwise fg_fillpat is same as bg_fillpat if HOST_APP.is_newer_than(2018): fg_fillpat = \ revit.query.get_fillpattern_from_element( element, background=False ) # process both forground and background patterns for fillpat in [bg_fillpat, fg_fillpat]: # if available if fillpat: fillgrids = fillpat.GetFillGrids() # adjust derafting patterns to current scale if fillpat.Target == DB.FillPatternTarget.Drafting: adjusted_fillgrids.extend( [self.update_fillgrid(x, revit.active_view.Scale) for x in fillgrids] ) else: adjusted_fillgrids.extend(fillgrids) return geom_curves, adjusted_fillgrids
def create_splitpush_button(self, item_name, icon_path, update_if_exists=False): if self.itemdata_mode and HOST_APP.is_older_than('2017'): raise PyRevitUIError('Revits earlier than 2017 do not support ' 'split buttons in a stack.') else: self._create_button_group(UI.SplitButtonData, item_name, icon_path, update_if_exists) self.ribbon_item(item_name).sync_with_current_item(False)
def toggle_category_visibility(view, subcat, hidden=None): if HOST_APP.is_older_than(2018): if hidden is None: hidden = not view.GetVisibility(subcat.Id) view.SetVisibility(subcat.Id, hidden) else: if hidden is None: hidden = not view.GetCategoryHidden(subcat.Id) view.SetCategoryHidden(subcat.Id, hidden)
def set_name(element, new_name): # grab viewname correctly if isinstance(element, DB.View): if HOST_APP.is_newer_than('2019', or_equal=True): element.Name = new_name else: element.ViewName = new_name else: element.Name = new_name
def convert_length_to_internal(d_units): # convert length units from display units to internal units = revit.doc.GetUnits() if HOST_APP.is_newer_than(2021): internal_units = units.GetFormatOptions( DB.SpecTypeId.Length).GetUnitTypeId() else: # pre-2021 internal_units = units.GetFormatOptions( DB.UnitType.UT_Length).DisplayUnits converted = DB.UnitUtils.ConvertToInternalUnits(d_units, internal_units) return converted
def setup_view_scale(self): biparam = DB.BuiltInParameter.VIEW_SCALE_PULLDOWN_IMPERIAL if revit.query.is_metric(revit.doc): biparam = DB.BuiltInParameter.VIEW_SCALE_PULLDOWN_METRIC # re issue #510 indexing the builtinparam only works on >=2015 if HOST_APP.is_newer_than(2014): self.viewscale_tb.Text = \ revit.active_view.Parameter[biparam].AsValueString() else: self.viewscale_tb.Text = \ revit.active_view.get_Parameter(biparam).AsValueString()
def _make_filledregion(fillpattern_name, fillpattern_id): filledregion_types = DB.FilteredElementCollector(revit.doc)\ .OfClass(framework.get_type(DB.FilledRegionType)) source_fr = filledregion_types.FirstElement() with revit.Transaction('Create Filled Region'): new_fr = source_fr.Duplicate(fillpattern_name) if HOST_APP.is_newer_than(2018): new_fr.ForegroundPatternId = fillpattern_id else: new_fr.FillPatternId = fillpattern_id
def get_fpm_from_frtype(etype): fp_id = None if HOST_APP.is_newer_than(2018): # return requested fill pattern (background or foreground) fp_id = etype.BackgroundPatternId \ if background else etype.ForegroundPatternId else: fp_id = etype.FillPatternId if fp_id: fillpat_element = doc.GetElement(fp_id) if fillpat_element: return fillpat_element.GetFillPattern()
def get_length_units(doc): # fetch Revit's internal units depending on the Revit version units = doc.GetUnits() # print ("Doc name {}".format(doc.Title)) if HOST_APP.is_newer_than(2021): int_length_units = units.GetFormatOptions( DB.SpecTypeId.Length).GetUnitTypeId() else: int_length_units = units.GetFormatOptions( DB.UnitType.UT_Length).DisplayUnits return int_length_units
def get_references(): # 'IronRuby', 'IronRuby.Libraries', ref_list = [ # system stuff 'System', 'System.Core', 'System.Xaml', 'System.Web', 'System.Xml', 'System.Numerics', 'System.Drawing', 'System.Windows.Forms', 'System.Web.Extensions', 'PresentationCore', 'PresentationFramework', 'WindowsBase', 'WindowsFormsIntegration', # legacy csharp/vb.net compiler 'Microsoft.CSharp', # iron python engine 'Microsoft.Dynamic', 'Microsoft.Scripting', 'IronPython', 'IronPython.Modules', # revit api 'RevitAPI', 'RevitAPIUI', 'AdWindows', 'UIFramework', # pyrevit loader assembly 'pyRevitLoader', # pyrevit labs 'pyRevitLabs.Common', 'pyRevitLabs.CommonWPF', 'pyRevitLabs.MahAppsMetro', 'pyRevitLabs.NLog', 'pyRevitLabs.TargetApps.Revit', 'pyRevitLabs.PyRevit', 'pyRevitLabs.Emojis', ] # another revit api if HOST_APP.is_newer_than(2018): ref_list.extend(['Xceed.Wpf.AvalonDock']) refs = [_get_reference_file(ref_name) for ref_name in ref_list] # add cpython engine assembly refs.append(CPYTHON_ENGINE_ASSM) return refs
def get_crop_region(view): """Takes crop region of a view Args: view (DB.View): view to get crop region from Returns: list[DB.CurveLoop]: list of curve loops """ crsm = view.GetCropRegionShapeManager() if HOST_APP.is_newer_than(2015): crsm_valid = crsm.CanHaveShape else: crsm_valid = crsm.Valid if crsm_valid: if HOST_APP.is_newer_than(2015): curve_loops = list(crsm.GetCropShape()) else: curve_loops = [crsm.GetCropRegionShape()] if curve_loops: return curve_loops
def setup_export_units(self): self.export_units_cb.ItemsSource = ['INCH', 'MM'] is_metric = False units = revit.doc.GetUnits() if HOST_APP.is_newer_than(2021): length_fo = units.GetFormatOptions(DB.SpecTypeId.Length) is_metric = length_fo.GetUnitTypeId() in metric_units else: length_fo = units.GetFormatOptions(DB.UnitType.UT_Length) is_metric = length_fo.DisplayUnits in metric_units if is_metric: self.export_units_cb.SelectedIndex = 1 else: self.export_units_cb.SelectedIndex = 0
def toggle_doc_colorizer(state): uiapp = HOST_APP.uiapp if HOST_APP.is_newer_than(2018): # cancel out the colorizer from previous runtime version current_tabcolorizer = \ envvars.get_pyrevit_env_var(envvars.TABCOLORIZER_ENVVAR) if current_tabcolorizer: current_tabcolorizer.StopGroupingDocumentTabs() # start or stop the document colorizer if state: types.DocumentTabEventUtils.StartGroupingDocumentTabs(uiapp) else: types.DocumentTabEventUtils.StopGroupingDocumentTabs() # set the new colorizer envvars.set_pyrevit_env_var(envvars.TABCOLORIZER_ENVVAR, types.DocumentTabEventUtils)
def set_crop_region(view, curve_loops): """Sets crop region to a view Args: view (DB.View): view to change curve_loops (list[DB.CurveLoop]): list of curve loops """ if not isinstance(curve_loops, list): curve_loops = [curve_loops] crop_active_saved = view.CropBoxActive view.CropBoxActive = True crsm = view.GetCropRegionShapeManager() for cloop in curve_loops: if HOST_APP.is_newer_than(2015): crsm.SetCropShape(cloop) else: crsm.SetCropRegionShape(cloop) view.CropBoxActive = crop_active_saved
def find_views_with_underlay(invert=False): for v in views: try: if HOST_APP.is_newer_than(2016, or_equal=True): base_underlay_param = \ v.Parameter[DB.BuiltInParameter.VIEW_UNDERLAY_BOTTOM_ID] top_underlay_param = \ v.Parameter[DB.BuiltInParameter.VIEW_UNDERLAY_TOP_ID] if (base_underlay_param \ and top_underlay_param \ and elementid_has_value(base_underlay_param) \ and elementid_has_value(top_underlay_param) ) != invert: print('TYPE: {1}\n' 'ID: {2}\n' 'TEMPLATE: {3}\n' 'UNDERLAY (BASE): {4}\n' 'UNDERLAY (TOP): {5}\n' '{0}\n\n' .format(revit.query.get_name(v), str(v.ViewType).ljust(20), output.linkify(v.Id), str(v.IsTemplate).ljust(10), base_underlay_param.AsValueString().ljust(25), top_underlay_param.AsValueString().ljust(25))) else: underlayp = v.Parameter[DB.BuiltInParameter.VIEW_UNDERLAY_ID] if (underlayp and elementid_has_value(underlayp) ) != invert: print('TYPE: {1}\n' 'ID: {2}\n' 'TEMPLATE: {3}\n' 'UNDERLAY: {4}\n' '{0}\n\n'.format(revit.query.get_name(v), str(v.ViewType).ljust(20), output.linkify(v.Id), str(v.IsTemplate).ljust(10), underlayp.AsValueString().ljust(25))) print("\n\n") except Exception: continue
def get_name(element, title_on_sheet=False): # grab viewname correctly if isinstance(element, DB.View): view_name = None if title_on_sheet: titleos_param = \ element.Parameter[DB.BuiltInParameter.VIEW_DESCRIPTION] view_name = titleos_param.AsString() # if view name could bot be extracted from title_on_sheet if view_name: return view_name else: if HOST_APP.is_newer_than('2019', or_equal=True): return element.Name else: return element.ViewName # have to use the imported Element otherwise # AttributeError occurs return Element.Name.__get__(element)
def find_views_with_underlay(): for v in views: try: if HOST_APP.is_newer_than(2016, or_equal=True): base_underlay_param = \ v.Parameter[DB.BuiltInParameter.VIEW_UNDERLAY_BOTTOM_ID] top_underlay_param = \ v.Parameter[DB.BuiltInParameter.VIEW_UNDERLAY_TOP_ID] if base_underlay_param \ and top_underlay_param \ and base_underlay_param.AsValueString() != 'None' \ and top_underlay_param.AsValueString() != 'None': print('TYPE: {1}\n' 'ID: {2}\n' 'TEMPLATE: {3}\n' 'UNDERLAY (BASE):{4}\n' 'UNDERLAY (TOP):{5}\n' '{0}\n\n' .format(v.ViewName, str(v.ViewType).ljust(20), output.linkify(v.Id), str(v.IsTemplate).ljust(10), base_underlay_param.AsValueString().ljust(25), top_underlay_param.AsValueString().ljust(25))) else: underlayp = v.Parameter[DB.BuiltInParameter.VIEW_UNDERLAY_ID] if underlayp and underlayp.AsValueString() != 'None': print('TYPE: {1}\n' 'ID: {2}\n' 'TEMPLATE: {3}\n' 'UNDERLAY:{4}\n' '{0}\n\n'.format(v.ViewName, str(v.ViewType).ljust(20), output.linkify(v.Id), str(v.IsTemplate).ljust(10), underlayp.AsValueString().ljust(25))) except Exception: continue
def setup_runtime_vars(): """Setup runtime environment variables with session information.""" # set pyrevit version pyrvt_ver = versionmgr.get_pyrevit_version().get_formatted() envvars.set_pyrevit_env_var(envvars.VERSION_ENVVAR, pyrvt_ver) # set app version env var if HOST_APP.is_newer_than(2017): envvars.set_pyrevit_env_var(envvars.APPVERSION_ENVVAR, HOST_APP.subversion) else: envvars.set_pyrevit_env_var(envvars.APPVERSION_ENVVAR, HOST_APP.version) # set ironpython engine version env var attachment = user_config.get_current_attachment() if attachment and attachment.Clone: envvars.set_pyrevit_env_var(envvars.CLONENAME_ENVVAR, attachment.Clone.Name) envvars.set_pyrevit_env_var(envvars.IPYVERSION_ENVVAR, str(attachment.Engine.Version)) else: mlogger.debug('Can not determine attachment.') envvars.set_pyrevit_env_var(envvars.CLONENAME_ENVVAR, "Unknown") envvars.set_pyrevit_env_var(envvars.IPYVERSION_ENVVAR, "0.0.0") # set cpython engine version env var cpyengine = user_config.get_active_cpython_engine() if cpyengine: envvars.set_pyrevit_env_var(envvars.CPYVERSION_ENVVAR, str(cpyengine.Version)) else: envvars.set_pyrevit_env_var(envvars.CPYVERSION_ENVVAR, "0.0.0") # set a list of important assemblies # this is required for dotnet script execution set_loaded_pyrevit_referenced_modules(runtime.get_references())
def create_3d_view(view_name, isometric=True, doc=None): doc = doc or DOCS.doc nview = query.get_view_by_name(view_name, doc=doc) if not nview: default_3dview_type = \ doc.GetDefaultElementTypeId(DB.ElementTypeGroup.ViewType3D) if isometric: nview = DB.View3D.CreateIsometric(doc, default_3dview_type) else: nview = DB.View3D.CreatePerspective(doc, default_3dview_type) if HOST_APP.is_newer_than('2019', or_equal=True): nview.Name = view_name else: nview.ViewName = view_name nview.CropBoxActive = False nview.CropBoxVisible = False if nview.CanToggleBetweenPerspectiveAndIsometric(): if isometric: nview.ToggleToIsometric() else: nview.ToggleToPerspective() return nview