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
1946 Views, 8 Replies

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

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

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

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

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

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

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

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

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

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

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

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

Revitalizer
Advisor
Advisor

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




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes

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

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

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

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

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  

Autodesk Design & Make Report