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
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
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
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
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