Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to calculate the center point of elbow?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Sino.Pacific
1875 Views, 8 Replies

How to calculate the center point of elbow?

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

 

8 REPLIES 8
Message 2 of 9
jeremytammik
in reply to: Sino.Pacific

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

Message 3 of 9
Sino.Pacific
in reply to: jeremytammik

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; 


        }

 

 

 

 

Message 4 of 9
jeremytammik
in reply to: Sino.Pacific

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

Message 5 of 9
Revitalizer
in reply to: Sino.Pacific

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





Message 6 of 9
Revitalizer
in reply to: Revitalizer

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





Message 7 of 9
Revitalizer
in reply to: Revitalizer

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




Rudolf Honke
Software Developer
Mensch und Maschine





Message 8 of 9
Sino.Pacific
in reply to: jeremytammik

Dear @jeremytammik and @Revitalizer ,

 

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

Message 9 of 9
jeremytammik
in reply to: Sino.Pacific

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report