hello i’m trying to auto create dimension for structural foundation sides.
i created a python script that retrieves every edge for the structural element and get each edge starting and ending point reference then used genius loki node to create dimensions but for some reason the dimensions are being created in a view that is not available or something went wrong. what is the the problem with the script? anyone can help?
this is the python code
import clr
from Autodesk.DesignScript.Geometry import *
import Autodesk.Revit.DB as DB
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
from System.Collections.Generic import List
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
foundations_input = IN[0]
if not hasattr(foundations_input, '__iter__') or isinstance(foundations_input, str):
foundations_input = [foundations_input]
all_edges = []
all_edge_references = []
errors = []
for foundation in foundations_input:
try:
if hasattr(foundation, "InternalElement"):
element = foundation.InternalElement
else:
element = foundation
opts = Options()
opts.ComputeReferences = True
opts.IncludeNonVisibleObjects = True
geometry = element.get_Geometry(opts)
if geometry is None:
errors.append(f"No geometry found for element {element.Id}")
continue
for geo_obj in geometry:
if isinstance(geo_obj, GeometryInstance):
instance_geo = geo_obj.GetInstanceGeometry()
for obj in instance_geo:
if isinstance(obj, Solid) and obj.Faces.Size > 0:
for edge in obj.Edges:
try:
curve = edge.AsCurve().ToProtoType()
start_ref = edge.GetEndPointReference(0)
end_ref = edge.GetEndPointReference(1)
all_edges.append(curve)
all_edge_references.append([start_ref, end_ref])
except Exception as e:
errors.append(f"Edge processing error: {str(e)}")
elif isinstance(geo_obj, Solid) and geo_obj.Faces.Size > 0:
for edge in geo_obj.Edges:
try:
curve = edge.AsCurve().ToProtoType()
start_ref = edge.GetEndPointReference(0)
end_ref = edge.GetEndPointReference(1) all_edges.append(curve)
all_edge_references.append([start_ref, end_ref])
except Exception as e:
errors.append(f"Edge processing error: {str(e)}")
except Exception as e:
errors.append(f"Foundation processing error: {str(e)}")
OUT = [all_edges, all_edge_references, errors]