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: 

sketch command in vba

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
akosi
2170 Views, 7 Replies

sketch command in vba

hi

 

can someone help me on how to activate/execute 2dsketch command using vba?

it would be identical to just pressing the sketch button.

 

i need the code to add to the macro im creating.

 

thanks

7 REPLIES 7
Message 2 of 8
ekinsb
in reply to: akosi

Try this:

Public Sub ActivateSketch()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    ' Get the sketch to activate.  This
    ' uses the name of the sketch.
    Dim sk As Sketch
    Set sk = partDoc.ComponentDefinition.Sketches.item("Sketch1")
    
    ' Bring the sketch into edit mode.
    sk.Edit
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 8
akosi
in reply to: ekinsb

.your code need the part to have existing sketch, am i right?

i need to do the 1st sketch , thats why i need to be able to launch the sketch command using vba.
Message 4 of 8
ekinsb
in reply to: akosi

In order to active a sketch, it needs to exist. If you need to activate a sketch that doesn't exist, you'll first need to create it, which means you'll need some planar entity to create it on.  This can be a work plane or a planar face on the model.  Here's a version of the previous program that creates a new sketch on the X-Y base work plane and then activates it.

Public Sub ActivateSketch()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    ' Create a new sketch on the X-Y base work plane.
    Dim sk As Sketch
    Set sk = partDoc.ComponentDefinition.Sketches.Add( _
             partDoc.ComponentDefinition.WorkPlanes.item(3))
    
    ' Bring the sketch into edit mode.
    sk.Edit
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 8
akosi
in reply to: ekinsb

can i select the plane?

not hardcode it...

Message 6 of 8
GosponZ
in reply to: akosi

I edit rule for i logic and working perfect. I fixed for x-z plane .

 

Message 7 of 8
ekinsb
in reply to: akosi

Here's an example that allows you to select the plane.  It can be either a planar face on the part or a work plane.

 

Public Sub NewSketchOnPlane()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    ' Create a new sketch on a selected face.
    Dim planarEntity As Object
    Set planarEntity = ThisApplication.CommandManager.Pick(kAllPlanarEntities, _
                                                        "Select a face or work plane.")
    Dim sk As sketch
    Set sk = partDoc.ComponentDefinition.Sketches.Add(planarEntity)
    
    ' Bring the sketch into edit mode.
    sk.Edit
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 8
GosponZ
in reply to: ekinsb

Can you make this one in iLogic

Thanks

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

Post to forums  

Autodesk Design & Make Report