How do you access faces that are no longer visible due to chamfer feature?

How do you access faces that are no longer visible due to chamfer feature?

johnPGNFG
Enthusiast Enthusiast
432 Views
4 Replies
Message 1 of 5

How do you access faces that are no longer visible due to chamfer feature?

johnPGNFG
Enthusiast
Enthusiast

Hi all!

I'm analyzing holes on pipe in which some have a chamfer feature applied to them.  I need some way to access the cylinder surface that existed before the chamfer feature was applied to the hole.  Note: The hole is not always created by a hole feature, sometimes it will be an extruded circle from a sketch. One way I tried was by finding the edge that was used to create the chamfer.  I then set "ChamferFeature.Suppressed" to "true". I then found the cylinder attached to the edge and could go from there.  After getting the info I needed, I set the suppressed property back to false and continued with the code.  The problem is that by suppressing the chamfer, it changed properties of other faces on the part as well.  I initially save the outside face of the pipe as "Inventor.Face topFace. If I try to access, for example, topFace.Edges, after suppressing/unsuppressing, the code fails because the face has changed.

 

Is there a way to access the original hole cylinder before the chamfer feature was applied without having to suppress the feature?

 

johnPGNFG_0-1664400797830.png

 

0 Likes
Accepted solutions (2)
433 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @johnPGNFG.  What do you need the old hole cylinder face for?  Have you tried doing all of what you need to do with it while the chamfer feature is suppressed, then un-suppress the feature after you are completely done with it?  Have you tried creating a transient Cylinder object of that face, while the feature is suppressed, so that you can use that created cylinder for your purposes after you un-suppress the feature?  (Transient = mathematical / not visible)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

johnPGNFG
Enthusiast
Enthusiast

I need the radius of the cylinder, the angle the cylinder intersects the pipe (it's not always straight), the offset of the cylinder from the center of the pipe (the cylinder axis will not always intersect the pipe axis), and the point where the cylinder axis intersects the outside face of the pipe.  I figured all this out by suppressing the chamfer and looking at the cylinder it was created on.  I no longer need the cylinder after that so I unsuppress the chamfer. The problem is when I unsuppress the chamfer the properties of other faces on the part seem to have changed. 

 

Here is some sample code below.  I first save the outer face of the pipe as "topFace".  (I figure out which face this is earlier in the code) I then use a foreach loop to go through each edge on topFace to prove they exist. This loop is entered and runs.  I then use a foreach each loop to go through all the faces on the part and find the one created by the chamfer feature.  When I find it, I suppress it, then unsuppress it.  I then run the same foreach loop I did at first to look at each edge on topFace but no edges exist and the loop is skipped.  This tells me the face has changed because I suppressed/unsuppressed the chamfer.  The chamfered face itself acts the same way after unsuppressing it.  It seems like there's a way to get to the cylinder face of the hole without suppressing the chamfer but I can't seem to find it.

 

Inventor.Face topFace= oCompDef.SurfaceBodies[1].Faces[4];   //Outer face of pipe

 

foreach (Inventor.Edge edge in topFace.Edges)
{
      //this foreach loop runs
}

 

foreach (Inventor.Face face in oCompDef.SurfaceBodies[1].Faces)
{
     if (face.CreatedByFeature.Type == ObjectTypeEnum.kChamferFeatureObject)
       {
            ChamferFeature oChamf = (ChamferFeature)face.CreatedByFeature;

            oChamf.Suppressed = true;

            oChamf.Suppressed = false;
        }
}

 

foreach (Inventor.Edge edge in topFace.Edges)
{
     //this foreach loop is skipped
}

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

That's a tough one.  As you have observed, things like faces & edges often loose their original reference when they get modified by features.  I have seen folks use the ReferenceKey system to find & bind back to objects later, which they may have worked with in previous processes, but I believe that even that system can get broken by this behavior.  You can dig into that system and give it a try, if this is important.  I do currently not have much personal experience using it though, so if you want to explore into it more, you can find examples of its use through a search on this forum.  The two main things you can look at within the online help area are the Face.GetReferenceKey method, and the ReferenceKeyManager object, which can be found right the Document object.  That ReferenceKeyManager object has several methods available under it that you may find useful.  Unfortunately they to not list any sample API codes for you to reference on that page.

 

PS.  It may be faster/more efficient to get to the face, by directly accessing the Feature that created it first, then explore its Feature.Faces property until you find the one you want.  For example, the ExtrudeFeature object has a Faces property, a SideFaces property, a StartFaces property, and an EndFaces property.  These can sometimes be helpful in these types of situations.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

johnPGNFG
Enthusiast
Enthusiast
Accepted solution

Thanks!  After playing around with it for a while it looks like that should work.  This is what made the sample code work:

 

Inventor.Face topFace = oCompDef.SurfaceBodies[1].Faces[4];   //Outer face of pipe

 

ReferenceKeyManager oRefKeyMan = partDoc.ReferenceKeyManager;  

int keycontext = oRefKeyMan.CreateKeyContext();

byte[] topFaceRefKey = new byte[0];
topFace.GetReferenceKey(ref topFaceRefKey, keycontext);
object matchType = null;

 

foreach (Inventor.Edge edge in topFace.Edges)
{
      //this foreach loop runs
}

 

foreach (Inventor.Face face in oCompDef.SurfaceBodies[1].Faces)
{
     if (face.CreatedByFeature.Type == ObjectTypeEnum.kChamferFeatureObject)
     {
           ChamferFeature oChamf = (ChamferFeature)face.CreatedByFeature;
           oChamf.Suppressed = true;
           oChamf.Suppressed = false;
      } 
}

 

topFace = (Inventor.Face)partDoc.ReferenceKeyManager.BindKeyToObject(topFaceRefKey, keycontext, out matchType);
matchType = null;

 

foreach (Inventor.Edge edge in topFace.Edges)
{
      //this foreach loop runs now
}

 

 

I don't need to keep up with matchType so I set it to null after I use BindKeyToObject or else I get an error the next time I use BindKeyToObject.

 

I appreciate the help!