Flexible Way to Obtain Extrusion Length

Flexible Way to Obtain Extrusion Length

Anonymous
Not applicable
994 Views
3 Replies
Message 1 of 4

Flexible Way to Obtain Extrusion Length

Anonymous
Not applicable

Hello,

 

As the title suggests, I am looking for a way to obtain the extrusion length of an object, regardless of the way it has been created. I have a few work arounds if the extrusion is a hole, or cutting into an object, by looking at the side/start/end faces, however I have come across an example in my work where there are actually no faces to reference; they all return null (I am using C#).

I notice within the GUI that the length is posted (I can attach a screenshot if necessary), so I am wondering how this number can be extracted.

 

Any help would be appreciated, 

 

Thanks,

 

Philip

 

 

0 Likes
Accepted solutions (1)
995 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

You can lookup all ExtrudeFeatures and look up the extrusion length.

C#

static void Main(string[] args)
        {

            Application inventor = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
            PartDocument doc = (PartDocument)inventor.ActiveDocument;
            
            foreach (ExtrudeFeature feature in doc.ComponentDefinition.Features.ExtrudeFeatures)
            {
                switch (feature.Definition.ExtentType)
                {
                    case PartFeatureExtentEnum.kDistanceExtent:
                        DistanceExtent ext = (DistanceExtent)feature.Definition.Extent;

                        Console.WriteLine(string.Format("{0} is of type {1} and has distance: {2}",
                            feature.Name,
                            feature.Definition.ExtentType.ToString(),
                            ext.Distance.Value
                            ));
                        break;
                    default:
                        break;
                }
                
            }
            
            Console.ReadKey();

        }

this example works only for a extrusion by a length. In the help you will find a more comprehensive example written in vba. (look for an example called "GetFeatureInfo")

Jelte de Jong
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


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thank you for the reply, however the examples given are too basic for what I am looking for. I know how to handle the simple case of kDistanceExtent, as the value is essentially built in, however I have a case with kToExtent, and no faces to reference (side, start, and end face counts all return 0).

 

If you'd like a little more information, my current method is to look for planar side faces, if they exist, and find the edge which is parallel to the normal of the sketch plane which created the extrusion. This edge allows me to grab a value for the depth of the 'cut'. If the side face is cylindrical, an edge still exist so my method works.

In the case of a fully rotated cylinder, no vertices or edges are present, so I just use the fact that the face area should be equal to 2*Pi*r*h and extract h.

 

However, now I have a extrusion that someone has made where no side faces (or any faces for that matter) are present to work with. However, as I said, within the GUI I can literally see the value that it should be, so I was wondering if there was some simpler way to get this number that I am just missing.

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

I have found a solution. Without error checking, it works as follows:

 

//get the extrude feature and type of extent, here assumed to be of type kToExtent
ExtrudeFeature extFeat = oCompDef.Features[1];
ToExtent toExt = extfeat.Extent as ToExtent;
PlanarSketch sketch = extFeat.Profile.Parent as PlanarSketch;
UnitVector sketchNormal = sketch.PlanarEntityGeometry.Normal;

//since ToFace returns a face collection, we grab the first
Faces extentFaces = toExt.ToFace as Faces;
Face extentFace = extentFaces[1];

//find the distance from a sketch point to a characteristic point on the face which defines the ToExtent, normal along the sketch plane.
double depth = sketch.SketchPoints[1].Geometry3d.VectorTo(face.PointOnFace).DotProduct(sketchNormal.AsVector());

0 Likes