Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issue with Sketch Extrusions using Faces

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
andrei.zorinGPRX9
272 Views, 10 Replies

Issue with Sketch Extrusions using Faces

I am having problem understanding creation of sketches with extrusions using different Faces.

 

I have a simple cuboid part where there are several rectangle extrusions on the left face and there are several circular extrusions on the front face. Rectangle cutouts are created first and circular cutouts are created after the last rectangular cutout (bottom one): 

error.JPG

As you can see the circular sketches are located outside of the front face.

If I don't create the bottom rectangle cutout - the circular sketches are created in the right place:

correct.JPG

 

My suspicion is that the bottom rectangular cutout somehow modifies the front face.

But I don't understand why or how.

 

Before creating any cutouts I create a map of all faces and their respective internal names like so: 

var faceNamesToInternalNames = new Dictionary < FaceName, string >
{
  { FaceName.Front, itemDefinition.SurfaceBodies[1].Faces[2].InternalName },
  { FaceName.Back, itemDefinition.SurfaceBodies[1].Faces[4].InternalName },
  { FaceName.Top, itemDefinition.SurfaceBodies[1].Faces[5].InternalName },
  { FaceName.Bottom, itemDefinition.SurfaceBodies[1].Faces[6].InternalName },
  { FaceName.Left, itemDefinition.SurfaceBodies[1].Faces[3].InternalName },
  { FaceName.Right, itemDefinition.SurfaceBodies[1].Faces[1].InternalName }
};

 

then I find the needed face like so:

var face = GetFaceById(partComponentDefinition, faceNamesToInternalNames[FaceName.FRONT]);

public Face GetFaceById(PartComponentDefinition itemDefinition, string faceName)
{
  return itemDefinition.SurfaceBodies[1].Faces.Cast<Face>().First(face => face.InternalName.Equals(faceName));
}

 

then I create a sketch on the selected Face like so:

var sketch = partComponentDefinition.Sketches.Add(face);
var center = GetCenterPoint(FaceName.FRONT, _tg);
sketch.SketchCircles.AddByCenterRadius(center, diameter);

 

Can somebody please explain what I am doing wrong and how to fix this.

The solution of creating circular cutouts first doesn't fit as I have no control over the order of cutouts (they come in a JSON format from the server).

Tags (3)
10 REPLIES 10
Message 2 of 11

@WCrihfield  you helped me a lot last time a lot with a similar issue, so I am tagging you here in a hope you can help me again 🙂

Message 3 of 11

Hi @andrei.zorinGPRX9.  From what I can tell, based on the information in your original post here, you are correct about the feature changing the identity of the face.  The Face.InternalName property tells us that this value will change if any features modify that face.  I don't even think that assigning an Attribute to that face will help in cases like this either.  The only process I can think of that may work better for you in a situation like that is the Face.GetReferenceKey method, combined with accessing the PartDocument.ReferenceKeyManager property to get its ReferenceKeyManager object and using its available tools.  It can be a complicated system to utilize properly, and it can load up your system memory if not handled correctly.  I do not really have a lot of experience with that system myself, because I have not needed to that much yet, but if you search around within this forum for a while, you will find some other very useful and informational posts about it, and some examples.  The process seems to start by you using the CreateKeyContext method to get an important 'Long' type value that you will need to store for later use.  Then you use that as the second input to the GetReferenceKey method, to bind the data to an internal database.  This database is specifically for the current state of the model (like a picture of everything the way it was when you collected that 'key context' spec).  That way, later, after changes have been made, and those faces have different internal ID's, you can still find them from the data that was stored at an earlier stage, in that database.  To find the same face again, based on that reference key, and the key context (from before), you will need to use the BindKeyToObject method.  But there are other step in the middle, using the other methods of the ReferenceKeyManager, for how to 'store' the 'key context' data to something like a custom iProperty, Attribute, or something like that before you close the model.  Then when you open the model again some time later, after some changes have been made, you can load that key context from wherever you stored it, and use that to find the original faces from before the changes.

Wesley Crihfield

EESignature

Message 4 of 11

Thank you a lot @WCrihfield for the tip on using the ReferenceKeyManager as a possible solution. I will investigate this option. However, I still dont understand how it works. For me it is logical that if I insert a cutout on a Face it can modify that face by splitting the full Face into kind of sub-Faces but I would expect those sub-Faces to be contained within the original face like so: 

