From 6c2acbb16f185466ccf66e10e9f62181aeef3a69 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Mon, 8 Oct 2018 10:14:23 -0700 Subject: [PATCH 01/23] A few tool fixes and todos --- dev/todo.todo | 1 + .../Purge Unused Filters.pushbutton/script.py | 50 +++++++++---------- .../script.py | 4 +- .../Orient View To Face.pushbutton/script.py | 2 +- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/dev/todo.todo b/dev/todo.todo index b34411f7f..643ac683e 100644 --- a/dev/todo.todo +++ b/dev/todo.todo @@ -3,5 +3,6 @@ pyrevit cli: installer: pyrevit: + ☐ faster titleblock selection tool ☐ slowly move collectors in List tool to db.query ☐ slowly phase out the extpackages module and user PyRevitLabs diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Purge Unused Filters.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Purge Unused Filters.pushbutton/script.py index ac3bea39b..f0cc991c7 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Purge Unused Filters.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Purge Unused Filters.pushbutton/script.py @@ -45,28 +45,28 @@ def name(self): if not unusedFilters: forms.alert('All filters are in use. No purging in necessary.') - -# ask user for wipe actions -return_options = \ - forms.SelectFromList.show( - [ViewFilterToPurge(revit.doc.GetElement(DB.ElementId(x))) - for x in unusedFilters], - title='Select Filters to Purge', - width=500, - button_name='Purge Filters', - multiselect=True - ) - -# print('{} Filters have not been used and will be purged.' -# .format(len(unusedFilters))) - -if return_options: - with revit.Transaction('Purge Unused Filters'): - for vf in return_options: - logger.debug('Purging Filter: {0}\t{1}' - .format(vf.Id, vf.Name)) - try: - revit.doc.Delete(vf.Id) - except Exception as del_err: - logger.error('Error purging filter: {} | {}' - .format(vf.Name, del_err)) +else: + # ask user for wipe actions + return_options = \ + forms.SelectFromList.show( + [ViewFilterToPurge(revit.doc.GetElement(DB.ElementId(x))) + for x in unusedFilters], + title='Select Filters to Purge', + width=500, + button_name='Purge Filters', + multiselect=True + ) + + # print('{} Filters have not been used and will be purged.' + # .format(len(unusedFilters))) + + if return_options: + with revit.Transaction('Purge Unused Filters'): + for vf in return_options: + logger.debug('Purging Filter: {0}\t{1}' + .format(vf.Id, vf.Name)) + try: + revit.doc.Delete(vf.Id) + except Exception as del_err: + logger.error('Error purging filter: {} | {}' + .format(vf.Name, del_err)) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Purge Unused View Templates.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Purge Unused View Templates.pushbutton/script.py index 26e79ab9c..32df3d89f 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Purge Unused View Templates.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Purge Unused View Templates.pushbutton/script.py @@ -35,7 +35,9 @@ def name(self): unusedvtemp = vtemp - usedvtemp -if unusedvtemp: +if not unusedvtemp: + forms.alert('All View Templates are in use. No purging in necessary.') +else: # ask user for wipe actions return_options = \ forms.SelectFromList.show( diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Orient View To Face.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Orient View To Face.pushbutton/script.py index 81e085083..b41eb66b3 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Orient View To Face.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Orient View To Face.pushbutton/script.py @@ -41,7 +41,7 @@ def reorient(): curview = revit.activeview -if isinstance(curview, DB.View3D) and curview.IsSectionBoxActive: +if isinstance(curview, DB.View3D): reorient() else: forms.alert('You must be on a 3D view for this tool to work.') From 0fbcea8b65e5cfc6d76e1c96369016777b70fde3 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Mon, 8 Oct 2018 10:43:24 -0700 Subject: [PATCH 02/23] Rocket mode is not experimental anymore --- .../pyRevit.panel/Settings.smartbutton/SettingsWindow.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/Settings.smartbutton/SettingsWindow.xaml b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/Settings.smartbutton/SettingsWindow.xaml index ca2024444..8ef887247 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/Settings.smartbutton/SettingsWindow.xaml +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/Settings.smartbutton/SettingsWindow.xaml @@ -80,7 +80,7 @@ - Rocket Mode 🚀 (Experimental / Reload Required) + Rocket Mode 🚀 (Reload Required) This is the switch for pyRevit Rocket Mode. If enabled, pyRevit will use a shared engine per each extension From e37b34d0335232cb5cd312855c358dfe53312666 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Mon, 8 Oct 2018 10:47:03 -0700 Subject: [PATCH 03/23] Removed debug REPL project Will focus more on logging capabilities --- .../pyrevit/loader/basetypes/replctrl.cs | 36 +++++++++---------- .../pyrevit/loader/basetypes/scriptoutput.cs | 34 +++++++++--------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pyrevitlib/pyrevit/loader/basetypes/replctrl.cs b/pyrevitlib/pyrevit/loader/basetypes/replctrl.cs index 1334d09da..73c414ecc 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/replctrl.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/replctrl.cs @@ -1,20 +1,20 @@ -using System.Windows.Controls; -using System.Windows.Media; +//using System.Windows.Controls; +//using System.Windows.Media; -namespace PyRevitBaseClasses { - public partial class REPLControl : TextBlock - { - public REPLControl() - { - InitializeComponent(); - } +//namespace PyRevitBaseClasses { +// public partial class REPLControl : TextBlock +// { +// public REPLControl() +// { +// InitializeComponent(); +// } - private void InitializeComponent() - { - this.FontFamily = new FontFamily("Verdana"); - this.Text = "IronPython 2.7.X on .NET 4.X (64-bit)" + - "\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information." + - "\n >>> REPL Prompt Coming Soon..."; - } - } -} +// private void InitializeComponent() +// { +// this.FontFamily = new FontFamily("Verdana"); +// this.Text = "IronPython 2.7.X on .NET 4.X (64-bit)" + +// "\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information." + +// "\n >>> REPL Prompt Coming Soon..."; +// } +// } +//} diff --git a/pyrevitlib/pyrevit/loader/basetypes/scriptoutput.cs b/pyrevitlib/pyrevit/loader/basetypes/scriptoutput.cs index 53ef99a74..38623c8af 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/scriptoutput.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/scriptoutput.cs @@ -192,29 +192,29 @@ public void InitializeComponent() { var rendererRow = new RowDefinition(); baseGrid.RowDefinitions.Add(rendererRow); - if (_debugMode) { - var splitterRow = new RowDefinition(); - var replRow = new RowDefinition(); + //if (_debugMode) { + // var splitterRow = new RowDefinition(); + // var replRow = new RowDefinition(); - splitterRow.Height = new GridLength(6); - replRow.Height = new GridLength(100); + // splitterRow.Height = new GridLength(6); + // replRow.Height = new GridLength(100); - baseGrid.RowDefinitions.Add(splitterRow); - baseGrid.RowDefinitions.Add(replRow); + // baseGrid.RowDefinitions.Add(splitterRow); + // baseGrid.RowDefinitions.Add(replRow); - var splitter = new GridSplitter(); - splitter.ResizeDirection = GridResizeDirection.Rows; - splitter.HorizontalAlignment = HorizontalAlignment.Stretch; - splitter.Background = Brushes.LightGray; + // var splitter = new GridSplitter(); + // splitter.ResizeDirection = GridResizeDirection.Rows; + // splitter.HorizontalAlignment = HorizontalAlignment.Stretch; + // splitter.Background = Brushes.LightGray; - var repl = new REPLControl(); + // var repl = new REPLControl(); - Grid.SetRow(splitter, 2); - Grid.SetRow(repl, 3); + // Grid.SetRow(splitter, 2); + // Grid.SetRow(repl, 3); - baseGrid.Children.Add(splitter); - baseGrid.Children.Add(repl); - } + // baseGrid.Children.Add(splitter); + // baseGrid.Children.Add(repl); + //} // set activity bar and host Grid.SetRow(activityBar, 0); From 35ee5fb114f1a6f1747f52e8e1090a529d94bc78 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Mon, 8 Oct 2018 15:59:31 -0700 Subject: [PATCH 04/23] A few tool fixes --- .../Tools.stack2/Sum.pushbutton/script.py | 5 ++-- .../Find Referring Views.pushbutton/script.py | 23 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack2/Sum.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack2/Sum.pushbutton/script.py index 38eacca76..79f70b607 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack2/Sum.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack2/Sum.pushbutton/script.py @@ -149,8 +149,9 @@ def process_sets(element_list): el_sets[el.LineStyle.Name].append(el) else: eltype = revit.doc.GetElement(el.GetTypeId()) - wrapped_eltype = revit.ElementWrapper(eltype) - el_sets[wrapped_eltype.name].append(el) + if eltype: + wrapped_eltype = revit.ElementWrapper(eltype) + el_sets[wrapped_eltype.name].append(el) return el_sets diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Find Referring Views.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Find Referring Views.pushbutton/script.py index cb4dff902..de6c4bb88 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Find Referring Views.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Find Referring Views.pushbutton/script.py @@ -5,6 +5,7 @@ from pyrevit import script +logger = script.get_logger() output = script.get_output() @@ -30,12 +31,12 @@ class ReferencingView: def __init__(self, view_id): - self.element = doc.GetElement(view_id) + self.element = revit.doc.GetElement(view_id) if not self._valid_view(): raise Exception() - title = self.element.LookupParameter('Title on Sheet').AsString() - self.name = title if title else self.element.ViewName + titleos = self.element.LookupParameter('Title on Sheet').AsString() + self.name = titleos if titleos else self.element.ViewName self.refs = [] self._update_refs(all_ref_els) # self._update_refs(self.element.GetReferenceCallouts()) @@ -59,9 +60,12 @@ def _valid_view(self): def _update_refs(self, el_list): for elid in el_list: - el = doc.GetElement(elid) - if el.OwnerViewId == self.element.Id: - self.refs.append(el.Name) + element = revit.doc.GetElement(elid) + viewnameparam = element.LookupParameter("View Name") + if element.OwnerViewId == self.element.Id \ + or (viewnameparam \ + and viewnameparam.AsString() == self.element.ViewName): + self.refs.append(element.Name) def is_referring_to(self, view_name): return view_name in self.refs @@ -76,14 +80,13 @@ def is_sheeted(self): try: rv = ReferencingView(view.Id) all_views.append(rv) - except Exception: - pass + except Exception as ex: + logger.debug(ex) print('{} views processed...'.format(len(all_views))) -for selid in selection: - vp = revit.doc.GetElement(selid) +for vp in selection: if isinstance(vp, DB.Viewport): v = revit.doc.GetElement(vp.ViewId) title = v.LookupParameter('Title on Sheet').AsString() From ca20a6351928aa10fdafd3fd3325f4c4f4337059 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Tue, 9 Oct 2018 19:51:29 -0700 Subject: [PATCH 05/23] Resolved issue #384 --- .../Tag All in All Views.pushbutton/script.py | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit.stack3/Edit.pulldown/Tag All in All Views.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit.stack3/Edit.pulldown/Tag All in All Views.pushbutton/script.py index e6c4c0221..281f0baef 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit.stack3/Edit.pulldown/Tag All in All Views.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit.stack3/Edit.pulldown/Tag All in All Views.pushbutton/script.py @@ -1,9 +1,12 @@ +"""Tag all chosen element types in all views.""" +#pylint: disable=C0103,E0401,C0111 from pyrevit import revit, DB from pyrevit import script from pyrevit import forms logger = script.get_logger() +output = script.get_output() views = DB.FilteredElementCollector(revit.doc)\ @@ -12,7 +15,7 @@ .ToElements() -def GetElementCenter(el, v): +def GetElementCenter(el): cen = el.Location.Point z = (el.UpperLimit.Elevation + el.LimitOffset) / 2 cen = cen.Add(DB.XYZ(0, 0, z)) @@ -26,41 +29,49 @@ def tag_all_rooms(): .ToElements() with revit.Transaction('Tag All Rooms in All Views'): - for v in views: + for view in views: for el in rooms: - room_center = GetElementCenter(el, v) - if type(v) in [DB.ViewSection, DB.ViewPlan]: - logger.debug('Working on view: %s' % v.ViewName) - roomtag = \ + room_center = GetElementCenter(el) + if not room_center: + logger.debug('Can not detect center for element: {}', + output.linkify(el.Id)) + continue + if isinstance(view, (DB.ViewSection, DB.ViewPlan)): + logger.debug('Working on view: %s' % view.ViewName) + room_tag = \ revit.doc.Create.NewRoomTag( DB.LinkElementId(el.Id), DB.UV(room_center.X, room_center.Y), - v.Id + view.Id ) - if isinstance(v, DB.ViewSection): - roomtag.Location.Move(DB.XYZ(0, 0, room_center.Z)) + if isinstance(view, DB.ViewSection): + room_tag.Location.Move(DB.XYZ(0, 0, room_center.Z)) def tag_all_spaces(): spaces = DB.FilteredElementCollector(revit.doc)\ - .OfCategory(DB.BuiltInCategory.OST_MEPSpaces)\ - .WhereElementIsNotElementType()\ - .ToElements() + .OfCategory(DB.BuiltInCategory.OST_MEPSpaces)\ + .WhereElementIsNotElementType()\ + .ToElements() with revit.Transaction('Tag All Spaces in All Views'): - for v in views: + for view in views: for el in spaces: - room_center = GetElementCenter(el, v) - if type(v) in [DB.ViewSection, DB.ViewPlan]: - logger.debug('Working on view: %s' % v.ViewName) - roomtag = \ + space_center = GetElementCenter(el) + if not space_center: + logger.debug('Can not detect center for element: {}', + output.linkify(el.Id)) + continue + if isinstance(view, (DB.ViewSection, DB.ViewPlan)): + logger.debug('Working on view: %s' % view.ViewName) + space_tag = \ revit.doc.Create.NewRoomTag( DB.LinkElementId(el.Id), - DB.UV(room_center.X, room_center.Y), - v.Id + DB.UV(space_center.X, space_center.Y), + view.Id ) - if isinstance(v, DB.ViewSection): - roomtag.Location.Move(DB.XYZ(0, 0, room_center.Z)) + if isinstance(view, DB.ViewSection): + space_tag.Location.Move(DB.XYZ(0, 0, space_center.Z)) options_dict = {'Tag All Rooms in All Views': tag_all_rooms, From 1a3b4987e5d9b93e01f8e0f07ea005831ef70c4b Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Wed, 10 Oct 2018 10:27:12 -0700 Subject: [PATCH 06/23] Make pattern now accepts model lines as well --- .../Make Pattern.pushbutton/script.py | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/Patterns.splitpushbutton/Make Pattern.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/Patterns.splitpushbutton/Make Pattern.pushbutton/script.py index 6d7a06c94..98cb0be31 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/Patterns.splitpushbutton/Make Pattern.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/Patterns.splitpushbutton/Make Pattern.pushbutton/script.py @@ -1,9 +1,9 @@ +#pylint: disable=C0111,E0401,C0103,W0201,W0613 import re -from pyrevit import coreutils from pyrevit.coreutils import pyutils from pyrevit import forms -from pyrevit import revit, DB, UI +from pyrevit import revit, DB from pyrevit import script import patmaker @@ -35,14 +35,19 @@ selection = revit.get_selection() -accpeted_lines = [DB.DetailLine, - DB.DetailArc, - DB.DetailEllipse, - DB.DetailNurbSpline] -accpeted_curves = [DB.Arc, - DB.Ellipse, - DB.NurbSpline] +acceptable_lines = (DB.DetailLine, + DB.DetailArc, + DB.DetailEllipse, + DB.DetailNurbSpline, + DB.ModelLine, + DB.ModelArc, + DB.ModelEllipse, + DB.ModelNurbSpline) + +acceptable_curves = (DB.Arc, + DB.Ellipse, + DB.NurbSpline) detail_line_types = [DB.DetailLine, DB.DetailEllipse, @@ -115,12 +120,18 @@ def update_fillgrid(self, rvt_fillgrid, scale): return rvt_fillgrid + def grab_geom_curves(self, line): + return line.GeometryCurve + + def convert_to_acceptable_line(self): + pass + def cleanup_selection(self, rvt_elements, for_model=True): - lines = [] + geom_curves = [] adjusted_fillgrids = [] for element in rvt_elements: - if type(element) in accpeted_lines: - lines.append(element) + if isinstance(element, acceptable_lines): + geom_curves.append(self.grab_geom_curves(element)) elif isinstance(element, DB.FilledRegion): frtype = revit.doc.GetElement(element.GetTypeId()) fillpat_element = revit.doc.GetElement(frtype.FillPatternId) @@ -134,7 +145,7 @@ def cleanup_selection(self, rvt_elements, for_model=True): else: adjusted_fillgrids.extend(fillgrids) - return lines, adjusted_fillgrids + return geom_curves, adjusted_fillgrids def setup_patnames(self): existing_pats = DB.FilteredElementCollector(revit.doc)\ @@ -216,14 +227,13 @@ def export_pattern(self, export_dir): def create_pattern(self, domain, export_only=False, export_path=None): # cleanup selection (pick only acceptable curves) - self.selected_lines, self.selected_fillgrids = \ + self.selected_geom_curves, self.selected_fillgrids = \ self.cleanup_selection(self._selection, for_model=self.is_model_pat) line_tuples = [] - for det_line in self.selected_lines: - geom_curve = det_line.GeometryCurve - if type(geom_curve) in accpeted_curves: + for geom_curve in self.selected_geom_curves: + if isinstance(geom_curve, acceptable_curves): tes_points = [tp for tp in geom_curve.Tessellate()] for xyz1, xyz2 in pyutils.pairwise(tes_points, step=1): line_tuples.append(self.make_pattern_line(xyz1, xyz2)) From c9251c2cabf6054007d12be3b1da7ffcec0bf40a Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Wed, 10 Oct 2018 10:27:17 -0700 Subject: [PATCH 07/23] Updated todos --- dev/todo.todo | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/todo.todo b/dev/todo.todo index 643ac683e..b5be12d9f 100644 --- a/dev/todo.todo +++ b/dev/todo.todo @@ -3,6 +3,7 @@ pyrevit cli: installer: pyrevit: - ☐ faster titleblock selection tool + ☐ faster sheet titleblock selection tool + ☐ the help uri for splitpushbutton doesn't work correctly e.g match tool ☐ slowly move collectors in List tool to db.query ☐ slowly phase out the extpackages module and user PyRevitLabs From 266113ea9e354fa6a71d5429318536e4f0906f87 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 11 Oct 2018 12:52:09 -0700 Subject: [PATCH 08/23] Resolved issue #387 --- .../script.py | 67 +++++++++++-------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Print.pulldown/Print Ordered Sheet Index.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Print.pulldown/Print Ordered Sheet Index.pushbutton/script.py index 825bc0323..83a5bdbdc 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Print.pulldown/Print Ordered Sheet Index.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Print.pulldown/Print Ordered Sheet Index.pushbutton/script.py @@ -97,6 +97,18 @@ def show_placeholders(self): def include_placeholders(self): return self.indexspace_cb.IsChecked + @property + def sheet_list(self): + return self.sheets_lb.ItemsSource + + @sheet_list.setter + def sheet_list(self, value): + self.sheets_lb.ItemsSource = value + + @property + def printable_sheets(self): + return [x for x in self.sheet_list if x.printable] + def _get_schedule_text_data(self, schedule_view): schedule_data_file = \ script.get_instance_data_file(str(schedule_view.Id.IntegerValue)) @@ -112,8 +124,8 @@ def _get_schedule_text_data(self, schedule_view): as sched_data_file: return sched_data_file.readlines() except Exception as open_err: - logger.error('Error opening sheet index export: {} | {}' - .format(schedule_data_file, open_err)) + logger.error('Error opening sheet index export: %s | %s', + schedule_data_file, open_err) return sched_data def _order_sheets_by_schedule_data(self, schedule_view, sheet_list): @@ -126,13 +138,12 @@ def _order_sheets_by_schedule_data(self, schedule_view, sheet_list): for sheet in sheet_list: for line_no, data_line in enumerate(sched_data): try: - if sheet.CanBePrinted: - if sheet.SheetNumber in data_line: - ordered_sheets_dict[line_no] = sheet - break - else: - logger.warning('Sheet {} is not printable.' - .format(sheet.SheetNumber)) + if sheet.SheetNumber in data_line: + ordered_sheets_dict[line_no] = sheet + break + if not sheet.CanBePrinted: + logger.debug('Sheet %s is not printable.', + sheet.SheetNumber) except Exception: continue @@ -166,7 +177,7 @@ def _get_printmanager(self): except Exception as printerr: logger.critical('Error getting printer manager from document. ' 'Most probably there is not a printer defined ' - 'on your system. | {}'.format(printerr)) + 'on your system. | %s', printerr) return None def _print_combined_sheets_in_order(self): @@ -182,11 +193,13 @@ def _print_combined_sheets_in_order(self): sheet_set = DB.ViewSet() original_sheetnums = [] with revit.Transaction('Fix Sheet Numbers') as t: - for idx, sheet in enumerate(self.sheets_lb.ItemsSource): - sht = sheet.revit_sheet - original_sheetnums.append(sht.SheetNumber) - sht.SheetNumber = NPC * (idx + 1) + sht.SheetNumber - sheet_set.Insert(sht) + for idx, sheet in enumerate(self.sheet_list): + rvtsheet = sheet.revit_sheet + original_sheetnums.append(rvtsheet.SheetNumber) + rvtsheet.SheetNumber = \ + NPC * (idx + 1) + rvtsheet.SheetNumber + if sheet.printable: + sheet_set.Insert(rvtsheet) # Collect existing sheet sets cl = DB.FilteredElementCollector(revit.doc) @@ -222,7 +235,7 @@ def _print_combined_sheets_in_order(self): logger.critical( 'Error setting sheet set on print mechanism. ' 'These items are included in the viewset ' - 'object:\n{}'.format(sheet_report) + 'object:\n%s', sheet_report ) raise viewset_err @@ -241,10 +254,10 @@ def _print_combined_sheets_in_order(self): # now fix the sheet names with revit.Transaction('Restore Sheet Numbers') as t: - for sheet, sheetnum in zip(self.sheets_lb.ItemsSource, + for sheet, sheetnum in zip(self.sheet_list, original_sheetnums): - sht = sheet.revit_sheet - sht.SheetNumber = sheetnum + rvtsheet = sheet.revit_sheet + rvtsheet.SheetNumber = sheetnum def _print_sheets_in_order(self): # make sure we can access the print config @@ -254,7 +267,7 @@ def _print_sheets_in_order(self): print_mgr.PrintToFile = True # print_mgr.CombinedFile = False print_mgr.PrintRange = DB.PrintRange.Current - for sheet in self.sheets_lb.ItemsSource: + for sheet in self.sheet_list: output_fname = \ coreutils.cleanup_filename('{:05} {} - {}.pdf' .format(sheet.print_index, @@ -265,8 +278,8 @@ def _print_sheets_in_order(self): if sheet.printable: print_mgr.SubmitPrint(sheet.revit_sheet) else: - logger.warning('Sheet {} is not printable. Skipping print.' - .format(sheet.SheetNumber)) + logger.debug('Sheet %s is not printable. Skipping print.', + sheet.number) def _update_print_indices(self, sheet_list): for idx, sheet in enumerate(sheet_list): @@ -295,7 +308,7 @@ def selection_changed(self, sender, args): if not self.include_placeholders: self._update_print_indices(printable_sheets) - self.sheets_lb.ItemsSource = printable_sheets + self.sheet_list = printable_sheets else: self.indexspace_cb.IsChecked = True @@ -303,12 +316,12 @@ def selection_changed(self, sender, args): # update print indices self._update_print_indices(sheet_list) # Show all sheets - self.sheets_lb.ItemsSource = sheet_list + self.sheet_list = sheet_list def print_sheets(self, sender, args): - if self.sheets_lb.ItemsSource: + if self.sheet_list: if not self.combine_print: - sheet_count = len(self.sheets_lb.ItemsSource) + sheet_count = len(self.sheet_list) if sheet_count > 5: if not forms.alert('Are you sure you want to print {} ' 'sheets individually? The process can ' @@ -340,7 +353,7 @@ def drop_sheet(self, sender, args): dropped_idx = self.sheets_lb.Items.IndexOf(dropped_data) target_idx = self.sheets_lb.Items.IndexOf(target) - sheet_list = self.sheets_lb.ItemsSource + sheet_list = self.sheet_list sheet_list.remove(dropped_data) sheet_list.insert(target_idx, dropped_data) self._update_print_indices(sheet_list) From 614fa0bb1e1a986a5ad0bea2bb0755e3c38c9c60 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 11 Oct 2018 12:52:21 -0700 Subject: [PATCH 09/23] todos --- dev/todo.todo | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/todo.todo b/dev/todo.todo index b5be12d9f..f5e7b4b2d 100644 --- a/dev/todo.todo +++ b/dev/todo.todo @@ -3,6 +3,7 @@ pyrevit cli: installer: pyrevit: + ☐ fix log messages in tools ☐ faster sheet titleblock selection tool ☐ the help uri for splitpushbutton doesn't work correctly e.g match tool ☐ slowly move collectors in List tool to db.query From cda1b3d9bd5bdd61421327df5c4f40968a675713 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 11 Oct 2018 15:36:30 -0700 Subject: [PATCH 10/23] forms improvements --- .../Get Central Path.pushbutton/script.py | 12 +++----- pyrevitlib/pyrevit/__init__.py | 7 +++-- pyrevitlib/pyrevit/forms/SelectFromList.xaml | 3 +- pyrevitlib/pyrevit/forms/__init__.py | 29 ++++++++++++++++--- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/tools.stack3/Spy.pulldown/Get Central Path.pushbutton/script.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/tools.stack3/Spy.pulldown/Get Central Path.pushbutton/script.py index b83a4cc69..2bffc077c 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/tools.stack3/Spy.pulldown/Get Central Path.pushbutton/script.py +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/tools.stack3/Spy.pulldown/Get Central Path.pushbutton/script.py @@ -1,12 +1,8 @@ -__doc__ = 'Print the full path to the central model (if model is workshared).' +"""Print the full path to the central model (if model is workshared).""" - -from pyrevit import revit, DB, UI +#pylint: disable=E0401 +from pyrevit import revit from pyrevit import forms -if revit.doc.IsWorkshared: - model_path = revit.doc.GetWorksharingCentralModelPath() - print(DB.ModelPathUtils.ConvertModelPathToUserVisiblePath(model_path)) -else: - forms.alert('Model is not workshared.') +forms.check_workshared(doc=revit.doc) diff --git a/pyrevitlib/pyrevit/__init__.py b/pyrevitlib/pyrevit/__init__.py index 3f75a3e7c..ccd6c93de 100644 --- a/pyrevitlib/pyrevit/__init__.py +++ b/pyrevitlib/pyrevit/__init__.py @@ -281,13 +281,16 @@ def proc_screen_scalefactor(self): scaled_width = screen.PrimaryScreen.WorkingArea.Width return abs(scaled_width / actual_wdith) - def is_newer_than(self, version): + def is_newer_than(self, version, or_equal=False): """bool: Return True if host app is newer than provided version. Args: version (str or int): version to check against. """ - return int(self.version) > int(version) + if or_equal: + return int(self.version) >= int(version) + else: + return int(self.version) > int(version) def is_older_than(self, version): """bool: Return True if host app is older than provided version. diff --git a/pyrevitlib/pyrevit/forms/SelectFromList.xaml b/pyrevitlib/pyrevit/forms/SelectFromList.xaml index 4a7562681..6985204a6 100644 --- a/pyrevitlib/pyrevit/forms/SelectFromList.xaml +++ b/pyrevitlib/pyrevit/forms/SelectFromList.xaml @@ -11,10 +11,11 @@ - Filter: