<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic C# - Get face of extruded hole? in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8800518#M97581</link>
    <description>&lt;P&gt;I'm trying to get the face plane of an extruded hole (blue in picture below) to start a sketch. I'm using the CustomCommand addin example as a reference and this works to get the extruded hole:&lt;/P&gt;
&lt;PRE&gt;EnableInteraction()&lt;BR /&gt;{&lt;BR /&gt;    ...&lt;BR /&gt;    m_selectEvents.AddSelectionFilter(SelectionFilterEnum.kPartFaceCylindricalFilter);&lt;BR /&gt;    ...&lt;BR /&gt;}&lt;/PRE&gt;
&lt;P&gt;And in&amp;nbsp;OnPreSelect ,&amp;nbsp;preSelectEntity even evaluates to Face. But if I pass the Face to&amp;nbsp;AddByPlaneAndOffset it throws an exception about the face being a wrong parameter. It works fine if I change the selection filter to&amp;nbsp;kPartFacePlanarFilter and select the actual face (red in picture).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to use&amp;nbsp;kPartFaceCylindricalFilter as my selection filter and get the face of the cylinder? I spent a good 8 hours looking in the API reference and trying different things.&amp;nbsp; Picture for reference:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cylinderface.jpg" style="width: 871px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/638143i377F6D19BDA24C24/image-size/large?v=v2&amp;amp;px=999" role="button" title="cylinderface.jpg" alt="cylinderface.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 19 May 2019 16:37:27 GMT</pubDate>
    <dc:creator>ieatacid</dc:creator>
    <dc:date>2019-05-19T16:37:27Z</dc:date>
    <item>
      <title>C# - Get face of extruded hole?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8800518#M97581</link>
      <description>&lt;P&gt;I'm trying to get the face plane of an extruded hole (blue in picture below) to start a sketch. I'm using the CustomCommand addin example as a reference and this works to get the extruded hole:&lt;/P&gt;
&lt;PRE&gt;EnableInteraction()&lt;BR /&gt;{&lt;BR /&gt;    ...&lt;BR /&gt;    m_selectEvents.AddSelectionFilter(SelectionFilterEnum.kPartFaceCylindricalFilter);&lt;BR /&gt;    ...&lt;BR /&gt;}&lt;/PRE&gt;
&lt;P&gt;And in&amp;nbsp;OnPreSelect ,&amp;nbsp;preSelectEntity even evaluates to Face. But if I pass the Face to&amp;nbsp;AddByPlaneAndOffset it throws an exception about the face being a wrong parameter. It works fine if I change the selection filter to&amp;nbsp;kPartFacePlanarFilter and select the actual face (red in picture).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to use&amp;nbsp;kPartFaceCylindricalFilter as my selection filter and get the face of the cylinder? I spent a good 8 hours looking in the API reference and trying different things.&amp;nbsp; Picture for reference:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cylinderface.jpg" style="width: 871px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/638143i377F6D19BDA24C24/image-size/large?v=v2&amp;amp;px=999" role="button" title="cylinderface.jpg" alt="cylinderface.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2019 16:37:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8800518#M97581</guid>
      <dc:creator>ieatacid</dc:creator>
      <dc:date>2019-05-19T16:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: C# - Get face of extruded hole?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8800701#M97582</link>
      <description>&lt;P&gt;Here is some more information. The exception:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="exception.jpg" style="width: 419px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/638177iE2BC5A9C41D1667B/image-size/large?v=v2&amp;amp;px=999" role="button" title="exception.jpg" alt="exception.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the intended result when I use&amp;nbsp;kPartFacePlanarFilter as the selection filter (but I need to use&amp;nbsp;kPartFaceCylindricalFilter so I can select the cylinder (extruded hole)):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="success.jpg" style="width: 361px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/638176i8C763FB21CF37055/image-size/large?v=v2&amp;amp;px=999" role="button" title="success.jpg" alt="success.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would love you forever if you can help!&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2019 20:59:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8800701#M97582</guid>
      <dc:creator>ieatacid</dc:creator>
      <dc:date>2019-05-19T20:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: C# - Get face of extruded hole?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8800934#M97584</link>
      <description>&lt;P&gt;Creating a work plane requires a planar entity as input.&amp;nbsp; You see the same thing in the UI.&amp;nbsp; You can't create a work plane by only selecting a cylindrical face.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, it is possible to find the faces that are on the ends of the hole.&amp;nbsp; If the hole is a through hole then there are two potential faces and you'll have to choose which one.&amp;nbsp; If it's a blind hole and the bottom is angled then it's fairly easy.&amp;nbsp; The cylindrical face you've found is represented by the Face object.&amp;nbsp; The Face object supports an Edges property which returns all of the edges of the face.&amp;nbsp; In the case of your hole example, there will be two edges returned.&amp;nbsp; The edges are represented by the Edge object and the Edge object supports a Face property which returns the faces that are connected to the edge.&amp;nbsp; This will return two faces, the cylindrical face you already have and the connecting face.&amp;nbsp; For a blind hole with an angled end, this will return a conical face but the face you're looking for will be a plane.&amp;nbsp; I'm not able to take the time to code up the sample but that's the workflow I would go through.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 03:04:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8800934#M97584</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2019-05-20T03:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: C# - Get face of extruded hole?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8801709#M97599</link>
      <description>&lt;P&gt;Thanks for your reply. That makes sense but here are some debug messages that don't match those numbers&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;RackFaceCmd.OnSelect m_extrudeFace.EdgeLoops.Count  4
