Skip to content

Commit 0fe8fca

Browse files
committed
Update
1 parent ea8650a commit 0fe8fca

2 files changed

Lines changed: 1 addition & 147 deletions

File tree

RevitAPI.extension/PapeEnginner.tab/Link.panel/Reload Link.pushbutton/bundle.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: Find Element by ID
1+
title: Reload Links
22

33
tooltip: >-
44
Show Data of Selected Elements.

RevitAPI.extension/PapeEnginner.tab/Link.panel/Reload Link.pushbutton/script.py

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -54,157 +54,11 @@
5454
"""----------------------FUNCTION----------------------------"""
5555

5656

57-
def FilterElementExistant(document, lstEleId):
58-
"""Filter List Element Existent or List Element non-Existent"""
59-
lstEle = []
60-
lstNoEle = []
61-
62-
for id in lstEleId:
63-
64-
ele = document.GetElement(id)
65-
if ele:
66-
lstEle.append(ele)
67-
else:
68-
lstNoEle.append(id)
69-
70-
lstName = [e.Name for e in lstEle]
71-
72-
return lstEle, lstNoEle, lstName
73-
74-
75-
def ZoomAllElement(document, lstEleId, linkSelected):
76-
"""Zoom all Element. I will not use it for now"""
77-
78-
validElements = []
79-
for elemId in lstEleId:
80-
elem = document.GetElement(elemId) # document here could be "doc" or "doclink"
81-
if elem and hasattr(elem, "get_BoundingBox") and elem.get_BoundingBox(None):
82-
validElements.append(elem)
83-
84-
if not validElements:
85-
ShowNotification("Warning", "No valid elements found with BoundingBox.")
86-
87-
# Gộp BoundingBox
88-
firstBox = validElements[0].get_BoundingBox(None)
89-
bboxMin = firstBox.Min
90-
bboxMax = firstBox.Max
91-
92-
for elem in validElements[1:]:
93-
bbox = elem.get_BoundingBox(None)
94-
if bbox:
95-
bboxMin = XYZ(
96-
min(bboxMin.X, bbox.Min.X),
97-
min(bboxMin.Y, bbox.Min.Y),
98-
min(bboxMin.Z, bbox.Min.Z),
99-
)
100-
bboxMax = XYZ(
101-
max(bboxMax.X, bbox.Max.X),
102-
max(bboxMax.Y, bbox.Max.Y),
103-
max(bboxMax.Z, bbox.Max.Z),
104-
)
105-
106-
if not bboxMin or not bboxMax:
107-
ShowNotification("Warning", "No valid BoundingBox found for selected elements.")
108-
109-
transform = linkSelected.GetTotalTransform()
110-
try:
111-
globalPoint1 = transform.OfPoint(bboxMin)
112-
globalPoint2 = transform.OfPoint(bboxMax)
113-
114-
# Sử dụng hàm isFinite để kiểm tra tính hợp lệ
115-
if not (isFinite(globalPoint1.X) and isFinite(globalPoint1.Y) and isFinite(
116-
globalPoint1.Z) and
117-
isFinite(globalPoint2.X) and isFinite(globalPoint2.Y) and isFinite(globalPoint2.Z)):
118-
raise ValueError("Invalid BoundingBox values detected.")
119-
120-
uiview.ZoomAndCenterRectangle(globalPoint1, globalPoint2)
121-
except Exception as ex:
122-
ShowNotification("Error", "Zoom failed due to invalid BoundingBox: {}".format(ex))
123-
124-
125-
# Define utility function
126-
def isFinite(value):
127-
"""Kiểm tra xem giá trị có phải là số hợp lệ (finite) hay không."""
128-
if value is None:
129-
return False
130-
if isinstance(value, (float, int)):
131-
return not (math.isnan(value) or math.isinf(value))
132-
return False
133-
13457

13558
"""----------------------MAIN CODE----------------------------"""
13659

13760
try:
13861

139-
collectModelLink = FilteredElementCollector(doc).OfClass(RevitLinkInstance).ToElements()
140-
141-
# Get linked model elements and their names
142-
modelLink = [link for link in collectModelLink]
143-
nameModelLink = [link.Name for link in modelLink] if modelLink else ["There is no Link Model"]
144-
145-
"""------------RUN FORM----------"""
146-
openForm = True
147-
while openForm:
148-
f = MainForm(nameModelLink)
149-
f.ShowDialog()
150-
151-
# User cancel
152-
if f.DialogResult != System.Windows.Forms.DialogResult.OK:
153-
break
154-
155-
elif f.DialogResult == System.Windows.Forms.DialogResult.OK:
156-
157-
radioLinkModel = f._linkBtn.Checked
158-
radioInModel = f._modelBtn.Checked
159-
160-
lstId = f._textBox1.Text.strip().split(",")
161-
lstId = list(set(lstId))
162-
163-
lstEleId = [ElementId(int(id.strip())) for id in lstId]
164-
lstEle = [doc.GetElement(id) for id in lstEleId]
165-
lstICollection = List[ElementId](lstEleId)
166-
167-
linkModel = f._comboBox1.Text
168-
169-
if radioInModel:
170-
lstEle, lstNoEle, lstName = FilterElementExistant(doc, lstEleId)
171-
172-
if not lstEle:
173-
ShowNotification("Warning", "No elements found with the given IDs.")
174-
continue
175-
176-
177-
else:
178-
ShowDataForm(doc, lstEleId)
179-
selection.SetElementIds(lstICollection)
180-
openForm = False
181-
182-
183-
184-
elif radioLinkModel:
185-
186-
if linkModel == "There is no Link Model":
187-
ShowNotification("Warning", "There is no Link Model, please select a valid option.")
188-
continue
189-
else:
190-
# Tìm liên kết được chọn
191-
linkSelected = next((link for link in modelLink if link.Name == linkModel), None)
192-
193-
# Lấy Document của file liên kết
194-
docLink = linkSelected.GetLinkDocument()
195-
196-
lstEle, lstNoEle, lstName = FilterElementExistant(docLink, lstEleId)
197-
198-
# Hiển thị thông báo nếu không tìm thấy phần tử nào
199-
if not lstEle:
200-
ShowNotification("Warning", "No elements found with the given IDs.")
201-
continue
202-
203-
204-
else:
205-
ShowDataForm(docLink, lstEleId)
206-
openForm = False
207-
20862

20963

21064
# Handle the case when the user cancels the operation

0 commit comments

Comments
 (0)