Screenshot at Nov 02 15-23-13.png

But this still doesn't explain why only the last (bottom) cutout changes the face.

Also it looks like the face where I apply circular cutouts is positioned outside of the SolidBody: 

andreizorinGPRX9_0-1698935085084.png

 

Maybe it is not even related to faces and something else messing up the positioning of the sketches, as if the origin of the face changes (from left edge to right edge) and the coordinates are now calculated from the right edge to the left edge of the same Face.

I am really confused and cannot find any documentation or tutorial regarding this behaviour.

Message 5 of 11

I'm afraid the reasoning behind those issues are over my head, and likely something you would have to ask someone at Autodesk about directly.  I thought the same as you about the faces being split by new features, and that may be partially correct, but for some reason, the folks who wrote the source code for the Inventor API saw the necessity to change the face's identity when it gets changed by features.  And apparently the only way to find that face again, after it has been changed by a feature, is to record a key context & reference key for that face before it gets changed, then use those resources to find it again after the changes.  It may in fact be the same face, but it may also be a Face that was created when the feature was created, but since its identification has changed either way, it can no longer be found the 'normal' way.  As for the circles not appearing on the face of the part, I am not sure why that might have happened, but I have definitely seen similar stuff happen several times before.  It seems like it has happened to me after either mirroring a part, or after changing the direction of an extrude feature, or after changing the direction of a Flange in a sheet metal part...after I had created the sketch on that face.  It may have something to do with the face and/or edges involved in the original sketch environment being redefined, which likely caused some of the constraints to loose their 'link' to the original geometry.  Just my thoughts.

Wesley Crihfield

EESignature

Message 6 of 11

@andrei.zorinGPRX9,

 

You mentioned you can't do the circular cuts first, but could you create the 2 sketches before any extrusion?  You would have less variance in the projected face profile in the sketch that way.

 

Another thought:  If that last extrusion is the only one causing issues, just suppress it before creating the sketch for the circular cutouts, then the projected face will ignore that extrusion feature, and the extrude feature can be unsuppressed after the circular extrusion sketch is created.

Final thought:  I think Named Faces persist through feature modifications, outside of Delete Face Feature or full separation of face region.  If you name the faces instead of creating a dictionary of internal names, then you should be able to call the faces through NamedGeometry.  The face names could be deleted after the fact as well, if you don't want them to persist to the final part.  You would have to use the AutoDesk.iLogic.Interfaces.NamedEntities Interface using the IiLogicAutomation.GetNamedEntities Method for this process.

Message 7 of 11
WCrihfield
in reply to: J-Camper

You are right about naming a face by assigning an Attribute to it with a String value type containing the name, and that usually allowing us find that face again, even if some changes have been made to it.  I do not fully understand the rules behind how/when the InternalName property of a Face gets changed, so I can't explain why it seems to work sometimes, and not others.  I have always used the Attribute route,  which is what the NamedEntities interface uses behind the scenes too, but I usually only assign names to entities in models that are well established (no further design changes needed), so I do not encounter some of the same problems that I hear about others having on the forums.  Keeps things interesting when we keep hearing about the challenges other are encountering, and trying to figure them out.  It would help a lot if there was more interactions with some knowledgeable Autodesk employees who could help us figure some of these mysteries out.

Wesley Crihfield

EESignature

Message 8 of 11

@J-Camper 

Thank you for the suggestion on using NamedEntities. I will try this approach.

 

Regarding the first approach, I didn't quite get it, did you mean to create sketches first and the do the extrusions? 

This will require to map sketches to their respective extrusion depths, then iterate over created sketches and create extrusions. This may work, but I will need to name the sketches in order to identify them later. 

 

Regarding the suppression of the problematic cutout, this unfortunately, is not really feasible as we don't know ahead of time which cutout will cause problems in the future when we will perform extrusions on the next set of cutouts and we also would not know the order of the cutouts as the order is not guarantied by the backend.

Message 9 of 11

In the end I solved the problem by delaying adding of extrude features to the part component definition.

So first I create all the sketches. profiles and extrude definitions:

var sketch = partComponentDefinition.Sketches.Add(face);
var center = GetCenterPoint(FaceName.FRONT, _tg);
sketch.SketchCircles.AddByCenterRadius(center, diameter);
var profile = sketch.Profiles.AddForSolid();
var extrudeDefinition = partComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile,PartFeatureOperationEnum.kCutOperation);
extrudeDefinition.SetDistanceExtent(Height,PartFeatureExtentDirectionEnum.kNegativeExtentDirection);
return extrudeDefinition;

 

