Hide Table of Contents

Fire Notifications for Background Processing Events Example (VBA)

This example shows how to fire notifications when background processing events occur.

' Preconditions:
' 1. Create a form, UserForm1, that contains the following controls:
'    * CheckBox1 with caption Enable background processing and open drawing
'    * CommandButton1 with caption Close after background processing end event fires
' 2. Copy this code to the main module.
' 3. Copy this code to UserForm1.
' 4. Modify the path in UserForm1's code to point to a large drawing document
'    containing many parts.
' 5. Open the Task Manager, click the Processes tab, and click the
'    CPU column header to sort the processes in descending order.
' 6. Run this macro to show UserForm1.
'    a. Select Enable background processing and open drawing.
'       1.   Enables background processing for the application.
'       2.   Opens the specified drawing document.
'       3.   Fires background processing start event.
'    b. In Task Manager, observe that several sldbgproc.exe processes
'       are occupying most of the CPU.
'    c. After several seconds, observe that the sldbgproc.exe processes stop,
'       and the background processing end event fires.
'    d. Click Close after background processing end event fires.
'       UserForm1 unloads.
' Postconditions: Inspect the Immediate window for background processing
' event notifications.

'Main module

Option Explicit

Sub main()

     UserForm1.Show vbModeless

End Sub

'UserForm1 Code

Option Explicit

Private WithEvents swApp As SldWorks.SldWorks

Private Sub CheckBox1_Click()

    Set swApp = Application.SldWorks
    swApp.EnableBackgroundProcessing = CheckBox1.Value

    Dim filePath As String
    filePath = "path_to_large_drawing"
    Dim docSpecification  As DocumentSpecification
    Set docSpecification = swApp.GetOpenDocSpec(filePath)
    docSpecification.Silent = True

    Dim swmodelDoc As ModelDoc2
    Set swmodelDoc = swApp.OpenDoc7(docSpecification)
    Dim swDrawingDoc As DrawingDoc
    Set swDrawingDoc = swmodelDoc

    ' Set document background processing to application setting
     swDrawingDoc.BackgroundProcessingOption = 2
End Sub

Private Function swApp_BackgroundProcessingStartNotify(ByVal filename As String) As Long
    Debug.Print "Background processing start event fired."
End Function

Private Function swApp_BackgroundProcessingEndNotify(ByVal filename As String) As Long
    Debug.Print "Background processing end event fired."
    swApp.EnableBackgroundProcessing = False
End Function

Private Sub CommandButton1_Click()
    Unload UserForm1
End Sub


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 Notifications for Background Processing Events Example (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) 2015 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.