Dimension from Lines

Is there a way to create dimensions from Lines?
If I use the Dimension.ByElements like this:

l1 = Line.ByStartPointEndPoint(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(0, 5, 0));
l2 = Line.ByStartPointEndPoint(Point.ByCoordinates(10, 0, 0), Point.ByCoordinates(10, 5, 0));
ls = {l1, l2};
dimension1 = Dimension.ByElements(view1, ls, null, “”, “”);

I get an error.

Hello @martin_stacey
im find the way to create dimension from one model detail line. May be its will be helpful for you

sources:
http://www.revitapidocs.com/2017.1/47b3977d-da93-e1a4-8bfa-f23a29e5c4c1.htm

solution:


image

code:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
from Revit.Elements import *

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

MY_LINE=Line.ByStartPointEndPoint(Point.ByCoordinates(0, 0, 0),     Point.ByCoordinates(0, 100, 0))
    
line=MY_LINE.ToRevitType(True) 

TransactionManager.Instance.EnsureInTransaction(doc)
detail_curve=doc.Create.NewDetailCurve(doc.ActiveView, line)
line_=UnwrapElement(detail_curve).GeometryCurve
#line_=UnwrapElement(ModelCurve.ByCurve(IN[0])).GeometryCurve  #Create ModelCurve

references = ReferenceArray()
references.Append(UnwrapElement(line_).GetEndPointReference(0))
references.Append(UnwrapElement(line_).GetEndPointReference(1))

dimension = doc.Create.NewDimension(doc.ActiveView, line, references)

TransactionManager.Instance.TransactionTaskDone()

OUT =references, line_ ,dimension

and one more…
how to use Dimension.ByElements node im dont understand :upside_down_face:

Thank you a lot for your quick reply! Ill try to use the code and see if it works for me.

thanks! it works perfectly, I made a change to the code to make it available for list of lines if anyone is interested

import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
from Revit.Elements import *
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

inNode0 = IN [0]
lineList = []
if isinstance(inNode0, list):
lineList.extend(IN[0])
else:
lineList.append(IN[0])
lineList = UnwrapElement(lineList)
lineListRevitType = []

for l in lineList:
lineListRevitType.append(l.ToRevitType(True)) #line se llamaba

TransactionManager.Instance.EnsureInTransaction(doc)

detailCurveList = []
line_List = []
referencesList = []
dimensions = []
for i in range(len(lineList)): #detail_curve
detailCurveList.append(doc.Create.NewDetailCurve(doc.ActiveView, lineListRevitType[i]))
line_List.append(UnwrapElement(detailCurveList[i]).GeometryCurve)
referencesList.append(ReferenceArray())
referencesList[i].Append(UnwrapElement(line_List[i]).GetEndPointReference(0))
referencesList[i].Append(UnwrapElement(line_List[i]).GetEndPointReference(1))
dimensions.append(doc.Create.NewDimension(doc.ActiveView, lineListRevitType[i], referencesList[i]))

TransactionManager.Instance.TransactionTaskDone()

OUT = dimensions

3 Likes

Hi Martin, could you please Edit your post, your code has no indents and this is Python, so Indents change everything. I tried to follow the logic here but Had a couple errors.

Thanks for the code anyways, I was looking for it.

Well after checking this with more caution I have a working version.

Like martin said it works with lists:
It makes a dimension using an existing line(lines) (not detail line), as the reference (references).

I will work on it to try to make it more customizable, i.e adjust grip points and offset from the curve.

note for @til.shviger:
it does not use the Dimension.byElement Node, it uses a list of Lines that can be created using the Line.ByStartPointEndPoint Node. "IT IS IMPORTANT TO HAVE A FLAT LIST"
In a future version, I will try to do It using reference points from Elements instead.

the Working code is:

#Import required lybraries
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
from Revit.Elements import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

#Data Entry
inNode0 = IN [0]
lineList = []
lineListRevitType=[]

#If more tham one element add it to a list
if isinstance(inNode0, list):
	lineList.extend(IN[0])
#if one element make it a 1 elemnt list tor the iterention works	
else:
	lineList.append(IN[0])
	lineList = UnwrapElement(lineList)
	lineListRevitType = []
#Iterate over Lines (list items), make it revit types to be used by the API 
for l in lineList:
	lineListRevitType.append(l.ToRevitType(True)) #line se llamaba
#Start the document transaction
TransactionManager.Instance.EnsureInTransaction(doc)

#Initialize the variables needed
detailCurveList = []
line_List = []
referencesList = []
dimensions = []
u=[]
#Iterate over the lineList(revit elements) to create the dimentions from it's reference points (Start and End points):
for i in range(len(lineList)): #detail_curve
	detailCurveList.append(doc.Create.NewDetailCurve(doc.ActiveView, lineListRevitType[i]))
	line_List.append(UnwrapElement(detailCurveList[i]).GeometryCurve)
	referencesList.append(ReferenceArray())
	referencesList[i].Append(UnwrapElement(line_List[i]).GetEndPointReference(0))
	referencesList[i].Append(UnwrapElement(line_List[i]).GetEndPointReference(1))
	dimensions.append(doc.Create.NewDimension(doc.ActiveView, lineListRevitType[i], referencesList[i]))
	u.append(i)
#Close Document transaction

TransactionManager.Instance.TransactionTaskDone() 

OUT = dimensions

Many thanks to @martin_stacey for this awesome piece of code. It helped me immensely. :wink:
you guys Rock!:love_you_gesture:

1 Like

You are welcome, was about to post the indented file!

Please make corrections to my comments on the code if I got something wrong, Once again really appreciate it!

Capture

can somebody make this so it also accepts lists…

Thanks

You can also Flatten your List.Create node and bring all your lists to a 1 level list like you have on your first example.

@lucaspfmoreira
Is there a way to feed this script a defined view? Since this only uses the active view?

I would ike to use it to generate dimensions for different views.

Yes there is,
you need to store your view into a variable of your choosing, you can do that using some dynamo node or the FilteredElementCollector Class from the Revit API.
https://www.revitapidocs.com/2019/263cf06b-98be-6f91-c4da-fb47d01688f3.htm

after just replace the doc.ActiveView call by your variable name.

You may need to Unwrap your view using the Dynamo Class UnwrapElement()

Good Luck!