and then I loop through the list of those extrude definitions and add them to the part component definition, like so:

foreach (var extrudeDefinition in extrudeDefinitions)
{
  partComponentDefinition.Features.ExtrudeFeatures.Add(extrudeDefinition);
}

Thank you again guys: @WCrihfield @J-Camper 

Message 10 of 11
J-Camper
in reply to: WCrihfield

@WCrihfield,

 

I think the unique face identity [InternalName] persists until the definition of edges and/or vertices changes by adding/removing or changing an edgetype.  At that time the 2 faces, modified and unmodified, are not the same geometry collection so the new face needs a new identity.  This way if the modifying feature is suppressed we have a reference to the previous, unmodified face.  It also makes sense in a features like mirror/combine because there is the option to keep or discard originals so any new faces have to be different to accommodate.

 

My best assumption on how the original face is aligning to the current face is they are referencing matching vertices.  In this case the bottom left vertex appears to be preferred as a reference point to the initial face [orientation from image and original face referring to the circular holes].

I'm not sure if the is some prime order for the alignment, but the first extrusion removes the top left vertex and therefore reference geometry in the projected face.  Losing this first vertex doesn't seem to affect the alignment.  In the final extrusion there is no longer a reference to the original face's bottom left vertex so the next time the face is selected, there are only 2 remaining vertices that match the initial face; the bottom right and the top right. 

In this final attempt to map the original face to the current face; the reference point of the original face is still using the the bottom left vertex, but this gets aligned to the current face's reference to the bottom right vertex that matches the original face. We would need insight on how they do the alignment of an old face to new faces when creating a sketch on a face to know for sure why this behavior occurred.

 

@andrei.zorinGPRX9,

I would be interested to see what face alignment for a sketch would look like if that last adjacent face extrusion cut all the way through the part.  There would only be 1 matching vertex left at that point, but it is a top point.

Message 11 of 11
WCrihfield
in reply to: J-Camper

In my testing, I created a new part from an empty part template, sketched an unconstrained rectangle around the origin point, then extruded that to a default single unit tall, bi-directional, so that neither face would be 'on' a WorkPlane.  Then created a simple 3 line rule that lets me 'Pick' a Face, and it writes its InternalName to the iLogic Log window.  Ran than, picked the top face, looked at the result in the iLogic Log window, then saved and closed that part.  Edited another part, then saved that.  Opened the new test part back up, created a new WorkPlane offset from the WorkPlane that the sketch was based on that is out above the top face of the part, so that the new sketch was not based on any existing face.  Created a new sketch on that offset WorkPlane that is also entirely unconstrainted to any aspect of the existing part.  In this new sketch, I created a jagged donut shape, with its outer edges way out away from the part's existing outer edges, and the inner profile of the donut was within all existing edges of the existing face.  Nothing in the donut sketch is circular or rectangular, just a bunch of unconstrained lines in messy, jagged arangement.  Then extruded the area between the inner and outer profile of the donut sketch from that offset WorkPlane that was above the top face, down to the bottom face of the part, that was below the origin WorkPlane.  That left only a small interior portion of the original face in tact, but none of its original edges or vertices.  Then I saved and closed this part again.  Then edited another part, and saved it.  Then opened the test part back up, then ran the rule, picked that small portion of what's left of the original face, and it wrote the same InternalName to the iLogic Log Window as when I first created the simple rectangular part.  I have also tried cutting all exterior edges away from the original part using multiple cut - extrude features, but leaving a little of the interior of the original face.  Same results, it still had the same InternalName.  None of those more recent tests had any Attributes involved at all, which blew away my assumption that adding an Attribute somehow caused the InternalName to be preserved for some reason.  Maybe if I had used different 'sessions' of Inventor, instead of just closing and reopening the part, it would have forgotten the face's InternalName, not sure, but that would require even more testing.

Most likely the only way we will find out precisely how that system works is by asking someone at Autodesk, who works with Inventor's API all the time about it directly.  Someone like @MikeDeck maybe.  He probably gets tagged a ton though by a lot of folks, so I don't like to wear out my welcome by calling on him too often. 😅

Wesley Crihfield

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report