Hi,
I need a little help with the dimensioning script I am working on. I am trying to dimension between multiple equipment either Electrical or Mechanical (if both work together… even better). This is my script so far:
This script is working well but only with walls:
When I switch the element to Mechanical equipment, Electrical Equipment, Door, Windows or etc. it doesn’t work and gives me these errors:
I would appreciate if anyone can help me with this, any modifications or alternatives to this script are appreciated.
Thank You in advance!
Hi @alyaan_h a windows location is a point itself, so you cant get curve point at parameter from that…you can try genius loci reference/ dimension nodes as well and see if it better
Hi @sovitek, thank you for your response. Is this what you mean? Getting a null error.
By the way for this script, I’m mainly aiming to dimension between electrical and mechanical equipment. I was just testing walls and they seemed to work but the other components weren’t working.
i would try with genius loci family reference / dimension nodes, for electrical, mechanical, windows etc…you can get the package from package manager
I am using the genius loci package, the logo doesn’t show up on the nodes for some reason.
Made some progress, now the script is at least picking up the mechanical equipment. It makes a line but no dimension yet.
yeas looks right, but for reference try geninus loci, family_origin_reference, or just family reference…depend how these families is build and which refrence they have…try here with origin
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
items = UnwrapElement(IN[0]) if isinstance(IN[0],list) else [UnwrapElement(IN[0])]
locationPoint,locRef = [],[]
refArr = ReferenceArray()
for item in items:
doc = item.Document
if isinstance(item, FamilyInstance):
refArr.Append(Reference.ParseFromStableRepresentation(doc, item.UniqueId + ":0:INSTANCE:" + item.Symbol.UniqueId + ":1:SURFACE"))
location = item.Location
if isinstance(location,LocationPoint):
locationPoint.append(location.Point.ToPoint())
else:
locationPoint.append(None)
else : refArr.Append(None), locationPoint.append(None)
if isinstance(IN[0], list): OUT = refArr,locationPoint
else: OUT = refArr[0],locationPoint[0]
@sovitek Thanks.
I’m not gonna lie with you but I have no clue where to plug in this python code. I’m going to need a visual of the workspace to understand this
. I’m still a beginner with dynamo and haven’t really played around with the python stuff.
Edit: I see the visual now. Let me try it. Thanks!
no worries i have shared an example in my post above with origin reference
So, this is what I’m getting by following your script. Basically, the same thing as before where I get the line but not the dimension itself.
can you share the family ?
be sure you have ironpython 2.7 version 2.5 or pythonnet 3 version 1.1.1 ipackage installed as well
yeah if you mean top right, for dimension i use pythonnet 3 engine but guess genius locis works both for ironpython 2.7 ver 2.5 and pythonnet 3 as i prefer, but not 100 % with pythonnet 3 but try…and can be downloaded via package manager
here for pythonnet 3 1.1.1 if that the case
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
views = tolist(UnwrapElement(IN[0]))
lines = tolist(IN[1])
if any(isinstance(el, list) for el in IN[2]) : referenceList = IN[2]
else : referenceList = [(IN[2])]
dimensionType = tolist(UnwrapElement(IN[3]))[0]
listRef,dimList = [], []
for references in referenceList :
elementsRef = ReferenceArray()
for reference in references :
elementsRef.Append(reference)
listRef.append(elementsRef)
TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:
dims = []
for line,refer in zip(lines,listRef) :
if doc.IsFamilyDocument == True :
if IN[3]== None:
dims.append(doc.FamilyCreate.NewDimension(view, line.ToRevitType(), refer).ToDSType(True))
else:
dims.append(doc.FamilyCreate.NewDimension(view, line.ToRevitType(), refer, dimensionType).ToDSType(True))
else:
if IN[3]== None:
dims.append(doc.Create.NewDimension(view, line.ToRevitType(), refer).ToDSType(True))
else:
dims.append(doc.Create.NewDimension(view, line.ToRevitType(), refer, dimensionType).ToDSType(True))
dimList.append(dims)
TransactionManager.Instance.TransactionTaskDone()
if isinstance(IN[0], list): OUT = dimList
else: OUT = dimList[0]
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
views = tolist(UnwrapElement(IN[0]))
lines = tolist(IN[1])
if any(isinstance(el, list) for el in IN[2]) : referenceList = IN[2]
else : referenceList = [(IN[2])]
dimensionType = tolist(UnwrapElement(IN[3]))[0]
listRef,dimList = [], []
for references in referenceList :
elementsRef = ReferenceArray()
for reference in references :
elementsRef.Append(reference)
listRef.append(elementsRef)
TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:
dims = []
for line,refer in zip(lines,listRef) :
if doc.IsFamilyDocument == True :
if IN[3]== None:
dims.append(doc.FamilyCreate.NewDimension(view, line.ToRevitType(), refer).ToDSType(True))
else:
dims.append(doc.FamilyCreate.NewDimension(view, line.ToRevitType(), refer, dimensionType).ToDSType(True))
else:
if IN[3]== None:
dims.append(doc.Create.NewDimension(view, line.ToRevitType(), refer).ToDSType(True))
else:
dims.append(doc.Create.NewDimension(view, line.ToRevitType(), refer, dimensionType).ToDSType(True))
dimList.append(dims)
TransactionManager.Instance.TransactionTaskDone()
if isinstance(IN[0], list): OUT = dimList
else: OUT = dimList[0]
Hey @sovitek,
Thanks for the details and the explanation. I’ve done some testing with this and I found a few “glitches”:
- For both horizontal and vertical dimensions it is duplicating the dimension in place.
- For the vertical dimension the dimension is frozen in place so I can’t adjust it to the desired position. When you try to move it a zero is added. I’m not sure why that’s happening.
I’ve tried fixing the issues thinking it’s the dimension type I’m using but I don’t think that’s the case.
yeah probably right, try here, try use the family ref instead origin seems more stable

dim.dyn (23.2 KB)
@sovitek
The script worked! Thank you again for all your help with it, I really appreciate you taking the time to help me figure it out.
Question for you outside of this script: How would you recommend getting better at writing Python code for Dynamo? From what I’ve seen so far, it seems like once you start getting into more complex Dynamo scripts, Python becomes really useful, and sometimes almost necessary.
I really want to improve my Dynamo skills and eventually get to the point where I can build more advanced scripts and tools myself. I was honestly really impressed by how quickly you were able to write those longer Python scripts and work through the problems.
Do you have any advice on how you learned or what you think would be the best way for me to improve? Whether it’s certain resources, practicing specific types of scripts, or just learning more Python in general, I’d really appreciate any recommendations.
And again, thank you for all the help with the script!
yeah sure python is awesome sure, but many ways, try go to primer there is some examples for python…but i just start with open other scripts, clockwork, genius loci etc. and analyze how they have done it…take a look at @GavinNicholls python videos on YT is great as well…and then follow in here in the forum…for me have follow @c.poupin and @Mike.Buttery etc…been great inspiration as well…good luck…