Draw the dimension for duct

Draw the dimension for duct

ttnhan1
Contributor Contributor
1,052 Views
3 Replies
Message 1 of 4

Draw the dimension for duct

ttnhan1
Contributor
Contributor

 

Line line = Line.CreateBound(topleft, botleft);
DetailLine detailLine = doc.Create.NewDetailCurve(doc.ActiveView, line) as DetailLine;
Reference ref = new Reference(detailLine);
arrRef.Append(ref);

 

I am making an API to draw the dimensions for elements automatically. I have some issue with the duct's dimension.

I created the dimension with this method:

 

doc.Create.NewDimension(doc.ActiveView, dimensionLine, refArr);

 

and I prepared the referenceArray with the duct by creating a new reference from the duct

 

Reference ductRef = new Reference(duct);
refArr.Append(ductRef);

 

 

This's what I got: 

Screenshot 2024-03-01 110812.png

The witness line of the dimension refers to the center of the duct. But I want to create the dimension like this: 

Screenshot 2024-03-01 111341.png

I want the witness line to refer to two sides of the duct. Is there a way to do that?

 

I researched, and there is a suggestion about creating a line that is parallel with the duct sides and getting references from that line.

Line line = Line.CreateBound(topleft, botleft);
DetailLine detailLine = doc.Create.NewDetailCurve(doc.ActiveView, line) as DetailLine;
Reference ref = new Reference(detailLine);
arrRef.Append(ref);

 However, I don't really want to create another line to the model like this. Is there a way to get the reference directly from two sides of the duct?

0 Likes
Accepted solutions (2)
1,053 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni
Accepted solution

Have you explored all the possible references provided by the duct? I don't know whether RevitLookup provides access to them all, but it is worth a try, at least. My last foray into dimensioning was for arcs and yielded this result:

  

  

So, lots of room for experimentation.

 

I understand that you wish to avoid creating extra elements.

 

If worst came to worst, you could do the following:

  

  • Determine the points for the dimension
  • Create a line segment between them
  • Dimension the line segment
  • Delete the line segment

  

All of the above could be wrapped into a DMU dynamic model updater that reacts to geometry changes of the duct, similar to the DynamicModelUpdate Revit SDK sample.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

ttnhan1
Contributor
Contributor
Accepted solution

Hi @jeremy_tammik,

Thank you for your suggestion!
I discovered that we could use RevitLookup to access the duct's edge, so I found a way to do that by code.

I followed this to access the edges. https://www.revitapidocs.com/2020.1/7f25fe6f-a427-7ac3-6753-2dec37fb058c.htm

This is my code:

 

 

BoundingBoxXYZ ductBB = duct.get_BoundingBox(doc.ActiveView);

// Get geometry element of the selected element
Autodesk.Revit.DB.Options geoOptions = app.Create.NewGeometryOptions();
geoOptions.ComputeReferences = true;
Autodesk.Revit.DB.GeometryElement geoElement = duct.get_Geometry(geoOptions);
FaceArray faces = ((Solid)geoElement.First()).Faces;

foreach (PlanarFace face in faces)
{
    XYZ origin = face.Origin;

    if (Math.Round(origin.Z,8)  == Math.Round(ductBB.Max.Z, 8))
    {
        foreach (Edge edge in face.EdgeLoops.get_Item(0))
        {
           //get the reference by edge.GetEndPointReference(0))
        }
        break;
    }
}

 

 


This is the result

Screenshot 2024-03-04 155609.png

 

The important thing in this is the geometry option. We should set it like this:

 

 

geoOptions.ComputeReferences = true;

 

 


to get the reference for dimension. (https://adndevblog.typepad.com/aec/2013/06/facesedges-returned-from-elementgeometry-have-no-referenc...)

Thank you for being so helpful!

0 Likes
Message 4 of 4

jeremy_tammik
Alumni
Alumni

Congratulations on the very good solution and thank you for your appreciation and sharing the results!

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes