Skip to content

Commit bfa2787

Browse files
authored
Merge pull request #2657 from Wurschdhaud/develop
Adding hosted level and z-offset from level to list DWGs printout
2 parents 0c3a967 + 1b5fc02 commit bfa2787

File tree

1 file changed

+59
-32
lines changed
  • extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Links.pulldown/ListDWGs.pushbutton

1 file changed

+59
-32
lines changed
Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: UTF-8 -*-
22
"""Lists all linked and imported DWG instances with worksets and creator."""
3-
import clr
43
from collections import defaultdict
54

65
from pyrevit import revit, DB
@@ -9,19 +8,25 @@
98

109

1110
output = script.get_output()
11+
mlogger = script.get_logger()
1212

1313

1414
def listdwgs(current_view_only=False):
15-
dwgs = DB.FilteredElementCollector(revit.doc)\
16-
.OfClass(DB.ImportInstance)\
17-
.WhereElementIsNotElementType()\
18-
.ToElements()
15+
dwgs = (
16+
DB.FilteredElementCollector(revit.doc)
17+
.OfClass(DB.ImportInstance)
18+
.WhereElementIsNotElementType()
19+
.ToElements()
20+
)
1921

2022
dwgInst = defaultdict(list)
2123

2224
output.print_md("## LINKED AND IMPORTED DWG FILES:")
23-
output.print_md('By: [{}]({})'.format('Frederic Beaupere',
24-
'https://github.com/frederic-beaupere'))
25+
output.print_md(
26+
"By: [{}]({})".format(
27+
"Frederic Beaupere", "https://github.com/frederic-beaupere"
28+
)
29+
)
2530

2631
for dwg in dwgs:
2732
if dwg.IsLinked:
@@ -33,34 +38,56 @@ def listdwgs(current_view_only=False):
3338
output.print_md("####{}".format(link_mode))
3439
for dwg in dwgInst[link_mode]:
3540
dwg_id = dwg.Id
36-
dwg_name = \
37-
dwg.Parameter[DB.BuiltInParameter.IMPORT_SYMBOL_NAME].AsString()
41+
dwg_name = dwg.Parameter[DB.BuiltInParameter.IMPORT_SYMBOL_NAME].AsString()
3842
dwg_workset = revit.query.get_element_workset(dwg).Name
39-
dwg_instance_creator = \
40-
DB.WorksharingUtils.GetWorksharingTooltipInfo(revit.doc,
41-
dwg.Id).Creator
43+
dwg_instance_creator = DB.WorksharingUtils.GetWorksharingTooltipInfo(
44+
revit.doc, dwg.Id
45+
).Creator
4246

43-
if current_view_only \
44-
and revit.active_view.Id != dwg.OwnerViewId:
47+
if current_view_only and revit.active_view.Id != dwg.OwnerViewId:
4548
continue
4649

47-
print('\n\n')
48-
output.print_md("**DWG name:** {}\n\n"
49-
"- DWG created by:{}\n\n"
50-
"- DWG id: {}\n\n"
51-
"- DWG workset: {}\n\n"
52-
.format(dwg_name,
53-
dwg_instance_creator,
54-
output.linkify(dwg_id),
55-
dwg_workset))
56-
57-
58-
selected_option = \
59-
forms.CommandSwitchWindow.show(
60-
['In Current View',
61-
'In Model'],
62-
message='Select search option:'
63-
)
50+
# Get hosted level name
51+
level = revit.doc.GetElement(dwg.LevelId)
52+
level_name = level.Name if level else "N/A"
53+
54+
# Get offset using the Transform
55+
offset_z = "N/A"
56+
offset_z_m = "N/A"
57+
try:
58+
transform = dwg.GetTransform()
59+
if transform:
60+
offset_z = transform.Origin.Z # in feet
61+
offset_z_m = DB.UnitUtils.ConvertFromInternalUnits(
62+
offset_z, DB.UnitTypeId.Meters
63+
)
64+
except Exception as ex:
65+
mlogger.debug(
66+
"Failed to convert offset Z from internal units: {}".format(ex)
67+
)
68+
69+
print("\n\n")
70+
output.print_md(
71+
"**DWG name:** {}\n\n"
72+
"- DWG created by: {}\n\n"
73+
"- DWG id: {}\n\n"
74+
"- DWG workset: {}\n\n"
75+
"- Hosted level: {}\n\n"
76+
"- Offset from level (Z): {} ft ({} m)\n\n".format(
77+
dwg_name,
78+
dwg_instance_creator,
79+
output.linkify(dwg_id),
80+
dwg_workset,
81+
level_name,
82+
offset_z,
83+
offset_z_m,
84+
)
85+
)
86+
87+
88+
selected_option = forms.CommandSwitchWindow.show(
89+
["In Current View", "In Model"], message="Select search option:"
90+
)
6491

6592
if selected_option:
66-
listdwgs(current_view_only=selected_option == 'In Current View')
93+
listdwgs(current_view_only=selected_option == "In Current View")

0 commit comments

Comments
 (0)