Hi Forum
I'm using the holidays to invest in a bit of API study, it's great! - no ones bothering me
I'm currently looking at using events
Specifically in this case I am trying to create a new sketch when the user adds a configuration.
I would then like to pass control back to the user so they can create the sketch
I will then pick up the new sketch has been created and do some more stuff
At first it appears to work fine, however there is something wrong.
The sketch entities are not displayed and the sketch is empty - eg a rectangle
It gets added to the tree, but will be deleted if it is again edited
Here's my debug.print that shows somethings working
swNotifyConfiguration A
swNotifyFeature Sketch3-A ProfileFeature
swNotifyConfiguration B
swNotifyFeature Sketch3-B ProfileFeature
swNotifyConfiguration C
swNotifyFeature Sketch3-C ProfileFeature
and heres the code,,, macro attached. I use 2016
The macro selects a face called "Blank Face" , so I also attach a simple sample file
<p>'Part_Events_Study1</p><p>Option Explicit</p><p>Public swapp As SldWorks.SldWorks</p><p>Dim swPartEvents As Class1</p><p></p><p>Sub main()</p><p> Set swapp = Application.SldWorks</p><p> Set swPartEvents = New Class1</p><p> swPartEvents.Init</p><p>End Sub</p>
<p>'Class1</p><p>Option Explicit</p><p></p><p>Public WithEvents swPart As SldWorks.PartDoc</p><p></p><p>Public Sub Init()</p><p> Set swPart = swapp.ActiveDoc</p><p>End Sub</p><p></p><p>Public Function swPart_AddItemNotify(ByVal EntityType As Long, ByVal itemName As String) As Long</p><p> </p><p> Select Case EntityType</p><p> Case swNotifyConfiguration</p><p> With swPart</p><p> Debug.Print "swNotifyConfiguration", itemName</p><p> </p><p> Dim swFace As SldWorks.Face2</p><p> Set swFace = .GetEntityByName("Blank Face", swSelFACES)</p><p> swFace.Select4 False, Nothing</p><p> </p><p> '.FeatureManager.EditRollback swMoveRollbackBarToAfterFeature, _</p><p> "Folder1"</p><p> With .SketchManager</p><p> .InsertSketch (True)</p><p> .ActiveSketch.Name = .ActiveSketch.Name & "-" & itemName</p><p> End With</p><p> End With</p><p> </p><p> Case swNotifyFeature</p><p> Debug.Print "swNotifyFeature", itemName, _</p><p> swPart.Extension.GetLastFeatureAdded().GetTypeName2</p><p> 'TODO catch when sketch is added</p><p> '.....</p><p> End Select</p><p> </p><p>End Function</p><p></p><p>Public Function swPart_DestroyNotify2(ByVal DestroyType As Long) As Long</p><p> Set swPart = Nothing</p><p>End Function</p>SolidworksApi macros