Listing the profiles of a face in C# |
Top Previous Next |
Look at this sheet metal:
Although it could be shown as a single face it is in fact 2 faces. It probably depends on how t was constructed. Anyway this code will list the two profiles (if they are made of LineSegment2d:
public static void Test2 () { PartDocument PartDoc; try { PartDoc = (PartDocument)m_Inventor.ActiveDocument as PartDocument; if (PartDoc == null) { MessageBox.Show("This is not a part document"); return; } } catch { MessageBox.Show ("not a part doc"); return; }
PartComponentDefinition PartDef = PartDoc.ComponentDefinition; PartFeatures FeatsList = PartDef.Features;
foreach (PartFeature ThisFeature in FeatsList) { if (ThisFeature.Type == ObjectTypeEnum.kCutFeatureObject) { CutFeature CutFeature = (CutFeature)ThisFeature; ProfilePath TheProfile = CutFeature.Definition.Profile[1]; ProfileEntity Ent = TheProfile[1];
Debug.WriteLine ("Profile ent " + Ent.ToString() + " " + Ent.CurveType.ToString());
if (Ent.CurveType == Curve2dTypeEnum.kCircleCurve2d) { Circle2d Circle = (Circle2d)Ent.Curve; Debug.WriteLine(" ...is a circle of radius " + Circle.Radius.ToString()); } } else if (ThisFeature.Type == ObjectTypeEnum.kFaceFeatureObject) { FaceFeature FaceFeat = (FaceFeature)ThisFeature; Debug.WriteLine("FaceFeature <" + FaceFeat.Name + "> has " + FaceFeat.Faces.Count.ToString() + " faces");
Debug.WriteLine(" the profile has " + FaceFeat.Definition.Profile.Count.ToString() + " objects");
foreach (ProfilePath ThisPath in FaceFeat.Definition.Profile) { Debug.WriteLine(" this path the profile has " + ThisPath.Count.ToString() + " entities");
foreach (ProfileEntity ThisEnt in ThisPath) { if (ThisEnt.CurveType == Curve2dTypeEnum.kLineSegmentCurve2d) { LineSegment2d Line2d = (LineSegment2d)ThisEnt.Curve;
string sX0 = string.Format("{0,8:0.00}", Line2d.StartPoint.X); string sY0 = string.Format("{0,8:0.00}", Line2d.StartPoint.Y); string sX1 = string.Format("{0,8:0.00}", Line2d.EndPoint.X); string sY1 = string.Format("{0,8:0.00}", Line2d.EndPoint.Y);
Debug.WriteLine(" LinSeg, X:" + sX0 + " Y:" + sY0 + " --> X:" + sX1 + " Y:" + sY1); } } }
// Un false this to see even more detail #if false Faces FacesList = FaceFeat.Faces; // Face BiggestFace = null;
foreach (Face ThisFace in FacesList) { Debug.WriteLine(" this face has vertices: " + ThisFace.Vertices.Count.ToString() + " (feature: " + FaceFeat.Name + ")");
foreach (Vertex v in ThisFace.Vertices) { Point p = v.Point; Debug.WriteLine(" " + p.X.ToString() + " " + p.Y.ToString() + " " + p.Z.ToString()); } } #endif } else { Debug.WriteLine("This feature is a " + ThisFeature.Type.ToString()); } } }
And the output will look like this:
FaceFeature <Face1> has 3 faces the profile has 1 objects this path the profile has 4 entities LinSeg, X: 0,00 Y: 0,00 --> X: -53,30 Y: 0,00 LinSeg, X: -53,30 Y: 0,00 --> X: -53,30 Y: -53,00 LinSeg, X: -53,30 Y: -53,00 --> X: 0,00 Y: -53,00 LinSeg, X: 0,00 Y: -53,00 --> X: 0,00 Y: 0,00 FaceFeature <Face3> has 1 faces the profile has 1 objects this path the profile has 4 entities LinSeg, X: 8,05 Y: 0,00 --> X: 8,05 Y: -3,50 LinSeg, X: 8,05 Y: -3,50 --> X: 52,90 Y: -1,90 LinSeg, X: 52,90 Y: -1,90 --> X: 52,90 Y: 0,00 LinSeg, X: 52,90 Y: 0,00 --> X: 8,05 Y: 0,00
...and shows that there are two FaceFeatures. |
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)