From 44e410bccecb11b530a26f6bd1768ddb1436011e Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Tue, 27 Aug 2024 10:39:33 +0200 Subject: [PATCH 01/64] Obsolet IntegerValue property in Revit2024 and higher replaced by Value --- .../LinesPerViewCounter_script.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/LinesPerViewCounter.pushbutton/LinesPerViewCounter_script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/LinesPerViewCounter.pushbutton/LinesPerViewCounter_script.py index 5c154b0b6..79b80d5b1 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/LinesPerViewCounter.pushbutton/LinesPerViewCounter_script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/LinesPerViewCounter.pushbutton/LinesPerViewCounter_script.py @@ -40,7 +40,10 @@ def line_count(document=doc): lines = DB.FilteredElementCollector(document).OfCategory(DB.BuiltInCategory.OST_Lines).WhereElementIsNotElementType().ToElements() for line in lines: if line.CurveElementType.ToString() == "DetailCurve": - view_id_int = line.OwnerViewId.IntegerValue + if HOST_APP.is_newer_than(2023): + view_id_int = line.OwnerViewId.Value + else: + view_id_int = line.OwnerViewId.IntegerValue detail_lines[view_id_int] += 1 for line_count, view_id_int \ in sorted(zip(detail_lines.values(), detail_lines.keys()), From a1d0e0b97e30c62b56f713065138d3d556d34508 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Tue, 27 Aug 2024 10:56:49 +0200 Subject: [PATCH 02/64] Update update.py --- pyrevitlib/pyrevit/revit/db/update.py | 32 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/pyrevitlib/pyrevit/revit/db/update.py b/pyrevitlib/pyrevit/revit/db/update.py index 168e9d756..60d27d3ed 100644 --- a/pyrevitlib/pyrevit/revit/db/update.py +++ b/pyrevitlib/pyrevit/revit/db/update.py @@ -23,25 +23,33 @@ def update_sheet_revisions(revisions, sheets=None, state=True, doc=None): # make sure revisions is a list if not isinstance(revisions, list): revisions = [revisions] - updated_sheets = [] if revisions: # get sheets if not available for sheet in sheets or query.get_sheets(doc=doc): - addrevs = set([x.IntegerValue - for x in sheet.GetAdditionalRevisionIds()]) - for rev in revisions: - # skip issued revisions - if not rev.Issued: - if state: - addrevs.add(rev.Id.IntegerValue) - elif rev.Id.IntegerValue in addrevs: - addrevs.remove(rev.Id.IntegerValue) - + if HOST_APP.is_newer_than(2023): + addrevs = set([x.Value + for x in sheet.GetAdditionalRevisionIds()]) + for rev in revisions: + # skip issued revisions + if not rev.Issued: + if state: + addrevs.add(rev.Id.Value) + elif rev.Id.Value in addrevs: + addrevs.remove(rev.Id.Value) + else: + addrevs = set([x.IntegerValue + for x in sheet.GetAdditionalRevisionIds()]) + for rev in revisions: + # skip issued revisions + if not rev.Issued: + if state: + addrevs.add(rev.Id.IntegerValue) + elif rev.Id.IntegerValue in addrevs: + addrevs.remove(rev.Id.IntegerValue) rev_elids = [DB.ElementId(x) for x in addrevs] sheet.SetAdditionalRevisionIds(List[DB.ElementId](rev_elids)) updated_sheets.append(sheet) - return updated_sheets From af581384ccf199bcada3d7423a7519e6dd797906 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Tue, 27 Aug 2024 10:59:26 +0200 Subject: [PATCH 03/64] Update linkmaker.py --- pyrevitlib/pyrevit/output/linkmaker.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyrevitlib/pyrevit/output/linkmaker.py b/pyrevitlib/pyrevit/output/linkmaker.py index ad83dc546..325e0590c 100644 --- a/pyrevitlib/pyrevit/output/linkmaker.py +++ b/pyrevitlib/pyrevit/output/linkmaker.py @@ -50,9 +50,15 @@ def make_link(element_ids, contents=None): """ try: try: - strids = [safe_strtype(x.IntegerValue) for x in element_ids] + if HOST_APP.is_newer_than(2023): + strids = [safe_strtype(x.Value) for x in element_ids] + else: + strids = [safe_strtype(x.IntegerValue) for x in element_ids] except TypeError: - strids = [safe_strtype(element_ids.IntegerValue)] + if HOST_APP.is_newer_than(2023): + strids = [safe_strtype(element_ids.Value)] + else: + strids = [safe_strtype(element_ids.IntegerValue)] except AttributeError: raise ValueError("One or more items are not ElementIds") From 6ffad4ea3fbb3286602426194f0a5646e41d74b8 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Tue, 27 Aug 2024 11:02:22 +0200 Subject: [PATCH 04/64] Update builtins.py --- pyrevitlib/rpw/db/builtins.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pyrevitlib/rpw/db/builtins.py b/pyrevitlib/rpw/db/builtins.py index 26b9c16b4..954107965 100644 --- a/pyrevitlib/rpw/db/builtins.py +++ b/pyrevitlib/rpw/db/builtins.py @@ -155,15 +155,20 @@ def from_category_id(self, category_id): Returns: ``DB.BuiltInCategory`` member """ - bic = Enum.ToObject(DB.BuiltInCategory, category_id.IntegerValue) - if DB.ElementId(bic).IntegerValue < -1: - return bic + if HOST_APP.is_newer_than(2023): + bic = Enum.ToObject(DB.BuiltInCategory, category_id.Value) + bic_value = DB.ElementId(bic).Value else: - # If you pass a regular element to category_id, it converts it to BIC. - # It should fail, because result is not a valid Category Enum - raise RpwCoerceError('category_id: {}'.format(category_id), - DB.BuiltInCategory) - # Similar to: Category.GetCategory(doc, category.Id).Name + bic = Enum.ToObject(DB.BuiltInCategory, category_id.IntegerValue) + bic_value = DB.ElementId(bic).IntegerValue + if bic_value < -1: + return bic + else: + # If you pass a regular element to category_id, it converts it to BIC. + # It should fail, because result is not a valid Category Enum + raise RpwCoerceError('category_id: {}'.format(category_id), + DB.BuiltInCategory) + # Similar to: Category.GetCategory(doc, category.Id).Name def __repr__(self): return super(_BiCategory, self).__repr__(to_string='Autodesk.Revit.DB.BuiltInCategory') From 261680d32041b7eb6ed4d56419e84f6d8c6140f6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Tue, 27 Aug 2024 11:07:05 +0200 Subject: [PATCH 05/64] Update pkgmgr.py --- .../pyRevitTags.extension/lib/pkgmgr.py | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/extensions/pyRevitTags.extension/lib/pkgmgr.py b/extensions/pyRevitTags.extension/lib/pkgmgr.py index b2a5a2f22..09578fe1d 100644 --- a/extensions/pyRevitTags.extension/lib/pkgmgr.py +++ b/extensions/pyRevitTags.extension/lib/pkgmgr.py @@ -68,11 +68,16 @@ def _read_commit_history(self, commit_cfg): mlogger.debug(self._chistory) # process revisions - sheet_revids = \ - {x.IntegerValue for x in self.revit_sheet.GetAllRevisionIds()} - add_sheet_revids = \ - {x.IntegerValue - for x in self.revit_sheet.GetAdditionalRevisionIds()} + if HOST_APP.is_newer_than(2023): + sheet_revids = \ + {x.Value for x in self.revit_sheet.GetAllRevisionIds()} + add_sheet_revids = \ + {x.Value for x in self.revit_sheet.GetAdditionalRevisionIds()} + else: + sheet_revids = \ + {x.IntegerValue for x in self.revit_sheet.GetAllRevisionIds()} + add_sheet_revids = \ + {x.IntegerValue for x in self.revit_sheet.GetAdditionalRevisionIds()} readonly_sheet_revids = sheet_revids - add_sheet_revids default_rev_commit_type = CommitPointTypes.Revision.default_commit_type @@ -183,19 +188,32 @@ def get_commit_points(): none_numtype = coreutils.get_enum_none(DB.RevisionNumberType) docrevs = sorted(revit.query.get_revisions(), key=lambda x: x.SequenceNumber) - commit_points.extend([ - CommitPoint(cptype=CommitPointTypes.Revision, - target=x.Id.IntegerValue, - idx=last_docpkg_idx + i + 1, - name='R{}'.format(x.SequenceNumber), - desc='{}{} (Sequence #{})'.format( - '{} - '.format(revit.query.get_rev_number(x)) - if revit.ensure.revision_has_numbertype(x) else '', - x.Description, - x.SequenceNumber)) - for i, x in enumerate(docrevs) - ]) - + if HOST_APP.is_newer_than(2023): + commit_points.extend([ + CommitPoint(cptype=CommitPointTypes.Revision, + target=x.Id.Value, + idx=last_docpkg_idx + i + 1, + name='R{}'.format(x.SequenceNumber), + desc='{}{} (Sequence #{})'.format( + '{} - '.format(revit.query.get_rev_number(x)) + if revit.ensure.revision_has_numbertype(x) else '', + x.Description, + x.SequenceNumber)) + for i, x in enumerate(docrevs) + ]) + else: + commit_points.extend([ + CommitPoint(cptype=CommitPointTypes.Revision, + target=x.Id.IntegerValue, + idx=last_docpkg_idx + i + 1, + name='R{}'.format(x.SequenceNumber), + desc='{}{} (Sequence #{})'.format( + '{} - '.format(revit.query.get_rev_number(x)) + if revit.ensure.revision_has_numbertype(x) else '', + x.Description, + x.SequenceNumber)) + for i, x in enumerate(docrevs) + ]) sorted_cpoints = sorted(commit_points, key=lambda x: x.idx) mlogger.debug(sorted_cpoints) return sorted_cpoints From 2182b008ba5717e4d1ccbb1fded4826f47226207 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Tue, 27 Aug 2024 11:10:03 +0200 Subject: [PATCH 06/64] Update family.py --- pyrevitlib/rpw/db/family.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyrevitlib/rpw/db/family.py b/pyrevitlib/rpw/db/family.py index ae867c1a5..ca4768cfc 100644 --- a/pyrevitlib/rpw/db/family.py +++ b/pyrevitlib/rpw/db/family.py @@ -93,7 +93,11 @@ def in_assembly(self): Returns: (bool): True if element is inside an AssemblyInstance """ - if self._revit_object.AssemblyInstanceId.IntegerValue == -1: + if HOST_APP.is_newer_than(2023): + assembly_id_value = self._revit_object.AssemblyInstanceId.Value + else: + assembly_id_value = self._revit_object.AssemblyInstanceId.IntegerValue + if assembly_id_value == -1: return False else: return True From c6af60a73a911d95b90e38a8d84ee428548a7a17 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Tue, 27 Aug 2024 11:16:06 +0200 Subject: [PATCH 07/64] Update create.py --- pyrevitlib/pyrevit/revit/db/create.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pyrevitlib/pyrevit/revit/db/create.py b/pyrevitlib/pyrevit/revit/db/create.py index 0eb279735..e68a5f1cf 100644 --- a/pyrevitlib/pyrevit/revit/db/create.py +++ b/pyrevitlib/pyrevit/revit/db/create.py @@ -292,11 +292,16 @@ def create_revision_sheetset(revisions, check_func = any if match_any else all for sheet in sheets: revs = sheet.GetAllRevisionIds() - sheet_revids = [x.IntegerValue for x in revs] - if check_func([x.Id.IntegerValue in sheet_revids - for x in revisions]): - myviewset.Insert(sheet) - + if HOST_APP.is_newer_than(2023): + sheet_revids = [x.Value for x in revs] + if check_func([x.Id.Value in sheet_revids + for x in revisions]): + myviewset.Insert(sheet) + else: + sheet_revids = [x.IntegerValue for x in revs] + if check_func([x.Id.IntegerValue in sheet_revids + for x in revisions]): + myviewset.Insert(sheet) # needs transaction # delete existing sheet set if any # create new sheet set @@ -436,14 +441,19 @@ def create_param_value_filter(filter_name, str(pvalue), False) elif isinstance(pvalue, DB.ElementId): + if HOST_APP.is_newer_than(2023): + p_id = str(pvalue.Value) + else: + p_id = str(pvalue.IntegerValue) + if HOST_APP.is_newer_than(2022): rule = DB.FilterStringRule(param_prov, num_eval(), - str(pvalue.IntegerValue)) + p_id) else: rule = DB.FilterStringRule(param_prov, num_eval(), - str(pvalue.IntegerValue), + p_id, False) # if value is int, eval is expected to be numeric elif isinstance(pvalue, int): From e42b75810262065e513746f6959b98106341c9b6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Tue, 27 Aug 2024 11:34:13 +0200 Subject: [PATCH 08/64] Update query.py --- pyrevitlib/pyrevit/revit/db/query.py | 111 +++++++++++++++++++-------- 1 file changed, 80 insertions(+), 31 deletions(-) diff --git a/pyrevitlib/pyrevit/revit/db/query.py b/pyrevitlib/pyrevit/revit/db/query.py index e1330fa23..5c62b8b15 100644 --- a/pyrevitlib/pyrevit/revit/db/query.py +++ b/pyrevitlib/pyrevit/revit/db/query.py @@ -760,10 +760,16 @@ def get_schedule_categories(doc=None): doc = doc or DOCS.doc all_cats = get_doc_categories(doc) cats = [] - for cat_id in DB.ViewSchedule.GetValidCategoriesForSchedule(): - for cat in all_cats: - if cat.Id.IntegerValue == cat_id.IntegerValue: - cats.append(cat) + if HOST_APP.is_newer_than(2023): + for cat_id in DB.ViewSchedule.GetValidCategoriesForSchedule(): + for cat in all_cats: + if cat.Id.Value == cat_id.Value: + cats.append(cat) + else: + for cat_id in DB.ViewSchedule.GetValidCategoriesForSchedule(): + for cat in all_cats: + if cat.Id.IntegerValue == cat_id.IntegerValue: + cats.append(cat) return cats @@ -771,10 +777,16 @@ def get_key_schedule_categories(doc=None): doc = doc or DOCS.doc all_cats = get_doc_categories(doc) cats = [] - for cat_id in DB.ViewSchedule.GetValidCategoriesForKeySchedule(): - for cat in all_cats: - if cat.Id.IntegerValue == cat_id.IntegerValue: - cats.append(cat) + if HOST_APP.is_newer_than(2023): + for cat_id in DB.ViewSchedule.GetValidCategoriesForKeySchedule(): + for cat in all_cats: + if cat.Id.Value == cat_id.Value: + cats.append(cat) + else: + for cat_id in DB.ViewSchedule.GetValidCategoriesForKeySchedule(): + for cat in all_cats: + if cat.Id.IntegerValue == cat_id.IntegerValue: + cats.append(cat) return cats @@ -782,10 +794,16 @@ def get_takeoff_categories(doc=None): doc = doc or DOCS.doc all_cats = get_doc_categories(doc) cats = [] - for cat_id in DB.ViewSchedule.GetValidCategoriesForMaterialTakeoff(): - for cat in all_cats: - if cat.Id.IntegerValue == cat_id.IntegerValue: - cats.append(cat) + if HOST_APP.is_newer_than(2023): + for cat_id in DB.ViewSchedule.GetValidCategoriesForMaterialTakeoff(): + for cat in all_cats: + if cat.Id.Value == cat_id.Value: + cats.append(cat) + else: + for cat_id in DB.ViewSchedule.GetValidCategoriesForMaterialTakeoff(): + for cat in all_cats: + if cat.Id.IntegerValue == cat_id.IntegerValue: + cats.append(cat) return cats @@ -797,9 +815,14 @@ def get_category(cat_name_or_builtin, doc=None): if cat.Name == cat_name_or_builtin: return cat elif isinstance(cat_name_or_builtin, DB.BuiltInCategory): - for cat in all_cats: - if cat.Id.IntegerValue == int(cat_name_or_builtin): - return cat + if HOST_APP.is_newer_than(2023): + for cat in all_cats: + if cat.Id.Value == int(cat_name_or_builtin): + return cat + else: + for cat in all_cats: + if cat.Id.IntegerValue == int(cat_name_or_builtin): + return cat elif isinstance(cat_name_or_builtin, DB.Category): return cat_name_or_builtin @@ -807,12 +830,20 @@ def get_category(cat_name_or_builtin, doc=None): def get_builtincategory(cat_name_or_id, doc=None): doc = doc or DOCS.doc cat_id = None - if isinstance(cat_name_or_id, str): - cat = get_category(cat_name_or_id) - if cat: - cat_id = cat.Id.IntegerValue - elif isinstance(cat_name_or_id, DB.ElementId): - cat_id = cat_name_or_id.IntegerValue + if HOST_APP.is_newer_than(2023): + if isinstance(cat_name_or_id, str): + cat = get_category(cat_name_or_id) + if cat: + cat_id = cat.Id.Value + elif isinstance(cat_name_or_id, DB.ElementId): + cat_id = cat_name_or_id.Value + else: + if isinstance(cat_name_or_id, str): + cat = get_category(cat_name_or_id) + if cat: + cat_id = cat.Id.IntegerValue + elif isinstance(cat_name_or_id, DB.ElementId): + cat_id = cat_name_or_id.IntegerValue if cat_id: for bicat in DB.BuiltInCategory.GetValues(DB.BuiltInCategory): if int(bicat) == cat_id: @@ -823,15 +854,26 @@ def get_subcategories(doc=None, purgable=False, filterfunc=None): doc = doc or DOCS.doc # collect custom categories subcategories = [] - for cat in doc.Settings.Categories: - for subcat in cat.SubCategories: - if purgable: - if subcat.Id.IntegerValue > 1: + if HOST_APP.is_newer_than(2023): + for cat in doc.Settings.Categories: + for subcat in cat.SubCategories: + if purgable: + if subcat.Id.Value > 1: + subcategories.append(subcat) + else: subcategories.append(subcat) - else: - subcategories.append(subcat) - if filterfunc: - subcategories = filter(filterfunc, subcategories) + if filterfunc: + subcategories = filter(filterfunc, subcategories) + else: + for cat in doc.Settings.Categories: + for subcat in cat.SubCategories: + if purgable: + if subcat.Id.IntegerValue > 1: + subcategories.append(subcat) + else: + subcategories.append(subcat) + if filterfunc: + subcategories = filter(filterfunc, subcategories) return subcategories @@ -849,8 +891,12 @@ def get_builtinparameter(element, param_name, doc=None): doc = doc or DOCS.doc eparam = element.LookupParameter(param_name) if eparam: + if HOST_APP.is_newer_than(2023): + eparam_def_id = eparam.Definition.Id.Value + else: + eparam_def_id = eparam.Definition.Id.IntegerValue for biparam in DB.BuiltInParameter.GetValues(DB.BuiltInParameter): - if int(biparam) == eparam.Definition.Id.IntegerValue: + if int(biparam) == eparam_def_id: return biparam @@ -1585,5 +1631,8 @@ def get_geometry(element, include_invisible=False, compute_references=False): geom_objs.append(gobj) return geom_objs except TypeError: - mlogger.debug("element %s has no geometry", element.Id.IntegerValue) + if HOST_APP.is_newer_than(2023): + mlogger.debug("element %s has no geometry", element.Id.Value) + else: + mlogger.debug("element %s has no geometry", element.Id.IntegerValue) return From 87e2ee5f999e0a0eb37f6ff87bdf8e7a8830d089 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Tue, 27 Aug 2024 11:54:12 +0200 Subject: [PATCH 09/64] Update parameter.py --- pyrevitlib/rpw/db/parameter.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyrevitlib/rpw/db/parameter.py b/pyrevitlib/rpw/db/parameter.py index 235191c7d..1502186f5 100644 --- a/pyrevitlib/rpw/db/parameter.py +++ b/pyrevitlib/rpw/db/parameter.py @@ -296,8 +296,13 @@ def to_dict(self): * value: Uses best parameter method based on StorageType * value_string: Parameter.AsValueString """ - value = self.value if not isinstance(self.value, DB.ElementId) \ - else self.value.IntegerValue + if not isinstance(self.value, DB.ElementId): + value = self.value + else: + if HOST_APP.is_newer_than(2023): + value = self.value.Value + else: + value = self.value.IntegerValue return { 'name': self.name, 'type': self.type.__name__, From bf1335108568583390433f3d0df1159641248f1a Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:03:57 +0200 Subject: [PATCH 10/64] Add get_value_func for ElementId Class --- pyrevitlib/pyrevit/compat.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pyrevitlib/pyrevit/compat.py b/pyrevitlib/pyrevit/compat.py index 8b5115685..43950e6d7 100644 --- a/pyrevitlib/pyrevit/compat.py +++ b/pyrevitlib/pyrevit/compat.py @@ -11,7 +11,7 @@ PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 -IRONPY2711 = sys.version_info[:3] == (2, 7, 11) +IRONPY2712 = sys.version_info[:3] == (2, 7, 12) IRONPY340 = sys.version_info[:3] == (3, 4, 0) #pylint: disable=import-error,unused-import @@ -58,6 +58,35 @@ def is_netcore(): safe_strtype = lambda x: unicode(x) #pylint: disable=E0602,unnecessary-lambda +def get_value_func(): + """Determines and returns the appropriate value extraction function based on the host application's version. + + Returns: + function: A function that takes an item as an argument and returns its value. + If the host application version is newer than 2023, it returns the `get_value_2024` function, + which extracts the `Value` attribute from the item. + Otherwise, it returns the `get_value_2003` function, which extracts the `IntegerValue` attribute from the item. + + Functions: + get_value_2024(item): Extracts the `Value` attribute from the given item. + get_value_2003(item): Extracts the `IntegerValue` attribute from the given item. + + Examples: + ```python + value_func = get_value_func() + sheet_revids = {value_func(x) for x in self.revit_sheet.GetAllRevisionIds()} + add_sheet_revids = {value_func(x) x in self.revit_sheet.GetAdditionalRevisionIds()} + ``` + """ + def get_value_2024(item): + return item.Value + + def get_value_2003(item): + return item.IntegerValue + + return get_value_2024 if __revit__.Application.is_newer_than(2023) else get_value_2003 + + def urlopen(url): """Urlopen wrapper. From 7698bf34b2acac2b2820e3db7789035d409b30ed Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:08:26 +0200 Subject: [PATCH 11/64] updated with compat func --- extensions/pyRevitTags.extension/lib/pkgmgr.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/extensions/pyRevitTags.extension/lib/pkgmgr.py b/extensions/pyRevitTags.extension/lib/pkgmgr.py index 09578fe1d..ab933985e 100644 --- a/extensions/pyRevitTags.extension/lib/pkgmgr.py +++ b/extensions/pyRevitTags.extension/lib/pkgmgr.py @@ -6,6 +6,7 @@ from pyrevit import coreutils from pyrevit.coreutils import logger from pyrevit import revit, DB +from pyrevit.compat import get_value_func from pkgcommits import CommitPointTypes, CommitTypes from pkgcommits import CommitPoint, Commit, CommitHistory @@ -68,16 +69,9 @@ def _read_commit_history(self, commit_cfg): mlogger.debug(self._chistory) # process revisions - if HOST_APP.is_newer_than(2023): - sheet_revids = \ - {x.Value for x in self.revit_sheet.GetAllRevisionIds()} - add_sheet_revids = \ - {x.Value for x in self.revit_sheet.GetAdditionalRevisionIds()} - else: - sheet_revids = \ - {x.IntegerValue for x in self.revit_sheet.GetAllRevisionIds()} - add_sheet_revids = \ - {x.IntegerValue for x in self.revit_sheet.GetAdditionalRevisionIds()} + value_func = get_value_func() + sheet_revids = {value_func(x) for x in self.revit_sheet.GetAllRevisionIds()} + add_sheet_revids = {value_func(x) for x in self.revit_sheet.GetAdditionalRevisionIds()} readonly_sheet_revids = sheet_revids - add_sheet_revids default_rev_commit_type = CommitPointTypes.Revision.default_commit_type From 1bdabda23302c8d2da1f27d3c961899394b16389 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:11:06 +0200 Subject: [PATCH 12/64] updated with compat func --- .../LinesPerViewCounter_script.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/LinesPerViewCounter.pushbutton/LinesPerViewCounter_script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/LinesPerViewCounter.pushbutton/LinesPerViewCounter_script.py index 79b80d5b1..7441f3956 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/LinesPerViewCounter.pushbutton/LinesPerViewCounter_script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/LinesPerViewCounter.pushbutton/LinesPerViewCounter_script.py @@ -3,6 +3,7 @@ from pyrevit import script from pyrevit import revit, DB +from pyrevit.compat import get_value_func __title__ = 'Lines Per View Counter' @@ -40,10 +41,8 @@ def line_count(document=doc): lines = DB.FilteredElementCollector(document).OfCategory(DB.BuiltInCategory.OST_Lines).WhereElementIsNotElementType().ToElements() for line in lines: if line.CurveElementType.ToString() == "DetailCurve": - if HOST_APP.is_newer_than(2023): - view_id_int = line.OwnerViewId.Value - else: - view_id_int = line.OwnerViewId.IntegerValue + value_func = get_value_func() + view_id_int = value_func(line.OwnerViewId) detail_lines[view_id_int] += 1 for line_count, view_id_int \ in sorted(zip(detail_lines.values(), detail_lines.keys()), From 432633e97fdad9030de178c4ba6c7b4d78730354 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:13:46 +0200 Subject: [PATCH 13/64] updated with compat func --- pyrevitlib/pyrevit/output/linkmaker.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pyrevitlib/pyrevit/output/linkmaker.py b/pyrevitlib/pyrevit/output/linkmaker.py index 325e0590c..48a8a625d 100644 --- a/pyrevitlib/pyrevit/output/linkmaker.py +++ b/pyrevitlib/pyrevit/output/linkmaker.py @@ -1,6 +1,6 @@ """Handle creation of output window helper links.""" -from pyrevit.compat import safe_strtype +from pyrevit.compat import safe_strtype, get_value_func from pyrevit import DB from pyrevit.coreutils.logger import get_logger @@ -48,17 +48,12 @@ def make_link(element_ids, contents=None): print('{}: {}'.format(idx+1, output.linkify(elid))) ``` """ + value_func = get_value_func() try: try: - if HOST_APP.is_newer_than(2023): - strids = [safe_strtype(x.Value) for x in element_ids] - else: - strids = [safe_strtype(x.IntegerValue) for x in element_ids] + strids = [safe_strtype(value_func(x)) for x in element_ids] except TypeError: - if HOST_APP.is_newer_than(2023): - strids = [safe_strtype(element_ids.Value)] - else: - strids = [safe_strtype(element_ids.IntegerValue)] + strids = [safe_strtype(value_func(element_ids))] except AttributeError: raise ValueError("One or more items are not ElementIds") From 2bb0b662f123d5a5cba835a24642efa87a2155ac Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:21:58 +0200 Subject: [PATCH 14/64] updated with compat func --- pyrevitlib/pyrevit/revit/db/create.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pyrevitlib/pyrevit/revit/db/create.py b/pyrevitlib/pyrevit/revit/db/create.py index e68a5f1cf..3291a409b 100644 --- a/pyrevitlib/pyrevit/revit/db/create.py +++ b/pyrevitlib/pyrevit/revit/db/create.py @@ -8,6 +8,7 @@ from pyrevit.coreutils.logger import get_logger from pyrevit import DB from pyrevit.revit.db import query +from pyrevit.compat import get_value_func #pylint: disable=W0703,C0302,C0103 @@ -290,17 +291,11 @@ def create_revision_sheetset(revisions, # find revised sheets myviewset = DB.ViewSet() check_func = any if match_any else all + value_func = get_value_func() for sheet in sheets: revs = sheet.GetAllRevisionIds() - if HOST_APP.is_newer_than(2023): - sheet_revids = [x.Value for x in revs] - if check_func([x.Id.Value in sheet_revids - for x in revisions]): - myviewset.Insert(sheet) - else: - sheet_revids = [x.IntegerValue for x in revs] - if check_func([x.Id.IntegerValue in sheet_revids - for x in revisions]): + sheet_revids = [value_func(x) for x in revs] + if check_func([value_func(x.Id) in sheet_revids for x in revisions]): myviewset.Insert(sheet) # needs transaction # delete existing sheet set if any @@ -409,6 +404,7 @@ def create_param_value_filter(filter_name, DB.LogicalOrFilter if match_any else DB.LogicalAndFilter # create the rule set + value_func = get_value_func() for pvalue in param_values: # grab the evaluator param_eval = PARAM_VALUE_EVALUATORS.get(evaluator, None) @@ -441,11 +437,7 @@ def create_param_value_filter(filter_name, str(pvalue), False) elif isinstance(pvalue, DB.ElementId): - if HOST_APP.is_newer_than(2023): - p_id = str(pvalue.Value) - else: - p_id = str(pvalue.IntegerValue) - + p_id = str(value_func(pvalue)) if HOST_APP.is_newer_than(2022): rule = DB.FilterStringRule(param_prov, num_eval(), From ae6773f7d80b8c6357421e575d162a01cc2fb04a Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:45:44 +0200 Subject: [PATCH 15/64] updated with compat func --- pyrevitlib/pyrevit/revit/db/query.py | 123 +++++++++------------------ 1 file changed, 42 insertions(+), 81 deletions(-) diff --git a/pyrevitlib/pyrevit/revit/db/query.py b/pyrevitlib/pyrevit/revit/db/query.py index 5c62b8b15..13a5c52b0 100644 --- a/pyrevitlib/pyrevit/revit/db/query.py +++ b/pyrevitlib/pyrevit/revit/db/query.py @@ -9,7 +9,7 @@ from pyrevit import api from pyrevit import framework from pyrevit import compat -from pyrevit.compat import PY3, safe_strtype +from pyrevit.compat import PY3, safe_strtype, get_value_func from pyrevit import DB from pyrevit.revit import db from pyrevit.revit import features @@ -760,16 +760,11 @@ def get_schedule_categories(doc=None): doc = doc or DOCS.doc all_cats = get_doc_categories(doc) cats = [] - if HOST_APP.is_newer_than(2023): - for cat_id in DB.ViewSchedule.GetValidCategoriesForSchedule(): - for cat in all_cats: - if cat.Id.Value == cat_id.Value: - cats.append(cat) - else: - for cat_id in DB.ViewSchedule.GetValidCategoriesForSchedule(): - for cat in all_cats: - if cat.Id.IntegerValue == cat_id.IntegerValue: - cats.append(cat) + value_func = get_value_func() + for cat_id in DB.ViewSchedule.GetValidCategoriesForSchedule(): + for cat in all_cats: + if value_func(cat.Id) == value_func(cat_id): + cats.append(cat) return cats @@ -777,16 +772,11 @@ def get_key_schedule_categories(doc=None): doc = doc or DOCS.doc all_cats = get_doc_categories(doc) cats = [] - if HOST_APP.is_newer_than(2023): - for cat_id in DB.ViewSchedule.GetValidCategoriesForKeySchedule(): - for cat in all_cats: - if cat.Id.Value == cat_id.Value: - cats.append(cat) - else: - for cat_id in DB.ViewSchedule.GetValidCategoriesForKeySchedule(): - for cat in all_cats: - if cat.Id.IntegerValue == cat_id.IntegerValue: - cats.append(cat) + value_func = get_value_func() + for cat_id in DB.ViewSchedule.GetValidCategoriesForKeySchedule(): + for cat in all_cats: + if value_func(cat.Id) == value_func(cat_id): + cats.append(cat) return cats @@ -794,16 +784,11 @@ def get_takeoff_categories(doc=None): doc = doc or DOCS.doc all_cats = get_doc_categories(doc) cats = [] - if HOST_APP.is_newer_than(2023): - for cat_id in DB.ViewSchedule.GetValidCategoriesForMaterialTakeoff(): - for cat in all_cats: - if cat.Id.Value == cat_id.Value: - cats.append(cat) - else: - for cat_id in DB.ViewSchedule.GetValidCategoriesForMaterialTakeoff(): - for cat in all_cats: - if cat.Id.IntegerValue == cat_id.IntegerValue: - cats.append(cat) + value_func = get_value_func() + for cat_id in DB.ViewSchedule.GetValidCategoriesForMaterialTakeoff(): + for cat in all_cats: + if value_func(cat.Id) == value_func(cat_id): + cats.append(cat) return cats @@ -815,14 +800,10 @@ def get_category(cat_name_or_builtin, doc=None): if cat.Name == cat_name_or_builtin: return cat elif isinstance(cat_name_or_builtin, DB.BuiltInCategory): - if HOST_APP.is_newer_than(2023): - for cat in all_cats: - if cat.Id.Value == int(cat_name_or_builtin): - return cat - else: - for cat in all_cats: - if cat.Id.IntegerValue == int(cat_name_or_builtin): - return cat + value_func = get_value_func() + for cat in all_cats: + if value_func(cat.Id) == int(cat_name_or_builtin): + return cat elif isinstance(cat_name_or_builtin, DB.Category): return cat_name_or_builtin @@ -830,20 +811,13 @@ def get_category(cat_name_or_builtin, doc=None): def get_builtincategory(cat_name_or_id, doc=None): doc = doc or DOCS.doc cat_id = None - if HOST_APP.is_newer_than(2023): - if isinstance(cat_name_or_id, str): - cat = get_category(cat_name_or_id) - if cat: - cat_id = cat.Id.Value - elif isinstance(cat_name_or_id, DB.ElementId): - cat_id = cat_name_or_id.Value - else: - if isinstance(cat_name_or_id, str): - cat = get_category(cat_name_or_id) - if cat: - cat_id = cat.Id.IntegerValue - elif isinstance(cat_name_or_id, DB.ElementId): - cat_id = cat_name_or_id.IntegerValue + value_func = get_value_func() + if isinstance(cat_name_or_id, str): + cat = get_category(cat_name_or_id) + if cat: + cat_id = value_func(cat.Id) + elif isinstance(cat_name_or_id, DB.ElementId): + cat_id = value_func(cat_name_or_id) if cat_id: for bicat in DB.BuiltInCategory.GetValues(DB.BuiltInCategory): if int(bicat) == cat_id: @@ -854,27 +828,16 @@ def get_subcategories(doc=None, purgable=False, filterfunc=None): doc = doc or DOCS.doc # collect custom categories subcategories = [] - if HOST_APP.is_newer_than(2023): - for cat in doc.Settings.Categories: - for subcat in cat.SubCategories: - if purgable: - if subcat.Id.Value > 1: - subcategories.append(subcat) - else: - subcategories.append(subcat) - if filterfunc: - subcategories = filter(filterfunc, subcategories) - else: - for cat in doc.Settings.Categories: - for subcat in cat.SubCategories: - if purgable: - if subcat.Id.IntegerValue > 1: - subcategories.append(subcat) - else: + value_func = get_value_func() + for cat in doc.Settings.Categories: + for subcat in cat.SubCategories: + if purgable: + if value_func(subcat.Id) > 1: subcategories.append(subcat) - if filterfunc: - subcategories = filter(filterfunc, subcategories) - + else: + subcategories.append(subcat) + if filterfunc: + subcategories = filter(filterfunc, subcategories) return subcategories @@ -890,14 +853,14 @@ def get_subcategory(cat_name_or_builtin, subcategory_name, doc=None): def get_builtinparameter(element, param_name, doc=None): doc = doc or DOCS.doc eparam = element.LookupParameter(param_name) + value_func = get_value_func() if eparam: - if HOST_APP.is_newer_than(2023): - eparam_def_id = eparam.Definition.Id.Value - else: - eparam_def_id = eparam.Definition.Id.IntegerValue + eparam_def_id = value_func(eparam.Definition.Id) for biparam in DB.BuiltInParameter.GetValues(DB.BuiltInParameter): if int(biparam) == eparam_def_id: return biparam + else: + raise PyRevitException('Parameter not found: {}'.format(param_name)) def get_view_cutplane_offset(view): @@ -1622,6 +1585,7 @@ def get_geometry(element, include_invisible=False, compute_references=False): geom_opts.IncludeNonVisibleObjects = include_invisible geom_opts.ComputeReferences = compute_references geom_objs = [] + value_func = get_value_func() try: for gobj in element.Geometry[geom_opts]: if isinstance(gobj, DB.GeometryInstance): @@ -1631,8 +1595,5 @@ def get_geometry(element, include_invisible=False, compute_references=False): geom_objs.append(gobj) return geom_objs except TypeError: - if HOST_APP.is_newer_than(2023): - mlogger.debug("element %s has no geometry", element.Id.Value) - else: - mlogger.debug("element %s has no geometry", element.Id.IntegerValue) + mlogger.debug("element %s has no geometry", value_func(element.Id)) return From b7f0f2d8108f8402683d518ab7f05a09ddb42a31 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:48:49 +0200 Subject: [PATCH 16/64] updated with compat func --- pyrevitlib/pyrevit/revit/db/update.py | 31 ++++++++++----------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/pyrevitlib/pyrevit/revit/db/update.py b/pyrevitlib/pyrevit/revit/db/update.py index 60d27d3ed..9f32f1085 100644 --- a/pyrevitlib/pyrevit/revit/db/update.py +++ b/pyrevitlib/pyrevit/revit/db/update.py @@ -5,6 +5,7 @@ from pyrevit.framework import List from pyrevit import DB from pyrevit.revit.db import query +from pyrevit.compat import get_value_func def set_name(element, new_name): @@ -20,6 +21,7 @@ def set_name(element, new_name): def update_sheet_revisions(revisions, sheets=None, state=True, doc=None): doc = doc or DOCS.doc + value_func = get_value_func() # make sure revisions is a list if not isinstance(revisions, list): revisions = [revisions] @@ -27,26 +29,15 @@ def update_sheet_revisions(revisions, sheets=None, state=True, doc=None): if revisions: # get sheets if not available for sheet in sheets or query.get_sheets(doc=doc): - if HOST_APP.is_newer_than(2023): - addrevs = set([x.Value - for x in sheet.GetAdditionalRevisionIds()]) - for rev in revisions: - # skip issued revisions - if not rev.Issued: - if state: - addrevs.add(rev.Id.Value) - elif rev.Id.Value in addrevs: - addrevs.remove(rev.Id.Value) - else: - addrevs = set([x.IntegerValue - for x in sheet.GetAdditionalRevisionIds()]) - for rev in revisions: - # skip issued revisions - if not rev.Issued: - if state: - addrevs.add(rev.Id.IntegerValue) - elif rev.Id.IntegerValue in addrevs: - addrevs.remove(rev.Id.IntegerValue) + addrevs = set([value_func(x) + for x in sheet.GetAdditionalRevisionIds()]) + for rev in revisions: + # skip issued revisions + if not rev.Issued: + if state: + addrevs.add(value_func(rev.Id)) + elif value_func(rev.Id) in addrevs: + addrevs.remove(value_func(rev.Id)) rev_elids = [DB.ElementId(x) for x in addrevs] sheet.SetAdditionalRevisionIds(List[DB.ElementId](rev_elids)) updated_sheets.append(sheet) From 145cc2fa346ee955e68a372de024ef9dc038f3b8 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:51:48 +0200 Subject: [PATCH 17/64] updated with compat func --- pyrevitlib/rpw/db/builtins.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pyrevitlib/rpw/db/builtins.py b/pyrevitlib/rpw/db/builtins.py index 954107965..f473e80a5 100644 --- a/pyrevitlib/rpw/db/builtins.py +++ b/pyrevitlib/rpw/db/builtins.py @@ -18,6 +18,7 @@ from rpw.base import BaseObject, BaseObjectWrapper from rpw.utils.dotnet import Enum from rpw.exceptions import RpwCoerceError +from pyrevit.compat import get_value_func class _BiParameter(BaseObjectWrapper): @@ -155,20 +156,17 @@ def from_category_id(self, category_id): Returns: ``DB.BuiltInCategory`` member """ - if HOST_APP.is_newer_than(2023): - bic = Enum.ToObject(DB.BuiltInCategory, category_id.Value) - bic_value = DB.ElementId(bic).Value + value_func = get_value_func() + bic = Enum.ToObject(DB.BuiltInCategory, value_func(category_id)) + bic_value = value_func(DB.ElementId(bic)) + if bic_value < -1: + return bic else: - bic = Enum.ToObject(DB.BuiltInCategory, category_id.IntegerValue) - bic_value = DB.ElementId(bic).IntegerValue - if bic_value < -1: - return bic - else: - # If you pass a regular element to category_id, it converts it to BIC. - # It should fail, because result is not a valid Category Enum - raise RpwCoerceError('category_id: {}'.format(category_id), - DB.BuiltInCategory) - # Similar to: Category.GetCategory(doc, category.Id).Name + # If you pass a regular element to category_id, it converts it to BIC. + # It should fail, because result is not a valid Category Enum + raise RpwCoerceError('category_id: {}'.format(category_id), + DB.BuiltInCategory) + # Similar to: Category.GetCategory(doc, category.Id).Name def __repr__(self): return super(_BiCategory, self).__repr__(to_string='Autodesk.Revit.DB.BuiltInCategory') From c5c5b52dd14cdc2459d97ab96a7e795b3b7f4ccf Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:53:08 +0200 Subject: [PATCH 18/64] updated with compat func --- pyrevitlib/rpw/db/family.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pyrevitlib/rpw/db/family.py b/pyrevitlib/rpw/db/family.py index ca4768cfc..5e84e29df 100644 --- a/pyrevitlib/rpw/db/family.py +++ b/pyrevitlib/rpw/db/family.py @@ -29,6 +29,7 @@ from rpw.utils.mixins import CategoryMixin from rpw.db.builtins import BicEnum from rpw.db.category import Category +from pyrevit.compat import get_value_func class FamilyInstance(Element, CategoryMixin): @@ -93,10 +94,8 @@ def in_assembly(self): Returns: (bool): True if element is inside an AssemblyInstance """ - if HOST_APP.is_newer_than(2023): - assembly_id_value = self._revit_object.AssemblyInstanceId.Value - else: - assembly_id_value = self._revit_object.AssemblyInstanceId.IntegerValue + value_func = get_value_func() + assembly_id_value = value_func(self._revit_object.AssemblyInstanceId) if assembly_id_value == -1: return False else: From f937f92da135cfa45fd1bf470a278302731377e0 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:54:44 +0200 Subject: [PATCH 19/64] update with compat func --- pyrevitlib/rpw/db/parameter.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pyrevitlib/rpw/db/parameter.py b/pyrevitlib/rpw/db/parameter.py index 1502186f5..ce5a7eb71 100644 --- a/pyrevitlib/rpw/db/parameter.py +++ b/pyrevitlib/rpw/db/parameter.py @@ -13,6 +13,7 @@ from rpw.exceptions import RpwException, RpwWrongStorageType from rpw.exceptions import RpwParameterNotFound, RpwTypeError from rpw.utils.logger import logger +from pyrevit.compat import get_value_func class ParameterSet(BaseObjectWrapper): @@ -299,10 +300,8 @@ def to_dict(self): if not isinstance(self.value, DB.ElementId): value = self.value else: - if HOST_APP.is_newer_than(2023): - value = self.value.Value - else: - value = self.value.IntegerValue + value_func = get_value_func() + value = value_func(self.value) return { 'name': self.name, 'type': self.type.__name__, From 2f4a794508d58f22b2035e719a4e729744b2b9d3 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 14:57:24 +0200 Subject: [PATCH 20/64] update with compat func --- .../pyRevitTags.extension/lib/pkgmgr.py | 40 ++++++------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/extensions/pyRevitTags.extension/lib/pkgmgr.py b/extensions/pyRevitTags.extension/lib/pkgmgr.py index ab933985e..05910db0e 100644 --- a/extensions/pyRevitTags.extension/lib/pkgmgr.py +++ b/extensions/pyRevitTags.extension/lib/pkgmgr.py @@ -152,6 +152,7 @@ def get_commit_points(): commit_points = [] # grab defined packages dockpkgs = [] + value_func = get_value_func() docpkg_finder = \ re.compile(r'docpkg(\d+)\s*[-_]*?\s*(.+)', flags=re.IGNORECASE) for project_param in revit.query.get_project_parameters(doc=revit.doc): @@ -166,7 +167,6 @@ def get_commit_points(): elif 'docpkg' in project_param.name.lower(): mlogger.warning('Package parameter "%s" is not formatted ' 'correctly and is skipped.', project_param.name) - last_docpkg_idx = -1 for idx, docpkg in enumerate(sorted(dockpkgs, key=lambda x: x.pkg_idx)): last_docpkg_idx = idx @@ -182,32 +182,18 @@ def get_commit_points(): none_numtype = coreutils.get_enum_none(DB.RevisionNumberType) docrevs = sorted(revit.query.get_revisions(), key=lambda x: x.SequenceNumber) - if HOST_APP.is_newer_than(2023): - commit_points.extend([ - CommitPoint(cptype=CommitPointTypes.Revision, - target=x.Id.Value, - idx=last_docpkg_idx + i + 1, - name='R{}'.format(x.SequenceNumber), - desc='{}{} (Sequence #{})'.format( - '{} - '.format(revit.query.get_rev_number(x)) - if revit.ensure.revision_has_numbertype(x) else '', - x.Description, - x.SequenceNumber)) - for i, x in enumerate(docrevs) - ]) - else: - commit_points.extend([ - CommitPoint(cptype=CommitPointTypes.Revision, - target=x.Id.IntegerValue, - idx=last_docpkg_idx + i + 1, - name='R{}'.format(x.SequenceNumber), - desc='{}{} (Sequence #{})'.format( - '{} - '.format(revit.query.get_rev_number(x)) - if revit.ensure.revision_has_numbertype(x) else '', - x.Description, - x.SequenceNumber)) - for i, x in enumerate(docrevs) - ]) + commit_points.extend([ + CommitPoint(cptype=CommitPointTypes.Revision, + target=value_func(x.Id), + idx=last_docpkg_idx + i + 1, + name='R{}'.format(x.SequenceNumber), + desc='{}{} (Sequence #{})'.format( + '{} - '.format(revit.query.get_rev_number(x)) + if revit.ensure.revision_has_numbertype(x) else '', + x.Description, + x.SequenceNumber)) + for i, x in enumerate(docrevs) + ]) sorted_cpoints = sorted(commit_points, key=lambda x: x.idx) mlogger.debug(sorted_cpoints) return sorted_cpoints From aad05475d2ed40d786387e9fbec41f7395ad578a Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 16:55:49 +0200 Subject: [PATCH 21/64] Update family.py --- pyrevitlib/rpw/db/family.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pyrevitlib/rpw/db/family.py b/pyrevitlib/rpw/db/family.py index 5e84e29df..af757310a 100644 --- a/pyrevitlib/rpw/db/family.py +++ b/pyrevitlib/rpw/db/family.py @@ -95,11 +95,7 @@ def in_assembly(self): (bool): True if element is inside an AssemblyInstance """ value_func = get_value_func() - assembly_id_value = value_func(self._revit_object.AssemblyInstanceId) - if assembly_id_value == -1: - return False - else: - return True + return value_func(self._revit_object.AssemblyInstanceId) != -1 @property def get_assembly(self, wrapped=True): From e134dc55d577f85f9e36d648d382753f8fbee695 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 18:33:53 +0200 Subject: [PATCH 22/64] editing comparison of Ids in query module --- pyrevitlib/pyrevit/compat.py | 16 ++++++++-------- pyrevitlib/pyrevit/revit/db/query.py | 24 +++++++++--------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/pyrevitlib/pyrevit/compat.py b/pyrevitlib/pyrevit/compat.py index 43950e6d7..50f79d3a4 100644 --- a/pyrevitlib/pyrevit/compat.py +++ b/pyrevitlib/pyrevit/compat.py @@ -59,17 +59,17 @@ def is_netcore(): def get_value_func(): - """Determines and returns the appropriate value extraction function based on the host application's version. + """Determines and returns the appropriate value extraction function based on the host application's version. Follows API changes in Revit 2024. Returns: function: A function that takes an item as an argument and returns its value. - If the host application version is newer than 2023, it returns the `get_value_2024` function, + If the host application version is newer than 2023, it returns the `get_value_post2024` function, which extracts the `Value` attribute from the item. - Otherwise, it returns the `get_value_2003` function, which extracts the `IntegerValue` attribute from the item. + Otherwise, it returns the `get_value_pre2024` function, which extracts the `IntegerValue` attribute from the item. Functions: - get_value_2024(item): Extracts the `Value` attribute from the given item. - get_value_2003(item): Extracts the `IntegerValue` attribute from the given item. + get_value_post2024(item): Extracts the `Value` attribute from the given item. + get_value_pre2024(item): Extracts the `IntegerValue` attribute from the given item. Examples: ```python @@ -78,13 +78,13 @@ def get_value_func(): add_sheet_revids = {value_func(x) x in self.revit_sheet.GetAdditionalRevisionIds()} ``` """ - def get_value_2024(item): + def get_value_post2024(item): return item.Value - def get_value_2003(item): + def get_value_pre2024(item): return item.IntegerValue - return get_value_2024 if __revit__.Application.is_newer_than(2023) else get_value_2003 + return get_value_post2024 if __revit__.Application.is_newer_than(2023) else get_value_pre2024 def urlopen(url): diff --git a/pyrevitlib/pyrevit/revit/db/query.py b/pyrevitlib/pyrevit/revit/db/query.py index 13a5c52b0..cfa81af3a 100644 --- a/pyrevitlib/pyrevit/revit/db/query.py +++ b/pyrevitlib/pyrevit/revit/db/query.py @@ -760,10 +760,9 @@ def get_schedule_categories(doc=None): doc = doc or DOCS.doc all_cats = get_doc_categories(doc) cats = [] - value_func = get_value_func() for cat_id in DB.ViewSchedule.GetValidCategoriesForSchedule(): for cat in all_cats: - if value_func(cat.Id) == value_func(cat_id): + if cat.Id == cat_id: cats.append(cat) return cats @@ -772,10 +771,9 @@ def get_key_schedule_categories(doc=None): doc = doc or DOCS.doc all_cats = get_doc_categories(doc) cats = [] - value_func = get_value_func() for cat_id in DB.ViewSchedule.GetValidCategoriesForKeySchedule(): for cat in all_cats: - if value_func(cat.Id) == value_func(cat_id): + if cat.Id == cat_id: cats.append(cat) return cats @@ -784,10 +782,9 @@ def get_takeoff_categories(doc=None): doc = doc or DOCS.doc all_cats = get_doc_categories(doc) cats = [] - value_func = get_value_func() for cat_id in DB.ViewSchedule.GetValidCategoriesForMaterialTakeoff(): for cat in all_cats: - if value_func(cat.Id) == value_func(cat_id): + if cat.Id == cat_id: cats.append(cat) return cats @@ -800,9 +797,8 @@ def get_category(cat_name_or_builtin, doc=None): if cat.Name == cat_name_or_builtin: return cat elif isinstance(cat_name_or_builtin, DB.BuiltInCategory): - value_func = get_value_func() for cat in all_cats: - if value_func(cat.Id) == int(cat_name_or_builtin): + if cat.Id == cat_name_or_builtin: return cat elif isinstance(cat_name_or_builtin, DB.Category): return cat_name_or_builtin @@ -811,16 +807,15 @@ def get_category(cat_name_or_builtin, doc=None): def get_builtincategory(cat_name_or_id, doc=None): doc = doc or DOCS.doc cat_id = None - value_func = get_value_func() if isinstance(cat_name_or_id, str): cat = get_category(cat_name_or_id) if cat: - cat_id = value_func(cat.Id) + cat_id = cat.Id elif isinstance(cat_name_or_id, DB.ElementId): - cat_id = value_func(cat_name_or_id) + cat_id = cat_name_or_id if cat_id: for bicat in DB.BuiltInCategory.GetValues(DB.BuiltInCategory): - if int(bicat) == cat_id: + if bicat == cat_id: return bicat @@ -853,11 +848,10 @@ def get_subcategory(cat_name_or_builtin, subcategory_name, doc=None): def get_builtinparameter(element, param_name, doc=None): doc = doc or DOCS.doc eparam = element.LookupParameter(param_name) - value_func = get_value_func() if eparam: - eparam_def_id = value_func(eparam.Definition.Id) + eparam_def_id = eparam.Definition.Id for biparam in DB.BuiltInParameter.GetValues(DB.BuiltInParameter): - if int(biparam) == eparam_def_id: + if biparam == eparam_def_id: return biparam else: raise PyRevitException('Parameter not found: {}'.format(param_name)) From ee692c12734583b073a93cd14dd1974c4bb1c1a7 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 18:42:33 +0200 Subject: [PATCH 23/64] IntegerValue API Change handling --- extensions/pyRevitDevTools.extension/startup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitDevTools.extension/startup.py b/extensions/pyRevitDevTools.extension/startup.py index a83379a9d..5aa9b516a 100644 --- a/extensions/pyRevitDevTools.extension/startup.py +++ b/extensions/pyRevitDevTools.extension/startup.py @@ -23,6 +23,7 @@ from pyrevit import revit, DB, UI from pyrevit import forms from pyrevit import routes +from pyrevit.compat import get_value_func # add your module paths to the sys.path here @@ -76,7 +77,8 @@ def get_doors(uiapp): doors = revit.query.get_elements_by_categories( [DB.BuiltInCategory.OST_Doors] ) - doors_data = [x.Id.IntegerValue for x in doors] + value_func = get_value_func() + doors_data = [value_func(x.Id) for x in doors] return routes.make_response( data=doors_data, headers={"pyRevit": "v4.6.7"} From c3f5f66b0d6f522a05774a6633c584f04a943188 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 18:44:16 +0200 Subject: [PATCH 24/64] IntegerValue API Change handling --- pyrevitlib/pyrevit/revit/db/failure.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrevitlib/pyrevit/revit/db/failure.py b/pyrevitlib/pyrevit/revit/db/failure.py index 34c541349..10b512f58 100644 --- a/pyrevitlib/pyrevit/revit/db/failure.py +++ b/pyrevitlib/pyrevit/revit/db/failure.py @@ -3,6 +3,7 @@ from pyrevit import framework from pyrevit import coreutils from pyrevit.coreutils.logger import get_logger +from pyrevit.compat import get_value_func #pylint: disable=W0703,C0302,C0103 @@ -86,6 +87,7 @@ def PreprocessFailures(self, failuresAccessor): # go through failures and attempt resolution action_taken = False + value_func = get_value_func() for failure in failures: failure_id = failure.GetFailureDefinitionId() @@ -99,7 +101,7 @@ def PreprocessFailures(self, failuresAccessor): mlogger.debug('\tseverity: %s', failure_severity) mlogger.debug('\tdescription: %s', failure_desc) mlogger.debug('\telements: %s', - [x.IntegerValue + [value_func(x) for x in failure.GetFailingElementIds()]) mlogger.debug('\thas resolutions: %s', failure_has_res) From df924c2bed4f27158ffca4fbb959aec7f83ce4bb Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 18:45:55 +0200 Subject: [PATCH 25/64] IntegerValue API Change handling --- pyrevitlib/pyrevit/revit/db/pickling.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyrevitlib/pyrevit/revit/db/pickling.py b/pyrevitlib/pyrevit/revit/db/pickling.py index e489180e0..85f719f6e 100644 --- a/pyrevitlib/pyrevit/revit/db/pickling.py +++ b/pyrevitlib/pyrevit/revit/db/pickling.py @@ -5,6 +5,7 @@ from pyrevit.compat import Iterable from pyrevit import coreutils from pyrevit.coreutils import logger +from pyrevit.compat import get_value_func __all__ = ('serialize', 'deserialize') @@ -38,9 +39,9 @@ class NoneSerializer(Serializable): class ElementId(Serializable): api_types = DB.ElementId - + value_func = get_value_func() def __init__(self, element_id): - self.integer_value = element_id.IntegerValue + self.integer_value = value_func(element_id) def deserialize(self): return DB.ElementId(self.integer_value) From 8e35070450dfda51c58d06fc57527cd406484ec2 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 18:48:47 +0200 Subject: [PATCH 26/64] IntegerValue API Change handling --- pyrevitlib/pyrevit/revit/db/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrevitlib/pyrevit/revit/db/__init__.py b/pyrevitlib/pyrevit/revit/db/__init__.py index 174687e11..0f82096b8 100644 --- a/pyrevitlib/pyrevit/revit/db/__init__.py +++ b/pyrevitlib/pyrevit/revit/db/__init__.py @@ -6,6 +6,7 @@ from pyrevit import coreutils from pyrevit import DB from Autodesk.Revit.DB import Element #pylint: disable=E0401 +from pyrevit.compat import get_value_func #pylint: disable=W0703,C0302,C0103 @@ -22,7 +23,8 @@ def __init__(self, obj=None): def __repr__(self, data=None): pdata = {} if hasattr(self._wrapped, 'Id'): - pdata['id'] = self._wrapped.Id.IntegerValue + value_func = get_value_func() + pdata['id'] = value_func(self._wrapped.Id) if data: pdata.update(data) From df28f84a6bd149b67d30aee8df1070f38171381c Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 18:51:23 +0200 Subject: [PATCH 27/64] IntegerValue API Change handling --- .../Selection.panel/mema.stack/MWrite.pushbutton/script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/mema.stack/MWrite.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/mema.stack/MWrite.pushbutton/script.py index f2fcafc44..059b26d10 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/mema.stack/MWrite.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/mema.stack/MWrite.pushbutton/script.py @@ -2,12 +2,14 @@ from pyrevit import script from pyrevit import revit +from pyrevit.compat import get_value_func datafile = script.get_document_data_file("SelList", "pym") selection = revit.get_selection() -selected_ids = {str(elid.IntegerValue) for elid in selection.element_ids} +value_func = get_value_func() +selected_ids = {str(value_func(elid)) for elid in selection.element_ids} f = open(datafile, 'wb') pickle.dump(selected_ids, f) From c121e321f4840e4409d0d44ee623e6718b0d8a40 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 18:54:39 +0200 Subject: [PATCH 28/64] IntegerValue API Change handling --- .../pyRevitTools.extension/checks/modelchecker_check.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extensions/pyRevitTools.extension/checks/modelchecker_check.py b/extensions/pyRevitTools.extension/checks/modelchecker_check.py index 10156f6a2..849cad559 100644 --- a/extensions/pyRevitTools.extension/checks/modelchecker_check.py +++ b/extensions/pyRevitTools.extension/checks/modelchecker_check.py @@ -4,6 +4,7 @@ from pyrevit import coreutils from pyrevit import revit, DB +from pyrevit.compat import get_value_func from pyrevit.preflight import PreflightTestCase @@ -257,6 +258,7 @@ def checkModel(doc, output): projectNumber = project_info_collector.Number projectName = project_info_collector.Name projectClient = project_info_collector.ClientName + value_func = get_value_func() if len(name) == 0: # name = "Not saved file" printedName = "Not saved file" @@ -434,7 +436,7 @@ def checkModel(doc, output): # to support french files or schedName[:28] != ""): if schedName not in schedulesOnSheet: - if schedule.OwnerViewId.IntegerValue != -1: + if value_func(schedule.OwnerViewId) != -1: # print schedName # print schedule.Id schedulesOnSheet.append(schedName) @@ -446,7 +448,7 @@ def checkModel(doc, output): # to support french files or schedName[:28] != ""): if schedName not in schedulesOnSheet: - if schedule.OwnerViewId.IntegerValue != -1: + if value_func(schedule.OwnerViewId) != -1: # print schedName # print schedule.Id schedulesOnSheet.append(schedName) @@ -926,7 +928,7 @@ def DocPhases(doc, links = []): for element in elements: try: category = element.Category.Name - categoryId = element.Category.Id.IntegerValue + categoryId = value_func(element.Category.Id) # filtering out DWGs and DXFs, categories from banlist # filtering out categories in catBanlist # DB.BuiltInCategory Ids are negative integers From d2a5b2187957b7868e01841ec213782ef24b4f09 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 18:57:54 +0200 Subject: [PATCH 29/64] IntegerValue API Change handling --- .../Compare Detail Views.deprecate/diffutils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/Compare Detail Views.deprecate/diffutils.py b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/Compare Detail Views.deprecate/diffutils.py index cb6ae4d31..f97b35456 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/Compare Detail Views.deprecate/diffutils.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/Compare Detail Views.deprecate/diffutils.py @@ -3,6 +3,7 @@ from pyrevit.coreutils.logger import get_logger from pyrevit.coreutils import reverse_dict, get_str_hash from pyrevit import DB +from pyrevit.compat import get_value_func logger = get_logger(__name__) @@ -78,7 +79,8 @@ def attribute_hash(el, attribute): def element_hash_dict(element_list, include_type=False, diff_results=None): - return {el.Id.IntegerValue: element_hash(el, include_type, diff_results) + value_func = get_value_func() + return {value_func(el.Id): element_hash(el, include_type, diff_results) for el in element_list} From c40b09d378f393f4e4e3238ab711908ddbf0b33a Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 18:59:57 +0200 Subject: [PATCH 30/64] IntegerValue API Change handling --- .../Selection.panel/mema.stack/MAppend.pushbutton/script.py | 4 +++- .../memo.stack/Memory.pulldown/MDeduct.pushbutton/script.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/mema.stack/MAppend.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/mema.stack/MAppend.pushbutton/script.py index 154d81e26..8b111ac61 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/mema.stack/MAppend.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/mema.stack/MAppend.pushbutton/script.py @@ -2,13 +2,15 @@ from pyrevit import script from pyrevit import revit +from pyrevit.compat import get_value_func datafile = script.get_document_data_file("SelList", "pym") selection = revit.get_selection() -selected_ids = {str(elid.IntegerValue) for elid in selection.element_ids} +value_func = get_value_func() +selected_ids = {str(value_func(elid)) for elid in selection.element_ids} try: f = open(datafile, 'rb') diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/memo.stack/Memory.pulldown/MDeduct.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/memo.stack/Memory.pulldown/MDeduct.pushbutton/script.py index a3ced2b13..b224241a0 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/memo.stack/Memory.pulldown/MDeduct.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/memo.stack/Memory.pulldown/MDeduct.pushbutton/script.py @@ -4,12 +4,14 @@ from pyrevit import revit from pyrevit import script +from pyrevit.compat import get_value_func datafile = script.get_document_data_file("SelList", "pym") selection = revit.get_selection() -selected_ids = {str(elid.IntegerValue) for elid in selection.element_ids} +value_func = get_value_func() +selected_ids = {str(value_func(elid)) for elid in selection.element_ids} try: f = open(datafile, 'rb') From ac6685a219e19f5b8717db5fe573d201bdb4a60e Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:07:10 +0200 Subject: [PATCH 31/64] IntegerValue API Change handling --- .../wipeactions.py | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Model Components.pushbutton/wipeactions.py b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Model Components.pushbutton/wipeactions.py index ffeb6a322..cc0f263f6 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Model Components.pushbutton/wipeactions.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Model Components.pushbutton/wipeactions.py @@ -6,6 +6,7 @@ from pyrevit import coreutils from pyrevit import revit, DB, UI, HOST_APP from pyrevit import script +from pyrevit.compat import get_value_func logger = coreutils.logger.get_logger(__name__) @@ -194,11 +195,13 @@ def remove_all_sheets(): .WhereElementIsNotElementType()\ .ToElements() open_UIViews = revit.uidoc.GetOpenUIViews() - open_views = [ov.ViewId.IntegerValue for ov in open_UIViews] + value_func = get_value_func() + open_views = [value_func(ov.ViewId) for ov in open_UIViews] def confirm_removal(sht): + value_func = get_value_func() return isinstance(sht, DB.ViewSheet) \ - and sht.Id.IntegerValue not in open_views + and value_func(sht.Id) not in open_views print_header('REMOVING SHEETS') remove_action('Remove All Sheets', @@ -428,9 +431,9 @@ def _purge_all_views(viewclass_to_purge, viewtype_to_purge, .WhereElementIsNotElementType() .ToElements() ) - + value_func = get_value_func() open_uiviews = revit.uidoc.GetOpenUIViews() - open_views = [x.ViewId.IntegerValue for x in open_uiviews] + open_views = [value_func(x.ViewId) for x in open_uiviews] view_refnames = get_referenced_view_names() sheeted_view_ids = get_sheeted_view_ids() @@ -457,6 +460,7 @@ def is_sheeted(view_id): def confirm_removal(view): if isinstance(view, viewclass_to_purge): + value_func = get_value_func() if viewtype_to_purge and view.ViewType != viewtype_to_purge: return False elif view.ViewType in READONLY_VIEWS: @@ -468,7 +472,7 @@ def confirm_removal(view): return False elif '<' in revit.query.get_name(view): return False - elif view.Id.IntegerValue in open_views: + elif value_func(view.Id) in open_views: return False elif keep_referenced and is_referenced(view): return False @@ -766,17 +770,19 @@ def remove_all_schedules(): .WhereElementIsNotElementType() .ToElements()) open_UIViews = revit.uidoc.GetOpenUIViews() - open_views = [ov.ViewId.IntegerValue for ov in open_UIViews] + value_func = get_value_func() + open_views = [value_func(ov.ViewId) for ov in open_UIViews] def confirm_removal(v): if isinstance(v, DB.ViewSchedule): + value_func = get_value_func() if v.ViewType in READONLY_VIEWS: return False elif v.IsTemplate: return False elif '<' in revit.query.get_name(v): return False - elif v.Id.IntegerValue in open_views: + elif value_func(v.Id) in open_views: return False elif v.Definition.CategoryId == \ DB.Category.GetCategory(revit.doc, @@ -804,17 +810,19 @@ def remove_all_legends(): .ToElements()) open_UIViews = revit.uidoc.GetOpenUIViews() - open_views = [ov.ViewId.IntegerValue for ov in open_UIViews] + value_func = get_value_func() + open_views = [value_func(ov.ViewId) for ov in open_UIViews] def confirm_removal(v): if isinstance(v, DB.View) and v.ViewType == DB.ViewType.Legend: + value_func = get_value_func() if v.ViewType in READONLY_VIEWS: return False elif v.IsTemplate: return False elif '<' in revit.query.get_name(v): return False - elif v.Id.IntegerValue in open_views: + elif value_func(v.Id) in open_views: return False else: return True From c1e432e2ab6fcaf74c618d4017930f2de361adb2 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:08:46 +0200 Subject: [PATCH 32/64] IntegerValue API Change handling --- .../Wipe All Project Parameters.pushbutton/script.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe All Project Parameters.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe All Project Parameters.pushbutton/script.py index c71e036f3..a5bb89793 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe All Project Parameters.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe All Project Parameters.pushbutton/script.py @@ -2,6 +2,7 @@ from pyrevit import HOST_APP from pyrevit import DB, revit +from pyrevit.compat import get_value_func doc = revit.doc @@ -42,6 +43,7 @@ for cat in b.Categories: try: + value_func = get_value_func() elements = DB.FilteredElementCollector(doc).OfCategoryId( cat.Id).WhereElementIsNotElementType() if BIND == 'Type' and p.Visible: @@ -50,13 +52,13 @@ print('Searching through {0} ElementTypes of Category {1}'.format( len(list(elements)), cat.Name)) for elType in elementTypes: - paramidlist.add(elType.LookupParameter( - p.Name).Id.IntegerValue) + paramidlist.add(value_func(elType.LookupParameter( + p.Name).Id)) elif p.Visible: print('Searching through {0} Elements of Category {1}'.format( len(list(elements)), cat.Name)) for el in elements: - paramidlist.add(el.LookupParameter(p.Name).Id.IntegerValue) + paramidlist.add(value_func(el.LookupParameter(p.Name).Id)) except Exception as e: print('---ERROR---\n', p.Name, cat.Name, cat.Id, e) continue From a0616756486039762dd650c03d27b8d74a0775d5 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:09:59 +0200 Subject: [PATCH 33/64] IntegerValue API Change handling --- .../Views.pulldown/Close Views.pushbutton/script.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Views.pulldown/Close Views.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Views.pulldown/Close Views.pushbutton/script.py index 973b7e911..39954c39f 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Views.pulldown/Close Views.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Views.pulldown/Close Views.pushbutton/script.py @@ -1,6 +1,7 @@ """Close selected views""" from pyrevit import forms from pyrevit import revit +from pyrevit.compat import get_value_func uiviews = revit.uidoc.GetOpenUIViews() @@ -14,9 +15,10 @@ ) if views_to_keep: - view_ids_to_keep = [v.Id.IntegerValue for v in views_to_keep] + value_func = get_value_func() + view_ids_to_keep = [value_func(v.Id) for v in views_to_keep] uiviews_to_close = filter( - lambda x: x.ViewId.IntegerValue not in view_ids_to_keep, + lambda x: value_func(x.ViewId) not in view_ids_to_keep, uiviews) for uiview in uiviews_to_close: From 07b06f309cfa42577e02d345e398ccc36744f114 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:12:55 +0200 Subject: [PATCH 34/64] IntegerValue API Change handling --- pyrevitlib/pyrevit/forms/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyrevitlib/pyrevit/forms/__init__.py b/pyrevitlib/pyrevit/forms/__init__.py index da6a6d5d8..609097554 100644 --- a/pyrevitlib/pyrevit/forms/__init__.py +++ b/pyrevitlib/pyrevit/forms/__init__.py @@ -21,7 +21,7 @@ from pyrevit import HOST_APP, EXEC_PARAMS, DOCS, BIN_DIR from pyrevit import PyRevitCPythonNotSupported, PyRevitException from pyrevit.compat import PY3, IRONPY340 -from pyrevit.compat import safe_strtype +from pyrevit.compat import safe_strtype, get_value_func if PY3 and not IRONPY340: raise PyRevitCPythonNotSupported('pyrevit.forms') @@ -2768,19 +2768,20 @@ def select_family_parameters(family_doc, family_params = filter(filterfunc, family_params) param_defs = [] + value_func = get_value_func() for family_param in family_params: if not include_instance and family_param.IsInstance: continue if not include_type and not family_param.IsInstance: continue - if not include_builtin and family_param.Id.IntegerValue < 0: + if not include_builtin and value_func(family_param.Id) < 0: continue if not include_labeled and family_param.Id in label_param_ids: continue param_defs.append( FamilyParamOption(family_param, - builtin=family_param.Id.IntegerValue < 0, + builtin=value_func(family_param.Id) < 0, labeled=family_param.Id in label_param_ids) ) From a86c05e5f4270d54d3ed67ece20c86c0249b7026 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:14:23 +0200 Subject: [PATCH 35/64] IntegerValue API Change handling --- .../Toggles.panel/toggles3.stack/sync.pushbutton/script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Toggles.panel/toggles3.stack/sync.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Toggles.panel/toggles3.stack/sync.pushbutton/script.py index 52276197b..1d7e24b73 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Toggles.panel/toggles3.stack/sync.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Toggles.panel/toggles3.stack/sync.pushbutton/script.py @@ -1,6 +1,7 @@ import datetime from pyrevit import DB, UI, revit, HOST_APP from pyrevit import script, forms, coreutils +from pyrevit.compat import get_value_func doc = revit.doc @@ -139,8 +140,9 @@ def sync_document(): try: set_active_view(view) except: + value_func = get_value_func() logger.warn( - "Failed to reopen view {}".format(v_id.IntegerValue)) + "Failed to reopen view {}".format(value_func(v_id))) endtime = timer.get_time() endtime_hms = str(datetime.timedelta(seconds=endtime).seconds) From 9dc80e2e96e7452b16c02bcdb8efa9007a66f6d9 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:23:27 +0200 Subject: [PATCH 36/64] IntegerValue API Change handling --- .../List Legends on Sheets.pushbutton/script.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Legends.pulldown/List Legends on Sheets.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Legends.pulldown/List Legends on Sheets.pushbutton/script.py index 3e8448d8b..154b316da 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Legends.pulldown/List Legends on Sheets.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Legends.pulldown/List Legends on Sheets.pushbutton/script.py @@ -1,10 +1,13 @@ from pyrevit import revit, DB, script, forms +from pyrevit.compat import get_value_func output = script.get_output() output.close_others() doc = revit.doc +value_func = get_value_func() + legends = [ x for x in DB.FilteredElementCollector(doc) .OfCategory(DB.BuiltInCategory.OST_Views) @@ -12,7 +15,7 @@ .ToElements() if x.ViewType == DB.ViewType.Legend] -legends_ids = [x.Id.IntegerValue for x in legends] +legends_ids = [value_func(x.Id) for x in legends] sheets = ( DB.FilteredElementCollector(doc) @@ -26,7 +29,7 @@ for sheet in sheets: vps = sheet.GetAllPlacedViews() for vp in vps: - if vp.IntegerValue in legends_ids: + if value_func(vp) in legends_ids: results.append((output.linkify(doc.GetElement(vp).Id), doc.GetElement( vp).Name, output.linkify(sheet.Id), sheet.SheetNumber, sheet.Name)) From 13032f32635aaf3576f86d93201e95e584d9dd4a Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:25:27 +0200 Subject: [PATCH 37/64] IntegerValue API Change handling --- .../script.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Find All Sheets With Selected Revision.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Find All Sheets With Selected Revision.pushbutton/script.py index 584b4d0f9..ad11019bc 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Find All Sheets With Selected Revision.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Find All Sheets With Selected Revision.pushbutton/script.py @@ -1,15 +1,18 @@ from pyrevit import revit, DB +from pyrevit.compat import get_value_func selection = revit.get_selection() +value_func = get_value_func() + selectedrevs = [] hasSelectedRevision = False multipleRevs = False for s in selection: if isinstance(s, DB.RevisionCloud): - selectedrevs.append(s.RevisionId.IntegerValue) + selectedrevs.append(value_func(s.RevisionId)) if len(selectedrevs) > 1: multipleRevs = True @@ -26,7 +29,7 @@ for s in sheets: hasSelectedRevision = False revision_ids = s.GetAllRevisionIds() - revids = [x.IntegerValue for x in revision_ids] + revids = [value_func(x) for x in revision_ids] for sr in selectedrevs: if sr in revids: hasSelectedRevision = True From 7fa5450821c7c303bce98cc86cedfb192c224de7 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:26:50 +0200 Subject: [PATCH 38/64] IntegerValue API Change handling --- .../Explode And Remove Selected Groups.pushbutton/script.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Groups.pulldown/Explode And Remove Selected Groups.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Groups.pulldown/Explode And Remove Selected Groups.pushbutton/script.py index f9a53e8ed..f03a9a532 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Groups.pulldown/Explode And Remove Selected Groups.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Groups.pulldown/Explode And Remove Selected Groups.pushbutton/script.py @@ -5,10 +5,12 @@ from pyrevit import revit, DB from pyrevit import forms from pyrevit import script +from pyrevit.compat import get_value_func logger = script.get_logger() +value_func = get_value_func() group_types = set() for el in revit.get_selection(): @@ -22,9 +24,9 @@ logger.debug('all groups: %s', all_groups) # grab all group types to be deleted -group_type_ids = {x.Id.IntegerValue for x in group_types} +group_type_ids = {value_func(x.Id) for x in group_types} group_type_ids.update( - [x.GroupType.Id.IntegerValue for x in all_groups + [value_func(x.GroupType.Id) for x in all_groups if x.Parameter[DB.BuiltInParameter.GROUP_ATTACHED_PARENT_NAME]] ) logger.debug('group types: %s', group_type_ids) From f25c6810bfdf9bf34282ffc5d7c9f81976f3654d Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:28:21 +0200 Subject: [PATCH 39/64] IntegerValue API Change handling --- .../Create Workset For Linked Element.pushbutton/script.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Links.pulldown/Create Workset For Linked Element.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Links.pulldown/Create Workset For Linked Element.pushbutton/script.py index b2c4a66be..d3f24a106 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Links.pulldown/Create Workset For Linked Element.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Links.pulldown/Create Workset For Linked Element.pushbutton/script.py @@ -1,12 +1,13 @@ from pyrevit import revit, DB, UI from pyrevit import script from pyrevit import forms - +from pyrevit.compat import get_value_func logger = script.get_logger() selection = revit.get_selection() +value_func = get_value_func() linkedModelName = '' @@ -26,7 +27,7 @@ newWs = DB.Workset.Create(revit.doc, linkedModelName) worksetParam = \ el.Parameter[DB.BuiltInParameter.ELEM_PARTITION_PARAM] - worksetParam.Set(newWs.Id.IntegerValue) + worksetParam.Set(value_func(newWs.Id)) except Exception as e: print('Workset: {} already exists\nError: {}'.format(linkedModelName,e)) else: From d60c4073998e53a0224dd8a6144e460bde3c7a74 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:30:40 +0200 Subject: [PATCH 40/64] IntegerValue API Change handling --- .../script.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Find All Sheets Missing Revision Number.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Find All Sheets Missing Revision Number.pushbutton/script.py index a705405f8..10aaba2d7 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Find All Sheets Missing Revision Number.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Find All Sheets Missing Revision Number.pushbutton/script.py @@ -1,5 +1,7 @@ from pyrevit import revit, DB +from pyrevit.compat import get_value_func +value_func = get_value_func() # Collecting all revisions revclouds = DB.FilteredElementCollector(revit.doc)\ @@ -15,12 +17,12 @@ sheets = sorted(shts, key=lambda x: x.SheetNumber) # make a dictionary of all viewports on each sheet -sheetvpdict = {sh.Id.IntegerValue: [revit.doc.GetElement(x).ViewId +sheetvpdict = {value_func(sh.Id): [revit.doc.GetElement(x).ViewId for x in sh.GetAllViewports()] for sh in sheets} # make a dictionary of all revisions and the associated sheets -sheetrevs = {sh.Id.IntegerValue: [] for sh in sheets} +sheetrevs = {value_func(sh.Id): [] for sh in sheets} atleastonecrazysheetwasfound = False @@ -28,7 +30,7 @@ for revcloud in revclouds: # get revision info - revid = revcloud.RevisionId.IntegerValue + revid = value_func(revcloud.RevisionId) # get parent view parentvpid = revcloud.OwnerViewId @@ -48,7 +50,7 @@ for sheetid, revids in sheetrevs.items(): missedrevids = [] sheet = revit.doc.GetElement(DB.ElementId(sheetid)) - listedrevids = [x.IntegerValue for x in sheet.GetAllRevisionIds()] + listedrevids = [value_func(x) for x in sheet.GetAllRevisionIds()] for revid in revids: if revid not in listedrevids: missedrevids.append(revid) From 8622694804ef1a9bc4f7ad957d94ef337fd86c19 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:32:19 +0200 Subject: [PATCH 41/64] IntegerValue API Change handling --- .../Wipe Family Parameters.pushbutton/script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Family.pulldown/Wipe Family Parameters.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Family.pulldown/Wipe Family Parameters.pushbutton/script.py index 1e2374307..5867e0e9a 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Family.pulldown/Wipe Family Parameters.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Family.pulldown/Wipe Family Parameters.pushbutton/script.py @@ -5,7 +5,9 @@ from pyrevit import revit, DB from pyrevit import script from pyrevit import forms +from pyrevit.compat import get_value_func +value_func = get_value_func() output = script.get_output() logger = script.get_logger() @@ -49,7 +51,7 @@ def reset_param(family_param, reset_message): logger.debug('%s, %s', param.Id, param.Definition) output.update_progress(idx + 1, max_progress) # if builtin, reset values and skip delete - if param.Id.IntegerValue < 0: + if value_func(param.Id) < 0: message = \ 'Can not delete builtin "%s"' % param.Definition.Name logger.warning(reset_param(param, message)) From ce721715b5c8c5dec4d1c02a3a91b7e6866f9837 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:33:20 +0200 Subject: [PATCH 42/64] IntegerValue API Change handling --- .../Remove Underlay From Selected Views.pushbutton/script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Views.pulldown/Remove Underlay From Selected Views.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Views.pulldown/Remove Underlay From Selected Views.pushbutton/script.py index b89d17120..65cc9fc5a 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Views.pulldown/Remove Underlay From Selected Views.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack/Views.pulldown/Remove Underlay From Selected Views.pushbutton/script.py @@ -7,7 +7,9 @@ from pyrevit import HOST_APP from pyrevit import revit, DB from pyrevit import forms +from pyrevit.compat import get_value_func +value_func = get_value_func() selected_views = \ forms.select_views(filterfunc=lambda x: isinstance(x, DB.ViewPlan), use_selection=True) @@ -15,7 +17,7 @@ if selected_views: with revit.Transaction('Batch Set Underlay to None'): for view in selected_views: - if view.Category.Id.IntegerValue == \ + if value_func(view.Category.Id) == \ int(DB.BuiltInCategory.OST_Views) \ and (view.CanBePrinted): if HOST_APP.is_newer_than(2016): From d44b2918c0a3fb4b75c130ae60ed3512a8cb7ece Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:34:13 +0200 Subject: [PATCH 43/64] IntegerValue API Change handling --- .../Modify.panel/edit1.stack/Overkill.pushbutton/script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit1.stack/Overkill.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit1.stack/Overkill.pushbutton/script.py index 11ec7f027..b1bc8a893 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit1.stack/Overkill.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit1.stack/Overkill.pushbutton/script.py @@ -8,6 +8,7 @@ from pyrevit import revit, DB from pyrevit import forms from pyrevit import script +from pyrevit.compat import get_value_func logger = script.get_logger() @@ -41,7 +42,8 @@ def __init__(self, curve, include_style=False): self.cgroup_id = (self.dir_x, self.dir_y, self.dir_offset, self.weight) # set cgroup boundary - self.dir_cid = curve.Id.IntegerValue + value_func = get_value_func() + self.dir_cid = value_func(curve.Id) self.add_points([ self.get_point(p1.X, p1.Y), self.get_point(p2.X, p2.Y), From 1f9d233da850ffec926a1d4da4d4aea69b922f9c Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:37:21 +0200 Subject: [PATCH 44/64] IntegerValue API Change handling --- .../script.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py index 5952fe395..9ecb00883 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py @@ -4,8 +4,10 @@ from pyrevit import revit, DB, HOST_APP from pyrevit import forms +from pyrevit.compat import get_value_func from System.Collections.Generic import List +value_func = get_value_func() Taggable = namedtuple('Taggable', ['tag_type', 'element_type']) @@ -182,11 +184,11 @@ for room_tag_id in target_tags: room_tag = revit.doc.GetElement(room_tag_id) if room_tag.Room is not None: - tagged_rooms.append(room_tag.Room.Id.IntegerValue) + tagged_rooms.append(value_func(room_tag.Room.Id)) for room_id in target_elements: room = revit.doc.GetElement(room_id) - if room.Id.IntegerValue not in tagged_rooms: + if value_func(room.Id) not in tagged_rooms: untagged_rooms.append(room_id) if untagged_rooms: @@ -200,11 +202,11 @@ for area_tag_id in target_tags: area_tag = revit.doc.GetElement(area_tag_id) if area_tag.Area is not None: - tagged_areas.append(area_tag.Area.Id.IntegerValue) + tagged_areas.append(value_func(area_tag.Area.Id)) for area_id in target_elements: area = revit.doc.GetElement(area_id) - if area.Id.IntegerValue not in tagged_areas: + if value_func(area.Id) not in tagged_areas: untagged_areas.append(area_id) if untagged_areas: @@ -218,11 +220,11 @@ for space_tag_id in target_tags: space_tag = revit.doc.GetElement(space_tag_id) if space_tag.Space is not None: - tagged_spaces.append(space_tag.Space.Id.IntegerValue) + tagged_spaces.append(value_func(space_tag.Space.Id)) for space_id in target_elements: space = revit.doc.GetElement(space_id) - if space.Id.IntegerValue not in tagged_spaces: + if value_func(space.Id) not in tagged_spaces: untagged_spaces.append(space_id) if untagged_spaces: @@ -240,14 +242,14 @@ tagged_elements.append(List[DB.ElementId](elt.GetTaggedLocalElementIds())[0].Value) elif HOST_APP.is_newer_than(2022, or_equal=True): if elt.GetTaggedLocalElementIds() != DB.ElementId.InvalidElementId: - tagged_elements.append(List[DB.ElementId](elt.GetTaggedLocalElementIds())[0].IntegerValue) + tagged_elements.append(List[DB.ElementId](value_func(elt.GetTaggedLocalElementIds())[0])) else: if elt.TaggedLocalElementId != DB.ElementId.InvalidElementId: - tagged_elements.append(elt.TaggedLocalElementId.IntegerValue) + tagged_elements.append(value_func(elt.TaggedLocalElementId)) for elid in target_elements: el = revit.doc.GetElement(elid) - if el.Id.IntegerValue not in tagged_elements: + if value_func(el.Id) not in tagged_elements: untagged_elements.append(elid) if untagged_elements: From bbc1bf770139c35fa53845d3f56839a8a24559eb Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:39:02 +0200 Subject: [PATCH 45/64] IntegerValue API Change handling --- .../Drawing Set.panel/Print Sheets.pushbutton/script.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Print Sheets.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Print Sheets.pushbutton/script.py index dd584cee7..34641c31f 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Print Sheets.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Print Sheets.pushbutton/script.py @@ -34,7 +34,9 @@ from pyrevit import forms from pyrevit import revit, DB from pyrevit import script +from pyrevit.compat import get_value_func +value_func = get_value_func() logger = script.get_logger() config = script.get_config() @@ -488,7 +490,7 @@ def get_sheets(self, doc): def _get_schedule_text_data(self, view_shedule): schedule_data_file = \ - script.get_instance_data_file(str(view_shedule.Id.IntegerValue)) + script.get_instance_data_file(str(value_func(view_shedule.Id))) vseop = DB.ViewScheduleExportOptions() vseop.TextQualifier = coreutils.get_enum_none(DB.ExportTextQualifier) view_shedule.Export(op.dirname(schedule_data_file), @@ -1127,7 +1129,7 @@ def _get_sheet_printsettings(self, tblocks, psettings): sheet = self.selected_doc.GetElement(tblock.OwnerViewId) # build a unique id for this tblock tblock_tform = tblock.GetTotalTransform() - tblock_tid = tblock.GetTypeId().IntegerValue + tblock_tid = value_func(tblock.GetTypeId()) tblock_tid = tblock_tid * 100 \ + tblock_tform.BasisX.X * 10 \ + tblock_tform.BasisX.Y From b16dff35603c599dfb140847639d1436f0d53636 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:40:31 +0200 Subject: [PATCH 46/64] IntegerValue API Change handling --- .../Inspect IExporter.pushbutton/script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Developer Examples.panel/Inspect IExporter.pushbutton/script.py b/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Developer Examples.panel/Inspect IExporter.pushbutton/script.py index b70cab044..31a7870ae 100644 --- a/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Developer Examples.panel/Inspect IExporter.pushbutton/script.py +++ b/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Developer Examples.panel/Inspect IExporter.pushbutton/script.py @@ -5,6 +5,7 @@ from pyrevit.framework import List from pyrevit import revit, DB from pyrevit import script +from pyrevit.compat import get_value_func output = script.get_output() @@ -31,8 +32,9 @@ def log(msg): def log_element(doc, eid): el = doc.GetElement(eid) + value_func = get_value_func() log("id={} name={} type={} category={}".format( - eid.IntegerValue, + value_func(eid), revit.query.get_name(el), type(el), el.Category.Name if el.Category else "?" From bcd25b2995f3e7bef15b89215bf1fce419b73d9f Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:41:58 +0200 Subject: [PATCH 47/64] IntegerValue API Change handling --- .../script.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Dimensions.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Dimensions.pushbutton/script.py index 656d61e21..929ecf79e 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Dimensions.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Dimensions.pushbutton/script.py @@ -2,6 +2,7 @@ #pylint: disable=import-error,invalid-name from pyrevit import revit, DB, HOST_APP from pyrevit import forms +from pyrevit.compat import get_value_func categories = { 'Rooms': DB.BuiltInCategory.OST_Rooms, @@ -18,6 +19,7 @@ 'Columns': DB.BuiltInCategory.OST_StructuralColumns, } +value_func = get_value_func() # make sure active view is not a sheet if isinstance(revit.active_view, DB.ViewSheet): @@ -35,7 +37,7 @@ all_elements = DB.FilteredElementCollector(revit.doc, revit.active_view.Id)\ .OfCategory(target)\ .WhereElementIsNotElementType() - all_ids = set(x.Id.IntegerValue for x in all_elements) + all_ids = set(value_func(x.Id) for x in all_elements) all_dims = \ DB.FilteredElementCollector(revit.doc, revit.active_view.Id)\ @@ -48,7 +50,7 @@ if HOST_APP.is_newer_than(2023): dimmed_ids.add(ref.ElementId.Value) else: - dimmed_ids.add(ref.ElementId.IntegerValue) + dimmed_ids.add(value_func(ref.ElementId)) # find non dimmed not_dimmed_ids = all_ids.difference(dimmed_ids) From 8c4ed405720061d4e13cb3b53a7fbf0f84ad55ae Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:43:35 +0200 Subject: [PATCH 48/64] IntegerValue API Change handling --- .../Edit.pulldown/Convert Line Styles.pushbutton/script.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Edit.pulldown/Convert Line Styles.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Edit.pulldown/Convert Line Styles.pushbutton/script.py index 690106b10..b45a600e8 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Edit.pulldown/Convert Line Styles.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Edit.pulldown/Convert Line Styles.pushbutton/script.py @@ -10,6 +10,7 @@ from pyrevit import revit, DB from pyrevit import forms from pyrevit import script +from pyrevit.compat import get_value_func NO_COLOR_COLOR = '#000000' @@ -17,6 +18,8 @@ logger = script.get_logger() +value_func = get_value_func() + class StyleOption(object): def __init__(self, style): @@ -39,7 +42,7 @@ def name(self): @property def builtin(self): - return self.category.Id.IntegerValue < 0 + return value_func(self.category.Id) < 0 @property def category(self): @@ -245,7 +248,7 @@ def delete_linecats(self, line_converts): try: revit.doc.Delete(line_cat.Id) except Exception as ex: - if line_cat.Id.IntegerValue < 0: + if value_func(line_cat.Id) < 0: logger.error( 'Can not remove builtin line style \"%s\"', line_cat.Name From 5a029b2054eb2155c2022707b87b94686d65c470 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:44:48 +0200 Subject: [PATCH 49/64] IntegerValue API Change handling --- .../Wipe Unpurgable Viewport Types.pushbutton/script.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unpurgable Viewport Types.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unpurgable Viewport Types.pushbutton/script.py index 6c28a3355..c42c36804 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unpurgable Viewport Types.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unpurgable Viewport Types.pushbutton/script.py @@ -4,7 +4,7 @@ from pyrevit import forms from pyrevit import revit, DB, UI from pyrevit import script - +from pyrevit.compat import get_value_func logger = script.get_logger() @@ -17,10 +17,11 @@ def __str__(self): return revit.query.get_name(self._rvt_type) def __repr__(self): + value_func = get_value_func() return '<{} Name:{} Id:{}>'\ .format(self.__class__.__name__, revit.query.get_name(self._rvt_type), - self._rvt_type.Id.IntegerValue) + value_func(self._rvt_type.Id)) def __lt__(self, other): return str(self) < str(other) From dd96208d23697c84315167f7684422d8a422c4cc Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:46:28 +0200 Subject: [PATCH 50/64] IntegerValue API Change handling --- .../Spy.pulldown/List Elements.pushbutton/script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/tools.stack/Spy.pulldown/List Elements.pushbutton/script.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/tools.stack/Spy.pulldown/List Elements.pushbutton/script.py index 57da3f3d3..022f447f1 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/tools.stack/Spy.pulldown/List Elements.pushbutton/script.py +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/tools.stack/Spy.pulldown/List Elements.pushbutton/script.py @@ -8,6 +8,7 @@ from pyrevit import revit, DB, UI from pyrevit import forms from pyrevit import script +from pyrevit.compat import get_value_func output = script.get_output() @@ -219,11 +220,12 @@ .OfCategory(DB.BuiltInCategory.OST_Levels)\ .WhereElementIsNotElementType() + value_func = get_value_func() for i in levelslist: print('Level ID:\t{1}\t' 'ELEVATION:{2}\t\t' 'Name:\t{0}'.format(i.Name, - i.Id.IntegerValue, + value_func(i.Id), i.Elevation)) elif selected_switch == 'Scope Boxes': From 49b92296a42e6db2de66c0a93382e11e18ea8c02 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:48:11 +0200 Subject: [PATCH 51/64] IntegerValue API Change handling --- .../Match Properties.pushbutton/script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit1.stack/Match.splitpushbutton/Match Properties.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit1.stack/Match.splitpushbutton/Match Properties.pushbutton/script.py index 7b5b56f6f..0a1f3ba27 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit1.stack/Match.splitpushbutton/Match Properties.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit1.stack/Match.splitpushbutton/Match Properties.pushbutton/script.py @@ -10,6 +10,7 @@ from pyrevit import revit, DB from pyrevit import forms from pyrevit import script +from pyrevit.compat import get_value_func logger = script.get_logger() @@ -95,7 +96,8 @@ def get_source_properties(src_element): elif tparam.StorageType == DB.StorageType.Double: value = tparam.AsDouble() elif tparam.StorageType == DB.StorageType.ElementId: - value = tparam.AsElementId().IntegerValue + value_func = get_value_func() + value = value_func(tparam.AsElementId()) else: value = tparam.AsString() From 359e70777ebe727671ed52235dbd88e71b1914df Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:49:43 +0200 Subject: [PATCH 52/64] IntegerValue API Change handling --- .../Wipe Unused View Templates.pushbutton/script.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unused View Templates.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unused View Templates.pushbutton/script.py index 8d90de335..5ade564bc 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unused View Templates.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unused View Templates.pushbutton/script.py @@ -1,5 +1,6 @@ from pyrevit import forms from pyrevit import revit, DB +from pyrevit.compat import get_value_func class ViewTemplateToPurge(forms.TemplateListItem): @@ -20,12 +21,14 @@ def name(self): for v in viewlist: if v.IsTemplate and 'master' not in revit.query.get_name(v).lower(): - vtemp.add(v.Id.IntegerValue) + value_func = get_value_func() + vtemp.add(value_func(v.Id)) else: views.append(v) for v in views: - vtid = v.ViewTemplateId.IntegerValue + value_func = get_value_func() + vtid = value_func(v.ViewTemplateId) if vtid > 0: usedvtemp.add(vtid) From e6bdb3d78dcf280adce897f683463d743a8adc81 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:55:35 +0200 Subject: [PATCH 53/64] IntegerValue API Change handling --- .../ColorSplasher.pushbutton/script.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/ColorSplasher.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/ColorSplasher.pushbutton/script.py index c98b30988..ba5cf2d49 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/ColorSplasher.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/ColorSplasher.pushbutton/script.py @@ -47,6 +47,8 @@ from System.Collections.Generic import * from pyrevit import HOST_APP, revit +from pyrevit.compat import get_value_func + class subscribeView(IExternalEventHandler): def __init__(self): @@ -116,14 +118,15 @@ def Execute(self, uiapp): t = Transaction(new_doc, "Apply colors to elements") t.Start() sel_cat = wndw._categories.SelectedItem['Value'] - if sel_cat._cat.Id.IntegerValue == int(BuiltInCategory.OST_Rooms) or sel_cat._cat.Id.IntegerValue == int(BuiltInCategory.OST_MEPSpaces) or sel_cat._cat.Id.IntegerValue == int(BuiltInCategory.OST_Areas): + value_func = get_value_func() + if value_func(sel_cat._cat.Id) == int(BuiltInCategory.OST_Rooms) or value_func(sel_cat._cat.Id) == int(BuiltInCategory.OST_MEPSpaces) or value_func(sel_cat._cat.Id) == int(BuiltInCategory.OST_Areas): #In case of rooms, spaces and areas. Check Color scheme is applied and if not if version > 2021: if str(wndw.crt_view.GetColorFillSchemeId(sel_cat._cat.Id)) == "-1": fColorScheme = FilteredElementCollector(new_doc).OfClass(ColorFillScheme).ToElements() if len(fColorScheme) > 0: for sch in fColorScheme: - if sch.CategoryId.IntegerValue == sel_cat._cat.Id.IntegerValue: + if sch.CategoryId == sel_cat._cat.Id: if len(sch.GetEntries()) > 0: wndw.crt_view.SetColorFillSchemeId(sel_cat._cat.Id, sch.Id) break @@ -228,11 +231,12 @@ def Execute(self, uiapp): old_all_ele = FilteredElementCollector(new_doc, legends[0].Id).ToElements() ele_id_type = ElementId(0) for ele in old_all_ele: - if ele.Id.IntegerValue != newLegend.Id.IntegerValue and ele.Category != None: + if ele.Id != newLegend.Id and ele.Category != None: if isinstance(ele, TextNote): ele_id_type = ele.GetTypeId() break - if ele_id_type.IntegerValue == 0: + value_func = get_value_func() + if value_func(ele_id_type) == 0: #Get any text in model all_text_notes = FilteredElementCollector(new_doc).OfClass(TextNoteType).ToElements() for ele in all_text_notes: @@ -479,7 +483,8 @@ class categ_info(): def __init__(self, cat, param): self._name = strip_accents(cat.Name) self._cat = cat - self._intId = cat.Id.IntegerValue + value_func = get_value_func() + self._intId = value_func(cat.Id) self._par = param def getActiveView(ac_doc): @@ -509,7 +514,8 @@ def getValuePar(para): value = para.AsValueString() elif para.StorageType == StorageType.ElementId: id_val = para.AsElementId() - if id_val.IntegerValue >= 0: + value_func = get_value_func() + if value_func(id_val) >= 0: value = Element.Name.__get__(doc.GetElement(id_val)) else: value ="None" @@ -606,7 +612,8 @@ def getCategoriesAndParametersInUsed(cat_exc, acti_view): list_cat = [] for ele in collector: if ele.Category != None: - current_int_cat_id = ele.Category.Id.IntegerValue + value_func = get_value_func() + current_int_cat_id = value_func(ele.Category.Id) if not current_int_cat_id in cat_exc and current_int_cat_id < -1: if not any(x._intId == current_int_cat_id for x in list_cat): list_parameters=[] From e56e533a5535331c85c51828ff5db6d6c2ae776f Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:56:59 +0200 Subject: [PATCH 54/64] IntegerValue API Change handling --- .../Select.pulldown/Invert Selection.pushbutton/script.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Invert Selection.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Invert Selection.pushbutton/script.py index a17b9bf9e..bc0dcfbe5 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Invert Selection.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Invert Selection.pushbutton/script.py @@ -5,7 +5,9 @@ """ #pylint: disable=import-error,invalid-name,broad-except from pyrevit import revit, DB +from pyrevit.compat import get_value_func +value_func = get_value_func() # get view elements viewelements = DB.FilteredElementCollector(revit.doc, revit.active_view.Id)\ @@ -14,11 +16,11 @@ # remove anything that is a direct DB.Element obj # these are the weird internal objects that Revit uses like a camera obj view_element_ids = \ - {x.Id.IntegerValue for x in viewelements if x.GetType() is not DB.Element} + {value_func(x.Id) for x in viewelements if x.GetType() is not DB.Element} # get current selection selection = revit.get_selection() -selected_element_ids = {x.Id.IntegerValue for x in selection} +selected_element_ids = {value_func(x.Id) for x in selection} # find elements that are not selected invert_ids = view_element_ids.difference(selected_element_ids) @@ -30,7 +32,7 @@ if not __shiftclick__: #pylint: disable=undefined-variable # collect ids of elements inside a group grouped_element_ids = \ - [x.Id.IntegerValue for x in viewelements + [value_func(x.Id) for x in viewelements if x.GetType() is not DB.Element and x.GroupId != DB.ElementId.InvalidElementId] From c8cbd539181a8d18b61410b73502702ff44cae83 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 19:58:15 +0200 Subject: [PATCH 55/64] IntegerValue API Change handling --- .../Wipe Unused Filters.pushbutton/script.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unused Filters.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unused Filters.pushbutton/script.py index bb35250b4..4f191343a 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unused Filters.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/Wipe.pulldown/Wipe Unused Filters.pushbutton/script.py @@ -1,6 +1,7 @@ from pyrevit import forms from pyrevit import revit, DB, UI from pyrevit import script +from pyrevit.compat import get_value_func logger = script.get_logger() @@ -23,8 +24,11 @@ def name(self): usedFiltersSet = set() allFilters = set() + +value_func = get_value_func() + for flt in filters: - allFilters.add(flt.Id.IntegerValue) + allFilters.add(value_func(flt.Id)) # print('{} Filters found.'.format(len(allFilters))) @@ -32,7 +36,7 @@ def name(self): if v.AreGraphicsOverridesAllowed(): view_filters = v.GetFilters() for filter_id in view_filters: - usedFiltersSet.add(filter_id.IntegerValue) + usedFiltersSet.add(value_func(filter_id)) if not allFilters: forms.alert('There are no filters available.') From 31f86523439f600c289427da42ae8459883a2018 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 20:01:55 +0200 Subject: [PATCH 56/64] IntegerValue API Change handling --- .../Test Family API.pushbutton/script.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Debug.panel/Unit Tests.pulldown/Test Family API.pushbutton/script.py b/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Debug.panel/Unit Tests.pulldown/Test Family API.pushbutton/script.py index b0877b9c8..fdc475e68 100644 --- a/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Debug.panel/Unit Tests.pulldown/Test Family API.pushbutton/script.py +++ b/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Debug.panel/Unit Tests.pulldown/Test Family API.pushbutton/script.py @@ -14,7 +14,7 @@ from pyrevit import revit, DB, script, HOST_APP from pyrevit.revit.db.create import FamilyLoaderOptionsHandler from pyrevit.revit.db.transaction import Transaction - +from pyrevit.compat import get_value_func __context__ = "doc-project" @@ -162,7 +162,8 @@ def test_family_api(): family_element = family_doc.LoadFamily(revit.doc, FamilyLoaderOptionsHandler()) LOG.info("Loaded test family into current document.") family_doc.Close() - assert _family_type_count(family_element.Id.IntegerValue) == 1 + value_func = get_value_func() + assert _family_type_count(value_func(family_element.Id)) == 1 LOG.info("Checked that only the base type is in the test family.") family_doc = revit.doc.EditFamily(family_element) _add_types(family_doc) @@ -176,14 +177,16 @@ def test_family_api(): family_element = family_doc.LoadFamily(revit.doc, FamilyLoaderOptionsHandler()) family_doc.Close() LOG.info("Reloaded test family into current file.") - assert _family_type_count(family_element.Id.IntegerValue) == type_count + value_func = get_value_func() + assert _family_type_count(value_func(family_element.Id)) == type_count LOG.info( "Checked that {0} type{1} are in the test family, as expected.".format( type_count, "" if type_count == 1 else "s", ) ) - _check_type_parameter_values(family_element.Id.IntegerValue) + value_func = get_value_func() + _check_type_parameter_values(value_func(family_element.Id)) LOG.info("Checked that the parameter values are correct in the test family.") _purge_family() LOG.info("Test completed.") From d202ec1908c26449bd917ae6bec3624e5fe4743a Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Wed, 28 Aug 2024 20:04:29 +0200 Subject: [PATCH 57/64] IntegerValue API Change handling --- .../Test CPython Command.pushbutton/script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Debug.panel/Engine Tests.pulldown/Test CPython Command.pushbutton/script.py b/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Debug.panel/Engine Tests.pulldown/Test CPython Command.pushbutton/script.py index 1b23a4f25..7a1ee27ba 100644 --- a/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Debug.panel/Engine Tests.pulldown/Test CPython Command.pushbutton/script.py +++ b/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Debug.panel/Engine Tests.pulldown/Test CPython Command.pushbutton/script.py @@ -88,8 +88,10 @@ def print_html(output_str): .ToElements() print('\n## list of DB.Walls:') +from pyrevit.compat import get_value_func +value_func = get_value_func() for wall in cl: - print(f'{wall} id:{wall.Id.IntegerValue}') + print(f'{wall} id:{value_func(wall.Id)}') # test unicode print(""" From 9db18509dcdef3474e4aed4bd90c8117151250dc Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Thu, 29 Aug 2024 10:32:37 +0200 Subject: [PATCH 58/64] Update script.py --- .../Analysis.panel/ColorSplasher.pushbutton/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/ColorSplasher.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/ColorSplasher.pushbutton/script.py index ba5cf2d49..4c0257450 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/ColorSplasher.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/ColorSplasher.pushbutton/script.py @@ -119,7 +119,7 @@ def Execute(self, uiapp): t.Start() sel_cat = wndw._categories.SelectedItem['Value'] value_func = get_value_func() - if value_func(sel_cat._cat.Id) == int(BuiltInCategory.OST_Rooms) or value_func(sel_cat._cat.Id) == int(BuiltInCategory.OST_MEPSpaces) or value_func(sel_cat._cat.Id) == int(BuiltInCategory.OST_Areas): + if value_func(sel_cat._cat.Id) in (int(BuiltInCategory.OST_Rooms), int(BuiltInCategory.OST_MEPSpaces), int(BuiltInCategory.OST_Areas)): #In case of rooms, spaces and areas. Check Color scheme is applied and if not if version > 2021: if str(wndw.crt_view.GetColorFillSchemeId(sel_cat._cat.Id)) == "-1": From a04876bc0c23d11f7c59fbc1228e919130a60217 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Thu, 29 Aug 2024 10:55:34 +0200 Subject: [PATCH 59/64] Update script.py --- .../Find And Select Entities Without Tags.pushbutton/script.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py index 9ecb00883..e20a314fb 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py @@ -237,9 +237,6 @@ untagged_elements = [] for eltid in target_tags: elt = revit.doc.GetElement(eltid) - if HOST_APP.is_newer_than(2023): - if elt.GetTaggedLocalElementIds() != DB.ElementId.InvalidElementId: - tagged_elements.append(List[DB.ElementId](elt.GetTaggedLocalElementIds())[0].Value) elif HOST_APP.is_newer_than(2022, or_equal=True): if elt.GetTaggedLocalElementIds() != DB.ElementId.InvalidElementId: tagged_elements.append(List[DB.ElementId](value_func(elt.GetTaggedLocalElementIds())[0])) From e23fdae58ec228a2fba2934e7a6176fb210f8372 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Thu, 29 Aug 2024 10:57:02 +0200 Subject: [PATCH 60/64] Update script.py --- .../Find And Select Entities Without Tags.pushbutton/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py index e20a314fb..5b9898455 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack/Select.pulldown/Find And Select Entities Without Tags.pushbutton/script.py @@ -242,7 +242,7 @@ tagged_elements.append(List[DB.ElementId](value_func(elt.GetTaggedLocalElementIds())[0])) else: if elt.TaggedLocalElementId != DB.ElementId.InvalidElementId: - tagged_elements.append(value_func(elt.TaggedLocalElementId)) + tagged_elements.append(elt.TaggedLocalElementId.IntegerValue) for elid in target_elements: el = revit.doc.GetElement(elid) From edfde6a8a44162a3447a7e10817fb029c9ba91eb Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Thu, 29 Aug 2024 10:58:10 +0200 Subject: [PATCH 61/64] Update pickling.py --- pyrevitlib/pyrevit/revit/db/pickling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrevitlib/pyrevit/revit/db/pickling.py b/pyrevitlib/pyrevit/revit/db/pickling.py index 85f719f6e..06791da1c 100644 --- a/pyrevitlib/pyrevit/revit/db/pickling.py +++ b/pyrevitlib/pyrevit/revit/db/pickling.py @@ -39,8 +39,8 @@ class NoneSerializer(Serializable): class ElementId(Serializable): api_types = DB.ElementId - value_func = get_value_func() def __init__(self, element_id): + value_func = get_value_func() self.integer_value = value_func(element_id) def deserialize(self): From 94545fb5ca9ccbc22c281362e7bb2cda2e326a50 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Thu, 29 Aug 2024 11:01:23 +0200 Subject: [PATCH 62/64] Update query.py --- pyrevitlib/pyrevit/revit/db/query.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrevitlib/pyrevit/revit/db/query.py b/pyrevitlib/pyrevit/revit/db/query.py index cfa81af3a..17180f456 100644 --- a/pyrevitlib/pyrevit/revit/db/query.py +++ b/pyrevitlib/pyrevit/revit/db/query.py @@ -798,7 +798,7 @@ def get_category(cat_name_or_builtin, doc=None): return cat elif isinstance(cat_name_or_builtin, DB.BuiltInCategory): for cat in all_cats: - if cat.Id == cat_name_or_builtin: + if value_func(cat.Id) == int(cat_name_or_builtin): return cat elif isinstance(cat_name_or_builtin, DB.Category): return cat_name_or_builtin @@ -815,7 +815,7 @@ def get_builtincategory(cat_name_or_id, doc=None): cat_id = cat_name_or_id if cat_id: for bicat in DB.BuiltInCategory.GetValues(DB.BuiltInCategory): - if bicat == cat_id: + if int(bicat) == value_func(cat_id): return bicat @@ -851,7 +851,7 @@ def get_builtinparameter(element, param_name, doc=None): if eparam: eparam_def_id = eparam.Definition.Id for biparam in DB.BuiltInParameter.GetValues(DB.BuiltInParameter): - if biparam == eparam_def_id: + if int(biparam) == value_func(eparam_def_id): return biparam else: raise PyRevitException('Parameter not found: {}'.format(param_name)) From d0c10a3da3af9b0c89104b08d102063285cc0837 Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Thu, 29 Aug 2024 11:03:12 +0200 Subject: [PATCH 63/64] Update builtins.py --- pyrevitlib/rpw/db/builtins.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pyrevitlib/rpw/db/builtins.py b/pyrevitlib/rpw/db/builtins.py index f473e80a5..7ac15a73c 100644 --- a/pyrevitlib/rpw/db/builtins.py +++ b/pyrevitlib/rpw/db/builtins.py @@ -156,11 +156,9 @@ def from_category_id(self, category_id): Returns: ``DB.BuiltInCategory`` member """ - value_func = get_value_func() - bic = Enum.ToObject(DB.BuiltInCategory, value_func(category_id)) - bic_value = value_func(DB.ElementId(bic)) - if bic_value < -1: - return bic + cat_id_value = value_func(category_id) + if cat_id_value < -1 and Enum.IsDefined(DB.BuiltInCategory, cat_id_value): + return Enum.ToObject(DB.BuiltInCategory, cat_id_value) else: # If you pass a regular element to category_id, it converts it to BIC. # It should fail, because result is not a valid Category Enum From bf3cabae739788c06de8ea0378cad108637db1df Mon Sep 17 00:00:00 2001 From: Jean-Marc Couffin Date: Thu, 29 Aug 2024 11:04:21 +0200 Subject: [PATCH 64/64] Update family.py --- pyrevitlib/rpw/db/family.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyrevitlib/rpw/db/family.py b/pyrevitlib/rpw/db/family.py index af757310a..1a99a93d7 100644 --- a/pyrevitlib/rpw/db/family.py +++ b/pyrevitlib/rpw/db/family.py @@ -94,8 +94,7 @@ def in_assembly(self): Returns: (bool): True if element is inside an AssemblyInstance """ - value_func = get_value_func() - return value_func(self._revit_object.AssemblyInstanceId) != -1 + return self._revit_object.AssemblyInstanceId != DB.ElementId.InvalidElementId @property def get_assembly(self, wrapped=True):