sketch command in vba

sketch command in vba

Anonymous
Not applicable
2,411 Views
7 Replies
Message 1 of 8

sketch command in vba

Anonymous
Not applicable

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

0 Likes
Accepted solutions (1)
2,412 Views
7 Replies
Replies (7)
Message 2 of 8

ekinsb
Alumni
Alumni

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
0 Likes
Message 3 of 8

Anonymous
Not applicable
.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.
0 Likes
Message 4 of 8

ekinsb
Alumni
Alumni
Accepted solution

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

Anonymous
Not applicable

can i select the plane?

not hardcode it...

0 Likes
Message 6 of 8

GosponZ
Collaborator
Collaborator

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

 

0 Likes
Message 7 of 8

ekinsb
Alumni
Alumni

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
0 Likes
Message 8 of 8

GosponZ
Collaborator
Collaborator

Can you make this one in iLogic

Thanks

0 Likes