- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to create a sketch onto a face within a part, which I will then add/modify features from, however I am unable to create a 2D sketch onto any desired face as I am given an error upon running Sketches.Add().
This part is currently an immediate child of the active assembly, but I have also attempted in modifying a part within an assembly, which itself is within the active assembly (a part within a sub-assembly).
To simplify my debugging process, I decided to replicate the "Start 2D Sketch" tool and select a specific face I want to create a sketch onto. Code snippets for this are below:
iLogic Sample:
Dim face As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a face")
' Only attempt to add a sketch if the selected face belongs to a part
If (face.Parent.ComponentDefinition.Type = ObjectTypeEnum.kPartComponentDefinitionObject) Then
Dim def = face.Parent.ComponentDefinition
Dim sketch As PlanarSketch = def.Sketches.Add(selection)
End IfC# Sample:
Face selection = (Face)Globals.InventorApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a face");
// Only attempt to add a sketch if the selected face belongs to a part
if (((Face)selection).Parent.ComponentDefinition is PartComponentDefinition def)
{
PlanarSketch profile = def.Sketches.Add(selection);
}
Both of these snippets fail upon adding the sketch the part's component definition.
What am I doing wrong?
To my understanding, you can only create a sketch profile on a planar face that resides within its part. But the code above is accessing the component definition of the face as it's parent, ensuring that I am getting the correct component definition for the face.
Are faces not suitable for sketches? In Inventor's built-in "Start 2D Sketch" tool you can select a face on some geometry to create a sketch onto.
Any guidance into understanding why I cannot add a sketch to a face of a part would be greatly appreciated.
Solved! Go to Solution.
Download the prerelease of Hole Projector for Inventor 2027