Auto Dimensioning Structural foundations

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]

@Osama.abdelsalam198 whats the point of giving node Dimension.ByReferences all 12 lines? don’t u want to use a subset of the 12 lines only? if Level 2 is a plan view, surely u won’t be able to see those vertical ones. besides, iirc, u want to deal with face references.

it might be a good idea to post another image of ur graph. having a dialog in the middle of the graph, blocking a part of it is…well… and u could format ur code nicely and entirely also.

elem = UnwrapElement(IN[0])

opt = Options()
opt.DetailLevel = ViewDetailLevel.Fine
opt.ComputeReferences = True

faces = []
uv = UV(0.1, 0.1)
for item in elem.get_Geometry(opt):
    if isinstance(item, Solid):
        for face in item.Faces:
            norm = face.ComputeNormal(uv)
            if norm.IsAlmostEqualTo(XYZ.BasisX) or norm.IsAlmostEqualTo(XYZ.BasisX.Negate()):
                faces.append(face)

faces = sorted(faces, key=lambda face: face.Evaluate(uv).X)
     
OUT = [f.Reference for f in faces]

1 Like

i’m just experimenting with references and i was gonna filter edges out later after it works. also i dont want to work with faces because the foundations could have irregular shapes. and after doing some research i found the problem that for instance families like isolated footings i cant get references from instance geometry and instead i have to get them from symbol geometry. anyway thanks for help :slight_smile:

@Osama.abdelsalam198 no worries but later on u might find working with surface reference is inevitable in some cases.