The center points of the two circles of the detail line are Dimension Error.

The center points of the two circles of the detail line are Dimension Error.

AD8080202
Advocate Advocate
1,452 Views
11 Replies
Message 1 of 12

The center points of the two circles of the detail line are Dimension Error.

AD8080202
Advocate
Advocate

I want to Dimension the center of the two circles
But it does become an arc edge
How can I correct the code?
I beg you for your help, thank you!

 

20200726-Center.jpg

 

[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]

public Result Execute
(ExternalCommandData commandData, ref string message, ElementSet elements )
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;

Reference ref1 = uidoc.Selection.PickObject(ObjectType.Element, "pick an element Arc A:");
Element elem1 = doc.GetElement(ref1);
Curve elem_Curve1 = (elem1.Location as LocationCurve).Curve;
Arc elem_arc1 = elem_Curve1 as Arc;
XYZ elem_pt_1 = elem_arc1.Center;


Reference ref2 = uidoc.Selection.PickObject(ObjectType.Element, "pick an element Arc B:");
Element elem2 = doc.GetElement(ref2);
Curve elem_Curve2 = (elem2.Location as LocationCurve).Curve;
Arc elem_arc2 = elem_Curve2 as Arc;
XYZ elem_pt_2 = elem_arc2.Center;

using (Transaction trans = new Transaction(doc, ""))
{
trans.Start();

Line line = Line.CreateBound(elem_pt_1, elem_pt_2);
ReferenceArray refArray = new ReferenceArray();
refArray.Append(ref1);
refArray.Append(ref2);
doc.Create.NewDimension(doc.ActiveView, line, refArray);

trans.Commit();
}
}

 

 

 

 

0 Likes
Accepted solutions (1)
1,453 Views
11 Replies
Replies (11)
Message 2 of 12

jeremytammik
Autodesk
Autodesk

The references provided to the NewDimension method specify what you will dimension.

 

You are passing in the references to the circle elements themselves, not to the circle centre points.

  

From a circle, you can retrieve a reference to its centre point by calling the Geometry property on it and specifying ComputeReferences == true in the Options passed in:

  

https://www.revitapidocs.com/2020/d8a55a5b-2a69-d5ab-3e1f-6cf1ee43c8ec.htm

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 12

Revitalizer
Advisor
Advisor

Hi,

 

there is a CenterPointReference property for all Elements derived from CurveElement.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 12

jeremytammik
Autodesk
Autodesk

Thank you Rudi for the great hint!

 

https://www.revitapidocs.com/2020/8e17164e-f2d0-828d-8fe2-9720fec91303.htm

 

Centerpoint reference of curve element. Curves such as circles, arcs, ellipses, and partial ellipses support this property.
 


Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 12

AD8080202
Advocate
Advocate

Thanks "Revitalizer" and "jeremytammik" for reply
But I tested after correction.
same not working.

 

AD8080202_0-1595838837101.png

 

[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]

public Result Execute
(ExternalCommandData commandData, ref string message, ElementSet elements )
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;

Options _opt = null;
_opt = new Options();
_opt.ComputeReferences = true;
_opt.IncludeNonVisibleObjects = true;

Reference ref1 = uidoc.Selection.PickObject(ObjectType.Element, "pick an element Arc A:");
Element elem1 = doc.GetElement(ref1);
Curve elem_Curve1 = (elem1.Location as LocationCurve).Curve;
Arc elem_arc1 = elem_Curve1 as Arc;
XYZ elem_pt_1 = elem_arc1.Center;

DetailArc detailCurve1 = doc.GetElement(ref1) as DetailArc;
Reference reference_1 = detailCurve1.CenterPointReference;


Reference ref2 = uidoc.Selection.PickObject(ObjectType.Element, "pick an element Arc B:");
Element elem2 = doc.GetElement(ref2);
Curve elem_Curve2 = (elem2.Location as LocationCurve).Curve;
Arc elem_arc2 = elem_Curve2 as Arc;
XYZ elem_pt_2 = elem_arc2.Center;

DetailArc detailCurve2 = doc.GetElement(ref2) as DetailArc;
Reference reference_2 = detailCurve2.CenterPointReference;

using (Transaction trans = new Transaction(doc, ""))
{
trans.Start();

Line line = Line.CreateBound(elem_pt_1, elem_pt_2);
ReferenceArray refArray = new ReferenceArray();
refArray.Append(reference_1);
refArray.Append(reference_2);
doc.Create.NewDimension(doc.ActiveView, line, refArray);

trans.Commit();
}
}

 

 

