05-20-2019
11:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
05-20-2019
11:15 PM
Here's some code that should give the right result every time, assuming that it's a blind hole and there are no other cuts into the hole. Other cases would be possible to handle too but will need some more logic to identify them.
private void button1_Click(object sender, EventArgs e)
{
Inventor.Application invapp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
PartDocument partDoc = (Inventor.PartDocument)invapp.ActiveDocument;
PartComponentDefinition partComp = partDoc.ComponentDefinition;
// Get the extrude feature named "Extrusion2".
ExtrudeFeature extrude = (ExtrudeFeature)partComp.Features["Extrusion2"];
// Get the side face of the extrusion.
Face sideFace = extrude.SideFaces[1];
// Iterate over the edges of the face and find the connecting faces.
Face endFace = null;
foreach (Edge testEdge in sideFace.Edges)
{
// Get the face that connects to the side face using the current edge.
Face otherFace = GetConnectedFace(sideFace, testEdge);
// check to see if this face isn't the bottom of the hole by
// making sure it isn't one of the faces created by the extrude.
bool badFace = false;
foreach (Face extrudeFace in extrude.Faces)
{
if (extrudeFace == otherFace)
{
badFace = true;
break;
}
}
// It isn't one of the extrude faces so keep it.
if (!badFace)
{
endFace = otherFace;
break;
}
}
if (endFace != null)
{
// A face was found so create a work plane.
WorkPlane workPlane = partComp.WorkPlanes.AddByPlaneAndOffset(endFace, 0);
}
}
// Function that given a face and an edge on that face returns
// the connecting face.
private Face GetConnectedFace(Face knownFace, Edge knownEdge)
{
if (knownEdge.Faces[1] == knownFace)
return knownEdge.Faces[2];
else
return knownEdge.Faces[1];
}
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com