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
'Part_Events_Study1
Option Explicit
Public swapp As SldWorks.SldWorks
Dim swPartEvents As Class1
Sub main()
Set swapp = Application.SldWorks
Set swPartEvents = New Class1
swPartEvents.Init
End Sub
SolidworksApi macros'Class1
Option Explicit
Public WithEvents swPart As SldWorks.PartDoc
Public Sub Init()
Set swPart = swapp.ActiveDoc
End Sub
Public Function swPart_AddItemNotify(ByVal EntityType As Long, ByVal itemName As String) As Long
Select Case EntityType
Case swNotifyConfiguration
With swPart
Debug.Print "swNotifyConfiguration", itemName
Dim swFace As SldWorks.Face2
Set swFace = .GetEntityByName("Blank Face", swSelFACES)
swFace.Select4 False, Nothing
'.FeatureManager.EditRollback swMoveRollbackBarToAfterFeature, _
"Folder1"
With .SketchManager
.InsertSketch (True)
.ActiveSketch.Name = .ActiveSketch.Name & "-" & itemName
End With
End With
Case swNotifyFeature
Debug.Print "swNotifyFeature", itemName, _
swPart.Extension.GetLastFeatureAdded().GetTypeName2
'TODO catch when sketch is added
'.....
End Select
End Function
Public Function swPart_DestroyNotify2(ByVal DestroyType As Long) As Long
Set swPart = Nothing
End Function