0 Likes
Message 6 of 12

AD8080202
Advocate
Advocate

How can I correct the code?
I beg you for your help.

Thank you!

0 Likes
Message 7 of 12

jeremytammik
Autodesk
Autodesk

Try to dimension the circles manually in the user interface. 

 

Does that work?

 

Analyse the result using RevitLookup.

 

Compare it with the data you are feeding into NewDimension.

 

Maybe the line that you supply is incorrect.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 12

AD8080202
Advocate
Advocate

Manually dimension is OK.
Use "RevitLookup" to check that the reference is "DetailArc".
Attachment of results.

Excuse me:
Q1. How can I confirm that "Reference" is Append to "ReferenceArray"?
Q2. What is the composition condition of "ReferenceArray"?

Thanks

 

 

Q200727.jpg

 

 

0 Likes
Message 9 of 12

jeremytammik
Autodesk
Autodesk

Interesting. 

 

I can confirm what you say. Even worse, I get an exception with the error message 'invalid number of references' for both model and detail circles.

 

Here is the code that I use for them both:

 

    class ArcSelectionFilter : ISelectionFilter
    {
      public bool AllowElement( Element e )
      {
        return e is DetailArc || e is ModelArc;
      }

      public bool AllowReference( Reference r, XYZ p )
      {
        return true;
      }
    }

    public Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements )
    {
      UIApplication uiapp = commandData.Application;
      UIDocument uidoc = uiapp.ActiveUIDocument;
      Application app = uiapp.Application;
      Document doc = uidoc.Document;

      Reference ref1 = uidoc.Selection.PickObject( 
        ObjectType.Element, new ArcSelectionFilter(), 
        "Please pick arc curve element A:" );

      CurveElement ce1 = doc.GetElement( ref1 ) as CurveElement;

      Reference cpr1 = ce1.CenterPointReference;
      XYZ p1 = ((ce1.Location as LocationCurve).Curve as Arc) .Center;

      Reference ref2 = uidoc.Selection.PickObject(
        ObjectType.Element, new ArcSelectionFilter(),
        "Please pick arc curve element B:" );

      CurveElement ce2 = doc.GetElement( ref2 ) as CurveElement;

      Reference cpr2 = ce2.CenterPointReference;
      XYZ p2 = ((ce2.Location as LocationCurve).Curve as Arc).Center;

      using( Transaction t = new Transaction( doc ) )
      {
        t.Start( "Dimension Circle Centres" );

        Line line = Line.CreateBound( p1, p2 );
        ReferenceArray refArray = new ReferenceArray();
        refArray.Append( cpr1 );
        refArray.Append( cpr2 );
        doc.Create.NewDimension( doc.ActiveView, line, refArray );

        t.Commit();
      }
      return Result.Succeeded;
    }
  }

 

I appended the entire Visual Studio solution including source code and add-in manifest, and also your sample model updated for Revit 2021.

 

Looking at the references fed into the reference array, I see that the element id is given, but the global point is null. 

 

I would have expected the global point to be equal to the circle centre point, not null.

 

I'll ask the development team what we are doing wrong.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 10 of 12

jeremytammik
Autodesk
Autodesk

To answer your two questions:

 

Q1. How can I confirm that "Reference" is Append to "ReferenceArray"?

 

Look at it in the debugger. I can see that the element count is 2, as expected.

 
Q2. What is the composition condition of "ReferenceArray"?

 

I would assume that two references are expected.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 11 of 12

jeremytammik
Autodesk
Autodesk
Accepted solution

I logged the issue REVIT-165556 [Cannot dimension circle centre point using CenterPointReference] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 12 of 12

jeremytammik
Autodesk
Autodesk

Thank you for your patience and sorry this is taking a while.

 

It will take quite a while longer, in fact...

 

The development team analysed the issue REVIT-165556 [Cannot dimension circle centre point using CenterPointReference] that I logged for this on your behalf and confirmed the problem.

 

In fact, they closed that issue with the resolution 'code fix required' and created a new one to apply the code fix in a future release of Revit: REVIT-165922 [API: Cannot dimension circle centre point using CenterPointReference]. Please make a note of the new ticket number as well.

 

You are welcome to request an update on the status of this issue as well and to provide additional information on it at any time quoting this change request number.

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder