Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsolete IntegerValue property in Revit2024 and higher - Replaced by Value #2380

Merged
merged 66 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
44e410b
Obsolet IntegerValue property in Revit2024 and higher
jmcouffin Aug 27, 2024
a1d0e0b
Update update.py
jmcouffin Aug 27, 2024
af58138
Update linkmaker.py
jmcouffin Aug 27, 2024
6ffad4e
Update builtins.py
jmcouffin Aug 27, 2024
261680d
Update pkgmgr.py
jmcouffin Aug 27, 2024
2182b00
Update family.py
jmcouffin Aug 27, 2024
c6af60a
Update create.py
jmcouffin Aug 27, 2024
e42b758
Update query.py
jmcouffin Aug 27, 2024
87e2ee5
Update parameter.py
jmcouffin Aug 27, 2024
bf13351
Add get_value_func for ElementId Class
jmcouffin Aug 28, 2024
7698bf3
updated with compat func
jmcouffin Aug 28, 2024
1bdabda
updated with compat func
jmcouffin Aug 28, 2024
432633e
updated with compat func
jmcouffin Aug 28, 2024
2bb0b66
updated with compat func
jmcouffin Aug 28, 2024
ae6773f
updated with compat func
jmcouffin Aug 28, 2024
b7f0f2d
updated with compat func
jmcouffin Aug 28, 2024
145cc2f
updated with compat func
jmcouffin Aug 28, 2024
c5c5b52
updated with compat func
jmcouffin Aug 28, 2024
f937f92
update with compat func
jmcouffin Aug 28, 2024
2f4a794
update with compat func
jmcouffin Aug 28, 2024
aad0547
Update family.py
jmcouffin Aug 28, 2024
e134dc5
editing comparison of Ids in query module
jmcouffin Aug 28, 2024
4964f48
Merge branch 'integer_value_obsolete' of https://github.com/jmcouffin…
jmcouffin Aug 28, 2024
ee692c1
IntegerValue API Change handling
jmcouffin Aug 28, 2024
c3f5f66
IntegerValue API Change handling
jmcouffin Aug 28, 2024
df924c2
IntegerValue API Change handling
jmcouffin Aug 28, 2024
8e35070
IntegerValue API Change handling
jmcouffin Aug 28, 2024
df28f84
IntegerValue API Change handling
jmcouffin Aug 28, 2024
c121e32
IntegerValue API Change handling
jmcouffin Aug 28, 2024
d2a5b21
IntegerValue API Change handling
jmcouffin Aug 28, 2024
c40b09d
IntegerValue API Change handling
jmcouffin Aug 28, 2024
ac6685a
IntegerValue API Change handling
jmcouffin Aug 28, 2024
c1e432e
IntegerValue API Change handling
jmcouffin Aug 28, 2024
a061675
IntegerValue API Change handling
jmcouffin Aug 28, 2024
07b06f3
IntegerValue API Change handling
jmcouffin Aug 28, 2024
a86c05e
IntegerValue API Change handling
jmcouffin Aug 28, 2024
9dc80e2
IntegerValue API Change handling
jmcouffin Aug 28, 2024
13032f3
IntegerValue API Change handling
jmcouffin Aug 28, 2024
7fa5450
IntegerValue API Change handling
jmcouffin Aug 28, 2024
f25c681
IntegerValue API Change handling
jmcouffin Aug 28, 2024
d60c407
IntegerValue API Change handling
jmcouffin Aug 28, 2024
8622694
IntegerValue API Change handling
jmcouffin Aug 28, 2024
ce72171
IntegerValue API Change handling
jmcouffin Aug 28, 2024
d44b291
IntegerValue API Change handling
jmcouffin Aug 28, 2024
1f9d233
IntegerValue API Change handling
jmcouffin Aug 28, 2024
bbc1bf7
IntegerValue API Change handling
jmcouffin Aug 28, 2024
b16dff3
IntegerValue API Change handling
jmcouffin Aug 28, 2024
bcd25b2
IntegerValue API Change handling
jmcouffin Aug 28, 2024
8c4ed40
IntegerValue API Change handling
jmcouffin Aug 28, 2024
5a029b2
IntegerValue API Change handling
jmcouffin Aug 28, 2024
dd96208
IntegerValue API Change handling
jmcouffin Aug 28, 2024
49b9229
IntegerValue API Change handling
jmcouffin Aug 28, 2024
359e707
IntegerValue API Change handling
jmcouffin Aug 28, 2024
e6bdb3d
IntegerValue API Change handling
jmcouffin Aug 28, 2024
e56e533
IntegerValue API Change handling
jmcouffin Aug 28, 2024
c8cbd53
IntegerValue API Change handling
jmcouffin Aug 28, 2024
31f8652
IntegerValue API Change handling
jmcouffin Aug 28, 2024
d202ec1
IntegerValue API Change handling
jmcouffin Aug 28, 2024
9db1850
Update script.py
jmcouffin Aug 29, 2024
a04876b
Update script.py
jmcouffin Aug 29, 2024
e23fdae
Update script.py
jmcouffin Aug 29, 2024
edfde6a
Update pickling.py
jmcouffin Aug 29, 2024
94545fb
Update query.py
jmcouffin Aug 29, 2024
d0c10a3
Update builtins.py
jmcouffin Aug 29, 2024
bf3caba
Update family.py
jmcouffin Aug 29, 2024
3acc9a3
Merge branch 'develop' into integer_value_obsolete
jmcouffin Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions extensions/pyRevitTags.extension/lib/pkgmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,11 +69,9 @@ 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()}
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
Expand Down Expand Up @@ -153,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):
Expand All @@ -167,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
Expand All @@ -185,7 +184,7 @@ def get_commit_points():
key=lambda x: x.SequenceNumber)
commit_points.extend([
CommitPoint(cptype=CommitPointTypes.Revision,
target=x.Id.IntegerValue,
target=value_func(x.Id),
idx=last_docpkg_idx + i + 1,
name='R{}'.format(x.SequenceNumber),
desc='{}{} (Sequence #{})'.format(
Expand All @@ -195,7 +194,6 @@ def get_commit_points():
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -40,7 +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":
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()),
Expand Down
31 changes: 30 additions & 1 deletion pyrevitlib/pyrevit/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
7 changes: 4 additions & 3 deletions pyrevitlib/pyrevit/output/linkmaker.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -48,11 +48,12 @@ def make_link(element_ids, contents=None):
print('{}: {}'.format(idx+1, output.linkify(elid)))
```
"""
value_func = get_value_func()
try:
try:
strids = [safe_strtype(x.IntegerValue) for x in element_ids]
strids = [safe_strtype(value_func(x)) for x in element_ids]
except TypeError:
strids = [safe_strtype(element_ids.IntegerValue)]
strids = [safe_strtype(value_func(element_ids))]
except AttributeError:
raise ValueError("One or more items are not ElementIds")

Expand Down
16 changes: 9 additions & 7 deletions pyrevitlib/pyrevit/revit/db/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -290,13 +291,12 @@ 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()
sheet_revids = [x.IntegerValue for x in revs]
if check_func([x.Id.IntegerValue in sheet_revids
for x in revisions]):
myviewset.Insert(sheet)

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
# create new sheet set
Expand Down Expand Up @@ -404,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)
Expand Down Expand Up @@ -436,14 +437,15 @@ def create_param_value_filter(filter_name,
str(pvalue),
False)
elif isinstance(pvalue, DB.ElementId):
p_id = str(value_func(pvalue))
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):
Expand Down
32 changes: 21 additions & 11 deletions pyrevitlib/pyrevit/revit/db/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -760,9 +760,10 @@ 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 cat.Id.IntegerValue == cat_id.IntegerValue:
if value_func(cat.Id) == value_func(cat_id):
cats.append(cat)
return cats

Expand All @@ -771,9 +772,10 @@ 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 cat.Id.IntegerValue == cat_id.IntegerValue:
if value_func(cat.Id) == value_func(cat_id):
cats.append(cat)
return cats

Expand All @@ -782,9 +784,10 @@ 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 cat.Id.IntegerValue == cat_id.IntegerValue:
if value_func(cat.Id) == value_func(cat_id):
cats.append(cat)
return cats

Expand All @@ -797,8 +800,9 @@ 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 cat.Id.IntegerValue == int(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
Expand All @@ -807,12 +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
value_func = get_value_func()
if isinstance(cat_name_or_id, str):
cat = get_category(cat_name_or_id)
if cat:
cat_id = cat.Id.IntegerValue
cat_id = value_func(cat.Id)
elif isinstance(cat_name_or_id, DB.ElementId):
cat_id = cat_name_or_id.IntegerValue
cat_id = value_func(cat_name_or_id)
if cat_id:
for bicat in DB.BuiltInCategory.GetValues(DB.BuiltInCategory):
if int(bicat) == cat_id:
Expand All @@ -823,16 +828,16 @@ def get_subcategories(doc=None, purgable=False, filterfunc=None):
doc = doc or DOCS.doc
# collect custom categories
subcategories = []
value_func = get_value_func()
for cat in doc.Settings.Categories:
for subcat in cat.SubCategories:
if purgable:
if subcat.Id.IntegerValue > 1:
if value_func(subcat.Id) > 1:
subcategories.append(subcat)
else:
subcategories.append(subcat)
if filterfunc:
subcategories = filter(filterfunc, subcategories)

return subcategories


Expand All @@ -848,10 +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:
eparam_def_id = value_func(eparam.Definition.Id)
for biparam in DB.BuiltInParameter.GetValues(DB.BuiltInParameter):
if int(biparam) == eparam.Definition.Id.IntegerValue:
if int(biparam) == eparam_def_id:
return biparam
else:
raise PyRevitException('Parameter not found: {}'.format(param_name))


def get_view_cutplane_offset(view):
Expand Down Expand Up @@ -1576,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):
Expand All @@ -1585,5 +1595,5 @@ 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)
mlogger.debug("element %s has no geometry", value_func(element.Id))
return
13 changes: 6 additions & 7 deletions pyrevitlib/pyrevit/revit/db/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -20,28 +21,26 @@ 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]

updated_sheets = []
if revisions:
# get sheets if not available
for sheet in sheets or query.get_sheets(doc=doc):
addrevs = set([x.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(rev.Id.IntegerValue)
elif rev.Id.IntegerValue in addrevs:
addrevs.remove(rev.Id.IntegerValue)

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)

return updated_sheets


Expand Down
7 changes: 5 additions & 2 deletions pyrevitlib/rpw/db/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -155,8 +156,10 @@ 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:
value_func = get_value_func()
bic = Enum.ToObject(DB.BuiltInCategory, value_func(category_id))
bic_value = value_func(DB.ElementId(bic))
jmcouffin marked this conversation as resolved.
Show resolved Hide resolved
if bic_value < -1:
return bic
else:
# If you pass a regular element to category_id, it converts it to BIC.
Expand Down
5 changes: 4 additions & 1 deletion pyrevitlib/rpw/db/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -93,7 +94,9 @@ def in_assembly(self):
Returns:
(bool): True if element is inside an AssemblyInstance
"""
if self._revit_object.AssemblyInstanceId.IntegerValue == -1:
value_func = get_value_func()
assembly_id_value = value_func(self._revit_object.AssemblyInstanceId)
if assembly_id_value == -1:
return False
else:
return True
jmcouffin marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading