Getting the CenterPointReference of an Arc to create Dimensions

Hello friends!

This is my first post here cause i just havent been able to solve this one on my own.

  1. THE GOAL: So, I’m trying to create a script that creates a dimension that looks like point 1: Dimension end points of line and centers of circles/arcs

  2. WHERE I’M AT: I’m currently getting only the dimension of the endpoints of the line. I don’t know where the problem was in my code. To get the centerpoints of the arcs im using the CenterPointReference property of the DetailLine Class. The script doesn’t return an error, but it ignores these references!

Any help is appreciated, thanks.
Paolo

Below is my code.

import clr

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

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

# Input
detailLine = UnwrapElement(IN[0])
detailArcs = UnwrapElement(IN[1])

# Create the reference array
refArr = ReferenceArray()

# Add the line end point references
curve = detailLine.GeometryCurve
ref1 = curve.GetEndPointReference(0)
refArr.Append(ref1)
ref2 = curve.GetEndPointReference(1)
refArr.Append(ref2)

# Add the arc center point references
for arc in detailArcs:
	ref = arc.CenterPointReference
	refArr.Append(ref)

# Create dimension
TransactionManager.Instance.EnsureInTransaction(doc)
dimension = doc.Create.NewDimension(doc.ActiveView, curve, refArr)
TransactionManager.Instance.TransactionTaskDone()

OUT = dimension

I edited your script and it worked a bit but it takes end of the arcs :S maybe you can solve it to take the centers :slight_smile:

import clr

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

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

# Input
detailLine = UnwrapElement(IN[0])
detailArcs = UnwrapElement(IN[1])

if not hasattr(detailArcs, '__iter__'):
	detailArcs = [detailArcs]

ref=[]

for element in detailArcs:
	ref.append(Reference(element))
# Create the reference array
refArr = ReferenceArray()

# Add the line end point references
curve = detailLine.GeometryCurve
ref1 = curve.GetEndPointReference(0)
refArr.Append(ref1)
ref2 = curve.GetEndPointReference(1)
refArr.Append(ref2)

# Add the arc center point references
for i in ref:
	i.GlobalPoint
	refArr.Append(i)
# Create dimension
TransactionManager.Instance.EnsureInTransaction(doc)
dimension = doc.Create.NewDimension(doc.ActiveView, curve, refArr)
TransactionManager.Instance.TransactionTaskDone()

OUT = dimension

1 Like

Thanks for your effort Deniz.
I’ll try to find a solution to get the center points.
A workaround i’m thinking of is creating small detail lines and getting their endpoint reference to create a reference from that :pensive:

Cheers.
Paolo

Quick follow up for anyone interested… it seems as though this method is not working correctly. I reproduced the script in C# and got the same result: The referencearray supposedly gets populated but the dimension line can´t be formed.
Here´s part of the code if anyone wants to dig into it and find out what the problem is:

using (Transaction t = new Transaction(doc))
                {
                    // Create circle for dimensioning
                    List<DetailCurve> detailCurves = new List<DetailCurve>();
                    t.Start("Create Detail Lines");
                    foreach (XYZ point in finalCenterPoints)
                    {
                        Arc arc = Arc.Create(point, 0.02, 0, 7,
                            doc.ActiveView.UpDirection,
                            doc.ActiveView.RightDirection);
                        
                        DetailCurve detailCurve = doc.Create.NewDetailCurve(doc.ActiveView, arc);
                        detailCurves.Add(detailCurve);
                    }
                    t.Commit();

                    // Add the CenterPointreferences to referenceArray
                    foreach (DetailCurve detCurve in detailCurves)
                    {
                        Reference reference = detCurve.CenterPointReference;
                        referenceArray.Append(reference);
                    }


                    // Create Dimension
                    if (t.GetStatus() == TransactionStatus.Committed)
                    {
                        t.Start("Gaptek - Dimension Arc Centers");
                        //Dimension dimension = doc.Create.NewDimension(doc.ActiveView, offsettedLine, referenceArray);
                        t.Commit();
                    }

                };

hi,
I’ve done a test and the functions seems to be working for me.
Although I have created all the lines manually not through the script. Maybe that is a difference? or Revit version perhaps…

the code I used:

import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument

#The inputs to this node will be stored as a list in the IN variables.
elements = UnwrapElement(IN[0])
line = UnwrapElement(IN[1])

refArray = ReferenceArray()

for e in elements:
	#refArray.Append(e.CenterPointReference)
	#output.append(e.CenterPointReference)
	center_ref = e.CenterPointReference
	if not center_ref is None:
		refArray.Append(center_ref)
	else:
		r0 = e.GeometryCurve.GetEndPointReference(0)
		r1 = e.GeometryCurve.GetEndPointReference(1)
		refArray.Append(r0)
		refArray.Append(r1)
	
TransactionManager.Instance.EnsureInTransaction(doc)

l = line.GeometryCurve	
d = doc.Create.NewDimension(doc.ActiveView, l, refArray)
	
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = d

On Revit 2019.2 it does not work.

Which version do you use?

You are right…I have tested now on 2019.2 and it does not work…
So at least we know it is an api bug/change…I have tried before on a really old version (2014-sic).

I wonder if it is working on 2020, but I have not installed it yet…

2 Likes

Thanks for your time Maciek. Glad to know I was not missing any steps :sweat_smile:

1 Like