Hey guys, I came into a problem. I have this graph in which I am trying to make a dimension line between two references, which came out of the faces of a column. One of the nodes extracts the reference, and the other gets them and a detail line and is supposed to make the dimension line. For some reason, the dimension line is output, but I canโt see it in the floor plan. If someone cares to take a quick look, it would be much appreciated.
Here is the first one that extracts the references:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.GeometryReferences)
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Inputs from Dynamo
column = UnwrapElement(IN[0]) # Column as FamilyInstance
detail_curve = UnwrapElement(IN[1]) # ModelCurve or Line
# Ensure input is a FamilyInstance (column from a Family)
if not isinstance(column, FamilyInstance):
OUT = "Error: The input element is not a FamilyInstance", None
else:
# Set geometry options
options = Options()
options.ComputeReferences = True
options.IncludeNonVisibleObjects = True
geo = column.get_Geometry(options)
# Collect all solids from the column geometry
solids = []
for g in geo:
if isinstance(g, Solid)and g.Volume > 0:
solids.append(g)
elif isinstance(g, GeometryInstance):
inst_geo = g.GetInstanceGeometry()
for sg in inst_geo:
if isinstance(sg, Solid)and sg.Volume > 0:
solids.append(sg)
if len(solids) == 0:
OUT = "No solid found in column geometry", None
else:
# Prepare list to collect references of faces that have intersections
intersected_references = []
intersected_faces = []
for solid in solids:
for face in solid.Faces:
out_InterResultArray = IntersectionResultArray()
set_ComparisonResult, out_InterResultArray = face.Intersect(detail_curve.GeometryCurve, out_InterResultArray)
if set_ComparisonResult != SetComparisonResult.Disjoint:
intersected_references.append(face.Reference)
intersected_faces.append(face)
# Add only the Reference of the face
# Return list of face references (can be empty)
OUT = intersected_references
And the second one, how should create a dimension line
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
clr.AddReference('RevitNodes')
clr.AddReference('RevitServices')
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import traceback
doc = DocumentManager.Instance.CurrentDBDocument
# ืงืืืช ืืงืื ื-Dynamo
face_references = IN[0] # ืจืฉืืื ืฉื ืฉืชื ืืคื ืืืช ืืคื ืื
line = UnwrapElement(IN[1]) # ืงื ืคืจืืื ืืืืืจืช ืืืงืื ืงื ืืืืืืช
def create_dimension_between_faces(face_refs, line):
"""
ืืฆืืจืช ืืืืืช ืืื ืฉืชื ืคื ืื
"""
try:
# ืืืืงืช ืชืงืื ืืช ืืงืื
OUT = "Checking input validity..." # ืืืืงืช ืชืงืื ืืช ืืงืื
if not face_refs or len(face_refs) != 2:
raise ValueError("ืืืื ืืืืืช ืืืืืง ืฉืชื ืืคื ืืืช ืืคื ืื")
if not line:
raise ValueError("ืืืื ืืกืคืง ืงื ืคืจืืื")
# ืงืืืช ืืืกืื ืืืชืฆืืื ืืคืขืืื
print("Getting active document and view...") # ืงืืืช ืืืกืื ืืืชืฆืืื
# ืงืืืช ืืืืืืืืจืื ืฉื ืืงื
#print("Extracting line geometry...") # ืืืืืฅ ืืืืืืืจืืืช ืืงื
line_curve = line.GeometryCurve
# ืืฆืืจืช ReferenceArray ืืืืคื ืืืช ืืคื ืื
#print("Creating reference array...") # ืืฆืืจืช ืืขืจื ืืคื ืืืช
ref_array = ReferenceArray()
for face_ref in face_refs:
ref_array.Append(face_ref)
# ืืชืืืช ืืจื ืืงืฆืื
#print("Starting transaction...") # ืืชืืืช ืืจื ืืงืฆืื
TransactionManager.Instance.EnsureInTransaction(doc)
# ืืฆืืจืช ืืืืืืช
#print("Creating dimension...") # ืืฆืืจืช ืืืืืืช
dimension = doc.Create.NewDimension(doc.ActiveView, line_curve, ref_array)
# ืกืืื ืืืจื ืืงืฆืื
#print("Committing transaction...") # ืกืืื ืืืจื ืืงืฆืื
TransactionManager.Instance.TransactionTaskDone()
#print("Dimension created successfully!") # ืืืืืืช ื ืืฆืจื ืืืฆืืื
return dimension
except Exception as e:
error_msg = "ืฉืืืื ืืืฆืืจืช ืืืืืืช: " + str(e)
print(error_msg)
print(traceback.format_exc())
return None
# ืืจืฆืช ืืคืื ืงืฆืื
#"Starting dimension creation process..." # ืืชืืืช ืชืืืื ืืฆืืจืช ืืืืืืช
result = create_dimension_between_faces(face_references, line)
# ืืืืจืช ืืชืืฆืื ื-Dynamo
OUT = result
