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.
you guys Rock!