def get_datafile(reverse): global append_mode datafile = script.get_document_data_file("pyApex_Constraints", "pym") saved_list = [] if os.path.exists(datafile): if reverse == False: td = TaskDialog("Constraints") td.MainInstruction = "File with elements saved after previous run found.\nHow to deal with it?" td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Remove it and replace") td.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Append new data") td.AllowCancellation = True taskDialogResult = td.Show() if taskDialogResult == TaskDialogResult.Cancel: return None, None elif taskDialogResult == TaskDialogResult.CommandLink1: append_mode = False else: append_mode = True if append_mode: f = open(datafile, 'r') saved_list = pickle.load(f) f.close() # remove duplicates ids = list(set(saved_list)) return datafile, ids
def iterate(mode, step_size=1): """Iterate over elements in memorized selection""" index_datafile = \ script.get_document_data_file("SelListPrevNextIndex", "pym") datafile = \ script.get_document_data_file("SelList", "pym") selection = revit.get_selection() if op.exists(index_datafile): with open(index_datafile, 'r') as f: idx = pickle.load(f) if mode == '-': idx = idx - step_size else: idx = idx + step_size else: idx = 0 if op.exists(datafile): try: with open(datafile, 'r') as df: cursel = pickle.load(df) if cursel: if idx < 0: idx = abs(idx / len(cursel)) * len(cursel) + idx elif idx >= len(cursel): idx = idx - abs(idx / len(cursel)) * len(cursel) selection.set_to([DB.ElementId(int(list(cursel)[idx]))]) with open(index_datafile, 'w') as f: pickle.dump(idx, f) except Exception as io_err: logger.error('Error read/write to: %s | %s', datafile, io_err)
def __init__(self, xaml_file_name): # make sure there is selection forms.check_selection(exitscript=True) # now setup window forms.WPFWindow.__init__(self, xaml_file_name) self._tag_cache = \ script.get_document_data_file(file_id='tagcache', file_ext='cache') if op.isfile(self._tag_cache): self._read_sow_cache() selection = revit.get_selection() sel_cnt = len(selection) self._target_elements = selection.elements self.Title += ' (for {} Selected Elements)'.format(sel_cnt) #pylint: disable=E1101 self.tags_tb.Focus() self.tags_tb.SelectAll()
import pickle from pyrevit.framework import List from pyrevit import script from pyrevit import revit, DB __helpurl__ = 'https://www.youtube.com/watch?v=pAM-ARIXXLw' __doc__ = 'Read selection from memory.\n'\ 'Works like the MR button in a calculator. '\ 'This is a project-dependent memory. Every project has its own '\ 'selection memory saved in %appdata%/pyRevit folder as *.pym files.' selection = revit.get_selection() datafile = script.get_document_data_file("SelList", "pym") try: f = open(datafile, 'r') current_selection = pickle.load(f) f.close() element_ids = [] for elid in current_selection: element_ids.append(DB.ElementId(int(elid))) selection.set_to(element_ids) except Exception: pass
selected_switch = \ forms.CommandSwitchWindow.show( ['View Zoom/Pan State', '3D Section Box State', 'Viewport Placement on Sheet', 'Visibility Graphics', 'Crop Region'], message='Select property to be applied to current view:' ) if selected_switch == 'View Zoom/Pan State': datafile = \ script.get_document_data_file(file_id='SaveRevitActiveViewZoomState', file_ext='pym', add_cmd_name=False) try: f = open(datafile, 'r') p2 = pickle.load(f) p1 = pickle.load(f) f.close() vc1 = DB.XYZ(p1.x, p1.y, 0) vc2 = DB.XYZ(p2.x, p2.y, 0) av = revit.uidoc.GetOpenUIViews()[0] av.ZoomAndCenterRectangle(vc1, vc2) except Exception: logger.error('CAN NOT FIND ZOOM STATE FILE:\n{0}'.format(datafile)) elif selected_switch == '3D Section Box State':
# pylint: skip-file from pyrevit import HOST_APP, EXEC_PARAMS from pyrevit import revit, script args = EXEC_PARAMS.event_args import hooks_logger as hl hl.log_hook(__file__, { "cancellable?": str(args.Cancellable), "doc": str(revit.doc), "status": str(args.Status), "script_doc": script.get_document_data_file('this', '.dat') }, log_doc_access=True)
# -*- coding: utf-8 -*- import os import os.path as op import sys import pickle from pyrevit.framework import List from pyrevit import revit, DB from pyrevit import script logger = script.get_logger() datafile = script.get_document_data_file("SelList", "pym") index_datafile = script.get_document_data_file("SelListPrevNextIndex", "pym") selection = revit.get_selection() def iterate(mode, step_size=1): if op.exists(index_datafile): with open(index_datafile, 'r') as f: idx = pickle.load(f) if mode == '-': idx = idx - step_size else: idx = idx + step_size else: idx = 0 try:
except: from pyrevit import versionmgr PYREVIT_VERSION = versionmgr.get_pyrevit_version() pyRevitNewer44 = PYREVIT_VERSION.major >= 4 and PYREVIT_VERSION.minor >= 5 if pyRevitNewer44: from pyrevit import script, revit from pyrevit.forms import WPFWindow output = script.get_output() logger = script.get_logger() linkify = output.linkify doc = revit.doc uidoc = revit.uidoc selection = revit.get_selection() datafile = script.get_document_data_file("SelList", "pym") my_config = script.get_config() else: from scriptutils import logger from scriptutils import this_script as script from revitutils import doc, uidoc from scriptutils.userinput import WPFWindow my_config = script.config output = script.output datafile = script.get_document_data_file(0, "pym", command_name="SelList") import os import re import pickle as pl
class PropKeyValue(object): """Storage class for matched property info and value.""" def __init__(self, name, datatype, value, istype): self.name = name self.datatype = datatype self.value = value self.istype = istype def __repr__(self): return str(self.__dict__) MEMFILE = script.get_document_data_file( file_id='MatchSelectedProperties', file_ext='pym', add_cmd_name=False ) def match_prop(dest_inst, dest_type, src_props): """Match given properties on target instance or type""" for pkv in src_props: logger.debug("Applying %s", pkv.name) # determine target target = dest_type if pkv.istype else dest_inst # ensure target is valid if it is type if pkv.istype and not target: logger.warning("Element type is not accessible.") continue