How to calculate the center point of elbow?

Sino.Pacific
Contributor
Contributor

How to calculate the center point of elbow?

Sino.Pacific
Contributor
Contributor

Hi everyone,

 

I am trying to get to center point of an elbow. I have check all the data of the elbow from Revit Lookup tool but did not find anything. So is there anyway I can get that information ?

Image05.png

Thank you so much for your help 😊

 

Best Regards,

 

Sino

 

0 Likes
Reply
Accepted solutions (1)
1,974 Views
8 Replies
Replies (8)

jeremytammik
Autodesk
Autodesk

Yes. 

 

This is a pretty simple geometrical exercise.

 

You have the full information about the start and end point, specifically including location and direction == face normal.

 

The start and end point directions are not parallel. Therefore, they define a 2D plane. The centre point will normally lie in that plane, so you just have a (simpler) 2D task to solve, not 3D.

 

In the 2D plane, you can determine the normal vector to the start and end directions. Extend those two normal vectors to define infinite lines and determine their intersection. That is your centre point.

 



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

Sino.Pacific
Contributor
Contributor

Dear @jeremytammik ,

 

Thank you for your answer. But I just finally find out that actually the elbow has the center point information under the Geometry information:

 

1.png

 

So my working code is: 

 

  static public XYZ GetCenterofElbow (FamilyInstance selectedDuct)
        {
            XYZ output = null; 
            List<Connector> allConnectors = selectedDuct.MEPModel.ConnectorManager.Connectors.Cast<Connector>().ToList();
            
            Connector connectorA = allConnectors[0]; 
            Connector connectorB = allConnectors[0];

            GeometryElement geometryElement = selectedDuct.get_Geometry(new Options());
            List<GeometryInstance> ginsList = selectedDuct.get_Geometry(new Options()).Where(o => o is GeometryInstance).Cast<GeometryInstance>().ToList();

            foreach (GeometryInstance gins in ginsList)
            {
                foreach (GeometryObject ge in gins.GetInstanceGeometry())
                {
                    try
                    {
                        Arc centerArc = ge as Arc;
                        output = centerArc.Center; 
                    }
                    catch (Exception)
                    {
                       
                    }
                }
            }

            return output; 


        }

 

 

 

 

0 Likes

jeremytammik
Autodesk
Autodesk
Accepted solution

Thank you for letting us know that simple solution!

 

Oh dear. I wasted some effort, then.

 

I implemented a geometrical solution for you based on the elbow connectors and their coordinate systems:

 

 

    /// <summary>
    /// Return elbow connectors.
    /// Return null if the given element is not a 
    /// family instance with exactly two connectors.
    /// </summary>
    List<Transform> GetElbowConnectors( Element e )
    {
      List<Transform> xs = null;
      FamilyInstance fi = e as FamilyInstance;
      if( null != fi )
      {
        MEPModel m = fi.MEPModel;
        if( null != m )
        {
          ConnectorManager cm = m.ConnectorManager;
          if( null != cm )
          {
            ConnectorSet cs = cm.Connectors;
            if( 2 == cs.Size )
            {
              xs = new List<Transform>( 2 );
              bool first = true;
              foreach( Connector c in cs )
              {
                if( first )
                {
                  xs[0] = c.CoordinateSystem;
                }
                else
                {
                  xs[1] = c.CoordinateSystem;
                }
              }
            }
          }
        }
      }
      return xs;
    }
    
    /// <summary>
    /// Return elbow centre point.
    /// Return null if the start and end points 
    /// and direction vectors are not all coplanar.
    /// </summary>
    XYZ GetElbowCentre( Element e )
    {
      XYZ pc = null;
      List<Transform> xs = GetElbowConnectors( e );
      if( null != xs )
      {
        // Get start and end point and direction

        XYZ ps = xs[ 0 ].Origin;
        XYZ vs = xs[ 0 ].BasisZ;

        XYZ pe = xs[ 1 ].Origin;
        XYZ ve = xs[ 1 ].BasisZ;

        XYZ vd = pe - ps;

        // For a regular elbow, Z vector is normal 
        // of the 2D plane spanned by the coplanar
        // start and end points and direction vectors.

        XYZ vz = vs.CrossProduct( vd );

        if( !vz.IsZeroLength() )
        {
          XYZ vxs = vs.CrossProduct( vz );
          XYZ vxe = ve.CrossProduct( vz );
          pc = Util.LineLineIntersection( 
            ps, vxs, pe, vxe );
        }
      }
      return pc;
    }

 

Would you like to test my code and see whether it returns the same result?

 

Thank you!

 



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

Revitalizer
Advisor
Advisor

Hi,

 

there may be elbow families which consist of two 45°-segments, connected by a cylindrical part between them.

 

In this case, there would be two arcs with different center points, so the connector based approach seems more flexible for different family content.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes

Revitalizer
Advisor
Advisor

Hi,

 

for example:

 

1020147-pelletofenrohr-90-bogen-mit-kesselanschluss-muffe~2.jpg

 

Source: https://www.ofenseite.com/1020147-pelletofenrohr-90-bogen-mit-kesselanschluss-muffe

 

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes

Revitalizer
Advisor
Advisor

In this case, there isn't any arc at all.




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes

Sino.Pacific
Contributor
Contributor

Dear @jeremytammik and @Revitalizer ,

 

Thank you so much for your great solution. I am very appreciate your kindly help 😊

0 Likes

jeremytammik
Autodesk
Autodesk

Thank you for your appreciation, and many thanks to Revitalizer for the nice example!

  

My code would solve the task for that as well. 

  

Please confirm that it works.

  

I have not tested it myself.

  

Thank you!

  



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

0 Likes