Hide Table of Contents

Fire Events When PropertyManager Page Opened and Canceled (VBA)

This example shows how to get the SolidWorks command ID, PropertyManager title, and whether the user interface is active. Events are fired before the PropertyManager page is opened and when it is canceled.

Main module

' Preconditions:
' 1. Specified model document exists.
' 2. Add a reference to SolidWorks <version> 
'    commands type library.
' 3. Open the Immediate window.
' 4. Run the macro.
' Postconditions:
' 1. Specified file opened.
' 2. CommandOpenPreNotify event fired.
' 3. Fillet PropertyManager page opened.
' 4. Title of PropertyManager page, whether the
'    user interface is active, and whether the command ID
'    is a fillet, are printed to the Immediate window.
' 5. Interactively click the X on the Fillet
'    PropertyManager page to cancel it. 
' 6. CommandCloseNotify event fired.
' 7. Interactively close the model document.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim modelName As String
Dim errors As Long
Dim warnings As Long
Dim commandID As Long
Dim pmpTitle As String
Dim isUIActive As Boolean
Dim swAppEvents As New Class1
Sub main()
Set swApp = Application.SldWorks
' Set up event
Set swAppEvents.swApp = swApp
' Open the model
modelName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\fillets\knob.sldprt"
Set swModel = swApp.OpenDoc6(modelName, swDocPART, swOpenDocOptions_Silent, "", errors, warnings)
Set swModelDocExt = swModel.Extension
' Open the Fillet PropertyManager Page,
' which causes the CommandOpenPreNotify event
' to fire
swModelDocExt.RunCommand swCommands_Fillet, "Fillet"
' Get the command ID if the command is a fillet,
' get the PropertyManager page title if one is active,
' and get whether the user interface is active
swApp.GetRunningCommandInfo commandID, pmpTitle, isUIActive
If pmpTitle <> "" Then Debug.Print "Title of PropertyManager page: " & pmpTitle
Debug.Print "Is user interface active? " & isUIActive
If (commandID = 9) Then
    Debug.Print "Command ID: " & "swCommands_Fillet"
    Debug.Print "Command ID: " & "Not a fillet."
End If
End Sub


Class Module

Option Explicit
Public WithEvents swApp As SldWorks.SldWorks
Private Function swApp_CommandOpenPreNotify(ByVal command As Long, ByVal userCommand As Long) As Long
    'Send message when the Fillet PropertyManager page is about to open
    If (command = swCommands_e.swCommands_Fillet) Then MsgBox "Fillet PropertyManager page is about to open."
End Function
Private Function swApp_CommandCloseNotify(ByVal command As Long, ByVal reason As Long) As Long
    'Send message because the Fillet PropertyManager page was canceled by clicking the X button
    MsgBox "Fillet PropertyManager page was canceled."
End Function


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Fire Events When PropertyManager Page Opened and Canceled (VBA)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2012 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.