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: 

add sketch on part's face by vba

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
skyngu
3349 Views, 6 Replies

add sketch on part's face by vba

hi,

 

I can add sketch on a part's workplane (xy, xz, yz) by using sketchs.add.

 

is there anyway i can select a face of part and create a new sketch?

 

thanks for any tips.

 

Autodesk Inventor Professional 2019
6 REPLIES 6
Message 2 of 7
jdkriek
in reply to: skyngu

Here's one method I use on Extruded parts, but hopefully you can gleem enough from it.

 

Sub Sketch2Face2()
'J.Kriek 2012
    Dim oApp As Application
    Set oApp = ThisApplication
    Dim oPart As PartDocument
    Set oPart = oApp.ActiveDocument
    Dim oCompDef As ComponentDefinition
    Set oCompDef = oPart.ComponentDefinition
    Dim oExtrude As ExtrudeFeatures
    Set oExtrude = oCompDef.Features.ExtrudeFeatures
    Dim oFaces As Faces
    
    'This can be changed to .SideFaces, .EndFaces, or .StartFaces
    'But .Faces will let you choose between all faces
    Set oFaces = oExtrude.Item(1).Faces
    
    Dim oSketch As PlanarSketch

    'Put a sketch on the first face (1) - change to suit
    Set oSketch = oCompDef.Sketches.Add(oFaces(1), True)
End Sub

 

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 3 of 7
skyngu
in reply to: jdkriek

thanks a lot.

 

I modified your code to fit my need. It works fine.

 

I don't understand how you get .sidefaces, endfaces to work. I have to test few times to get face right. in thise case is oFace(4)

 

Is there any way I always get top face of a face feature in sheet metal part?

Autodesk Inventor Professional 2019
Message 4 of 7
jdkriek
in reply to: skyngu

SideFaces, EndFaces, ect is only available for extruded features. When dealing with sheetmetal faces features you can only choose the item number. And yes unfortunately it's a guessing game as to which number that is depending on how the face was created.

 

However, I did have a crazy idea...

 

You can obtain the .BaseFace from the flat pattern and since it's a face feature it's going to be the top face. It will create the sketch in the folded. This worked for me, but try it out.

 

Sub Sketch2FlatFace()
'J.Kriek 2012
    Dim oApp As Application
    Set oApp = ThisApplication
    Dim oPart As PartDocument
    Set oPart = oApp.ActiveDocument

    Dim oSheetMetalComp As SheetMetalComponentDefinition
    Set oSheetMetalComp = oPart.ComponentDefinition
    
    'Make sure there is a flat pattern
    If oSheetMetalComp.HasFlatPattern = False Then
    
        'Create flat pattern
        Call oSheetMetalComp.Unfold
        
        'Switch back to Folded
        Set oDef = oApp.CommandManager.ControlDefinitions.Item("PartSwitchRepresentationCmd")
        Call oDef.Execute
    End If
    
    Dim oFlatpattern As FlatPattern
    Set oFlatpattern = oSheetMetalComp.FlatPattern

    'Edit the flat pattern
    Call oFlatpattern.Edit

    'Grab the BaseFace (Top) - can also be .BottomFace
    Dim oFace As Face
    Set oFace = oFlatpattern.BaseFace
    
    'Exit the flat pattern
    Call oFlatpattern.ExitEdit
    
    'Sketch on Top Face
    Dim oSketch As PlanarSketch
    Set oSketch = oSheetMetalComp.Sketches.Add(oFace, True)
    
    'Remove the flat pattern - optional
    'Call oFlatpattern.Delete
End Sub
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 5 of 7
skyngu
in reply to: jdkriek

well, mine is front face. so the sketch goes to my flange side whick is top face.

 

I did face feature on x-y plane.

 

thanks a lot. I learn something from it.

Autodesk Inventor Professional 2019
Message 6 of 7
akosi
in reply to: jdkriek

how to execute the 2d sketch command in vba?

Message 7 of 7
akosi
in reply to: skyngu

i want to select a face from a derived solid and project geometry to get a sketch.

 

can anybody help me with this?

 

thanksSmiley Happy

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

Post to forums  

Autodesk Design & Make Report