RackFaceCmd.OnSelect m_extrudeFace.Edges.Count      22
&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2019 11:22:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8801709#M97599</guid>
      <dc:creator>ieatacid</dc:creator>
      <dc:date>2019-05-20T11:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: C# - Get face of extruded hole?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8803027#M97609</link>
      <description>&lt;P&gt;Well this works, but it's obviously not the *right* way to do it (I don't think)&lt;/P&gt;
&lt;PRE&gt;    Edge edge = m_extrudeFace.Edges[1];
    Face face = edge.Faces[1];
    WorkPlane workPlane = workPlanes.AddByPlaneAndOffset(face, dOffset);
    workPlane.Visible = true;&lt;/PRE&gt;
&lt;P&gt;There has to be a way to check if the edge is right on the face of the part - or will this always be the case with edge 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Another hole that doesn't go all the way through produced the same exception as above, so it's not going to work unless I can figure out how to check if edge-&amp;gt;face is at the opening of the hole (open to suggestions &amp;gt;.&amp;lt; )&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 20:41:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8803027#M97609</guid>
      <dc:creator>ieatacid</dc:creator>
      <dc:date>2019-05-20T20:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: C# - Get face of extruded hole?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8803180#M97610</link>
      <description>&lt;P&gt;This "just works" and selects the correct face to add the plane to. Still, I'd like to find a way to be absolutely sure it's the same face as the hole's face.&lt;/P&gt;
&lt;PRE&gt;    Face planarFace = null;

    for (int i = m_extrudeFace.Edges.Count; i &amp;gt; 0; i--)
    {
        Edge edge = m_extrudeFace.Edges[i];

        if (edge != null)
        {
            int nFaces = edge.Faces.Count;

            for (int j = 1; j &amp;lt;= nFaces; j++)
            {
                Face face = edge.Faces[j];

                if(face.SurfaceType == SurfaceTypeEnum.kPlaneSurface)
                {
                    Message("Planar surface found!");
                    planarFace = face;
                }
            }
        }

    }

    if(planarFace != null)
    {
        WorkPlane workPlane = workPlanes.AddByPlaneAndOffset(planarFace, 0);
        workPlane.Visible = true;
    }&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2019 22:08:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8803180#M97610</guid>
      <dc:creator>ieatacid</dc:creator>
      <dc:date>2019-05-20T22:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: C# - Get face of extruded hole?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8803644#M97618</link>
      <description>&lt;P&gt;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.&amp;nbsp; Other cases would be possible to handle too but will need some more logic to identify them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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];
}&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 May 2019 06:15:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/c-get-face-of-extruded-hole/m-p/8803644#M97618</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2019-05-21T06:15:41Z</dc:date>
    </item>
  </channel>
</rss>

