I am trying to create a script that auto-dimensions the structural column’s width and length in the floor plan at a specified distance from the edge of the column and not from the center.
Below is my trial script. I’m not sure what and how to change to get it working or if there is any simpler way.
Column Dimensions.dyn (66.3 KB)
Hi Viraj,
From a quick search, Dimension.ByElements works on a list of elements not a list of references:
There is another node called Dimension.Faces which accepts Surface[] but I could not find a way to make it work.
I think the best way is to just use the Revit api in a python node:
import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView
column = UnwrapElement(IN[0])
# geometry options
opt = Options()
opt.ComputeReferences = True
opt.DetailLevel = ViewDetailLevel.Medium
geom = column.get_Geometry(opt)
faces = []
# find faces
for g in geom:
solid = g if isinstance(g, Solid) else None
if not solid:
continue
for face in solid.Faces:
pf = face if isinstance(face, PlanarFace) else None
if not pf:
continue
n = pf.FaceNormal
faces.append(pf.Reference)
# ensure two faces
if len(faces) < 2:
raise Exception("Not enough faces found")
y_ref_array = ReferenceArray()
y_ref_array.Append(faces[2])
y_ref_array.Append(faces[4])
x_ref_array = ReferenceArray()
x_ref_array.Append(faces[1])
x_ref_array.Append(faces[3])
# get column location
loc = column.Location
pt = loc.Point
offset = 2
internal_value = UnitUtils.ConvertToInternalUnits(
offset,
UnitTypeId.Millimeters
)
# create dimension line Y
y_line = Line.CreateBound(pt.Add(XYZ(-offset, offset, 0)),pt.Add(XYZ(-offset, -offset, 0)))
# create dimension line X
x_line = Line.CreateBound(pt.Add(XYZ(-offset, -offset, 0)),pt.Add(XYZ(+offset, -offset, 0)))
TransactionManager.Instance.EnsureInTransaction(doc)
#detail_line = doc.Create.NewDetailCurve(view, line)
dims = []
y_dim = doc.Create.NewDimension(
view,
y_line,
y_ref_array
)
x_dim = doc.Create.NewDimension(
view,
x_line,
x_ref_array
)
dims.append(y_dim)
dims.append(x_dim)
TransactionManager.Instance.TransactionTaskDone()
OUT = dims
1 Like
Thanks for giving a direction.
Initially, I was getting error with your python script. I modified .get_Geometry(opt) to add a check for GeometryInstance and unpack it using .GetInstanceGeometry().
The script worked. But I am unable to find those dims on view. They can be selected using element id but not visible in project.
1 Like
Hi Viraj,
Sorry the script is very simplified and I have only tested it on the Revit Structural Sample Project.
The issue may be related to the face indexes used:
y_ref_array = ReferenceArray()
y_ref_array.Append(faces[2])
y_ref_array.Append(faces[4])
x_ref_array = ReferenceArray()
x_ref_array.Append(faces[1])
x_ref_array.Append(faces[3])
and if the column is joined with the slab or not (number of faces increases if joined):
If you are still stuck and can share the family I can test it on my end too.
Yes, that would be great. Here is my sample file with the column. I am also attaching the script in case you want to have a look.
I am using the Architecture Template, Revit 2023.
Column dims 10-03.dyn (7.1 KB)
Sample Project.rvt (6.1 MB)
I think the example below may help.
You need to convert the reference into stable representation, combine it with the instance representation string and use the parse from stable to get the correct face reference.
Add the dimensions to the columns and then check with Revit Lookup for their references strings and then try to recreate them in Python.
The instance string in the example below is hard coded so you will need to find a way to extract it programmatically.
x_stableRepr = face.Reference.ConvertToStableRepresentation(doc)
x_ref_array.Append(Reference.ParseFromStableRepresentation(doc,'b4f1dd2d-6004-4419-ad80-c2045970e6a7-0004bff2'+':0:INSTANCE:'+x_stableRepr))
Column dims 10-04.dyn (18.9 KB)
1 Like
Thankyou @Giovanni_Brogiolo. you gave a perfect direction. The “Stable Representation” trick you shared is the correct, advanced workaround.
1 Like