Skip to content

Commit 1218739

Browse files
committed
added hosted level and z-offset from hosted level
1 parent 684966d commit 1218739

File tree

1 file changed

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

1 file changed

+56
-32
lines changed
Lines changed: 56 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
@@ -12,16 +11,21 @@
1211

1312

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

2021
dwgInst = defaultdict(list)
2122

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

2630
for dwg in dwgs:
2731
if dwg.IsLinked:
@@ -33,34 +37,54 @@ def listdwgs(current_view_only=False):
3337
output.print_md("####{}".format(link_mode))
3438
for dwg in dwgInst[link_mode]:
3539
dwg_id = dwg.Id
36-
dwg_name = \
37-
dwg.Parameter[DB.BuiltInParameter.IMPORT_SYMBOL_NAME].AsString()
40+
dwg_name = dwg.Parameter[DB.BuiltInParameter.IMPORT_SYMBOL_NAME].AsString()
3841
dwg_workset = revit.query.get_element_workset(dwg).Name
39-
dwg_instance_creator = \
40-
DB.WorksharingUtils.GetWorksharingTooltipInfo(revit.doc,
41-
dwg.Id).Creator
42+
dwg_instance_creator = DB.WorksharingUtils.GetWorksharingTooltipInfo(
43+
revit.doc, dwg.Id
44+
).Creator
4245

43-
if current_view_only \
44-
and revit.active_view.Id != dwg.OwnerViewId:
46+
if current_view_only and revit.active_view.Id != dwg.OwnerViewId:
4547
continue
4648

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-
)
49+
# Get hosted level name
50+
level = revit.doc.GetElement(dwg.LevelId)
51+
level_name = level.Name if level else "N/A"
52+
53+
# Get offset using the Transform
54+
offset_z = "N/A"
55+
offset_z_m = "N/A"
56+
try:
57+
transform = dwg.GetTransform()
58+
if transform:
59+
offset_z = transform.Origin.Z # in feet
60+
offset_z_m = round(
61+
offset_z * 0.3048, 3
62+
) # convert to meters, round for readability
63+
except:
64+
pass
65+
66+
print("\n\n")
67+
output.print_md(
68+
"**DWG name:** {}\n\n"
69+
"- DWG created by: {}\n\n"
70+
"- DWG id: {}\n\n"
71+
"- DWG workset: {}\n\n"
72+
"- Hosted level: {}\n\n"
73+
"- Offset from level (Z): {} ft ({} m)\n\n".format(
74+
dwg_name,
75+
dwg_instance_creator,
76+
output.linkify(dwg_id),
77+
dwg_workset,
78+
level_name,
79+
offset_z,
80+
offset_z_m,
81+
)
82+
)
83+
84+
85+
selected_option = forms.CommandSwitchWindow.show(
86+
["In Current View", "In Model"], message="Select search option:"
87+
)
6488

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

0 commit comments

Comments
 (0)