How to get width and Height of curveloop

How to get width and Height of curveloop

Anonymous
Not applicable
1,351 Views
4 Replies
Message 1 of 5

How to get width and Height of curveloop

Anonymous
Not applicable

How to calculate height and width of cuveloop as shown below?

Untitled.png

0 Likes
Accepted solutions (2)
1,352 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

One easy way to get a pretty good approximate value would be to tessellate the curve and determine the minimum and maximum resulting vertex coordinates:

 

https://apidocs.co/apps/revit/2019/f95f3199-3251-c708-c5a3-a0e9ef95ecfa.htm

 

 



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

Message 3 of 5

Anonymous
Not applicable

Hi 

It works for me.

Thank you

 

List<XYZ> lstPts = new List<XYZ>();
foreach (Curve cv in cl)
{
lstPts.AddRange(cv.Tessellate());
}

List<XYZ> tmp = lstPts.OrderBy(x => x.Z).ToList();

List<XYZ> tmp1 = lstPts.OrderBy(x => x.X).ToList();

double height = Math.Abs(tmp[0].Z - tmp[tmp.Count - 1].Z);
double width = Math.Abs(tmp1[0].X - tmp1[tmp1.Count - 1].X);

0 Likes
Message 4 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

Thank you for confirming and sharing!

 

I decided to add something similar to The Building Coder samples for future reference.

 

To make it more generic, I implemented an extension method ExpandToContain( IEnumerable<XYZ> ) on the bounding box, and use it like this:

 

    public static BoundingBoxXYZ GetBoundingBox(
      CurveLoop curveLoop )
    {
      List<XYZ> pts = new List<XYZ>();
      foreach( Curve c in curveLoop )
      {
        pts.AddRange( c.Tessellate() );
      }

      BoundingBoxXYZ bb = new BoundingBoxXYZ();
      bb.Clear();
      bb.ExpandToContain( pts );
      return bb;
    }

  

Can you confirm that this works for you as well?

 

Thank you!

 

Here are the entire diffs (unfortunately including lots of superfluous whitespace modifications):

 

https://github.com/jeremytammik/the_building_coder_samples/compare/2019.0.145.12...2019.0.145.13

 

Cheers,

 

Jeremy

 



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

Message 5 of 5

Anonymous
Not applicable

Hi 

0 Likes