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: 

Create Extrusion Geometry Issue

3 REPLIES 3
Reply
Message 1 of 4
alistairaMWWGJ
258 Views, 3 Replies

Create Extrusion Geometry Issue

Hi All,

I have a floor with a slab edge underneath it, and I am trying to extend those slab edges under the slab when certain conditions exist (basically at an internal corner when the next section extends out a certain distance).  I identify the external corners and then make a call to add just a simple extrusion, passing in the corner point, and the previous corner point along the plane. 

 

/// <summary>
/// 
/// </summary>
/// <param name="doc"></param>
/// <param name="current">The is the Point that I want to Start From </param>
/// <param name="previous">This is the Previous Point</param>
private void CreateFooting(Document doc, XYZ current, XYZ previous)
{
    // Get the extrusion direction
    XYZ extrusionDirection = GetExtrusionDirection(previous, current);

 

Firstly, this gets the direction change between the 2 points as it could be changing X or Y or both, it then adds 300mm to the starting point (as this is the outside of the slab, and I want it from the inside of the footing)

        private XYZ GetExtrusionDirection(XYZ previous, XYZ current)
        {
            // Calculate the vector from previous to current
            XYZ directionVector = (current - previous).Normalize();

            // Convert 300mm to feet
            double distance = 300 / 304.8;

            // Calculate the new point 300mm past the current point in the direction away from the previous point
            XYZ extrusionPoint = current + directionVector * distance;

            return extrusionPoint;
        }

 

 

I then offset it further out by (fixed but will be eventually be parameter driven 300mm - which is the thickness of the external footing).  My complete method is below, but it in essence

  • gets a direction from current to previous (as I want to continue on the same plane)
  • sets up 4 points (p1 to p4) in essence 300mm wide, by 200mm, but starting 300mm "past" the current starting point, then adds those 4 points into a CurveLoop
  • It then creates a new extrusion (called footing) with the CurveLoop, in the extrusionDirection and 2.000m long)
  • finally adds it.

 

 private void CreateFooting(Document doc, XYZ current, XYZ previous)
 {
     // Get the extrusion direction
     XYZ extrusionDirection = GetExtrusionDirection(previous, current);

     // Convert millimeters to feet
     double width = 300 / 304.8; // 300mm to feet
     double depth = 200 / 304.8; // 300mm to feet
     double length = 2000 / 304.8; // 2 meters to feet

     // Define points for the footing profile
     XYZ p1 = extrusionDirection;
     XYZ p2 = extrusionDirection + new XYZ(width, 0, 0);
     XYZ p3 = p2 + new XYZ(0, 0, -depth);
     XYZ p4 = extrusionDirection + new XYZ(0, 0, -depth);

     Line line1 = Line.CreateBound(p1, p2);
     Line line2 = Line.CreateBound(p2, p3);
     Line line3 = Line.CreateBound(p3, p4);
     Line line4 = Line.CreateBound(p4, p1);

     CurveLoop curveLoop = new CurveLoop();
     curveLoop.Append(line1);
     curveLoop.Append(line2);
     curveLoop.Append(line3);
     curveLoop.Append(line4);

     // Create the extrusion
     Solid footing = GeometryCreationUtilities.CreateExtrusionGeometry(new List<CurveLoop> { curveLoop }, extrusionDirection, length);

     // Create a DirectShape to represent the footing
     DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
     ds.SetShape(new List<GeometryObject> { footing });
 }

 

It's drawing the extrusion the right size, but on an angle, and I can't figure out why (shape is red, should be blue), so the problem has to be with y extrustion direction vector.

alistairaMWWGJ_0-1718340721318.png

Am I right in assuming that I can create the vector from the current point - previous point?

 

Thanks for help and any ideas appreciated.

Cheers, Al

3 REPLIES 3
Message 2 of 4

Hi @alistairaMWWGJ,

 

I have no idea what "XYZ current, XYZ previous" are and where do they come from...?

 

Not looking deeper, but the line below in "private XYZ GetExtrusionDirection(XYZ previous, XYZ current)" doesn't seem ok, the direction was already obtained?

XYZ extrusionPoint = current + directionVector * distance;

 

Maybe check if the 2 input XYZ's are correct.

 

Also: for unit conversion use the builtin methods: ConvertToInternalUnits Method 

 

- Michel

Message 3 of 4

Hi Michel,

 

Thanks for your answer.  Sorry I hadn't provided enough details.  

 

I was traversing the edges of a floor slab, previous was the last corner, current is the corner being tested.  I have logic that creates re-entrant beams into the slab for structural purposes, and the line you highlighted moved the geometry out the width of the existing slab footing.

 

I simplified the code, and changed from using an extrusion to using the required footing type, and then continued it on in the normalised version of the vector and it's working.

 

Thanks for looking!

Regards, Al

Message 4 of 4
scgq425
in reply to: alistairaMWWGJ

Hi @alistairaMWWGJ :

can u debug and print u extrusionDirection value , or just set this value is XYZ(1,0,0) and test this , may be the problem is this value , and then debug the curveloop-plane use curvelppp.getplane() , check the direction value

 

LanHui Xu
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

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

Post to forums  

Autodesk Design & Make Report