Selective Open Post-Notify Event Example (VBA)
This example shows how to handle the post-notification event that fires when
components are selected for Quick View/Selective Open.
'------------------------------------------------------
' Preconditions:
' 1.
Create main module with Main module code.
' 2.
Insert Class1 module with Class1 module code.
' 3.
Specified file to open exists.
' 4.
Run macro (F5).
'
' Postconditions:
' 1.
When prompted, select components to open.
' 2.
A message box displays.
' 3.
Click OK.
' 4.
Only the selected components display.
' 5.
Inspect the Immediate Window.
'--------------------------------------------------------------------------
' Main module
'--------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDocSpecification As SldWorks.DocumentSpecification
Dim swAssemblyEvents As Class1
Dim swAssembly As SldWorks.AssemblyDoc
Option
Explicit
Sub main()
Set
swApp = Application.SldWorks
Set
swDocSpecification = swApp.GetOpenDocSpec("C:\Program Files\SOLIDWORKS
Corp\SOLIDWORKS\samples\tutorial\advdrawings\bowl and chute.sldasm")
swDocSpecification.InteractiveComponentSelection
= True
swDocSpecification.DocumentType
= swDocASSEMBLY
Set
swModel = swApp.OpenDoc7(swDocSpecification)
Set
swModel = swApp.ActiveDoc
Set
swAssembly = swModel
'
Set up event
Set
swAssemblyEvents = New Class1
Set
swAssemblyEvents.swAssembly = swAssembly
End Sub
'---------------------------------------------------------------------------------------
' Class1 module
'---------------------------------------------------------------------------------------
Public WithEvents swAssembly As SldWorks.AssemblyDoc
Private Function swAssembly_SelectiveOpenPostNotify(ByVal
NewAddedDisplayStateName As String, SelectedComponentNames As Variant)
As Long
MsgBox
"A post-notification event has been fired for the selective open."
Debug.Print
"New display state name: " & NewAddedDisplayStateName
Debug.Print
"Selected component names:"
Dim
i As Long
For
i = 0 To UBound(SelectedComponentNames)
Debug.Print
" "
& SelectedComponentNames(i)
Next
End Function