Hide Table of Contents

Fire Notifications for Background Processing Events Example (VB.NET)

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

'----------------------------------------------------------------------------
' Preconditions:
' 1. Create a VSTA VB.NET macro.
'    a. Copy and paste SolidWorksMacro.vb's code in the macro.
'    b. Create a form, Form1, that contains the following
'       controls:
'       * CheckBox1 with caption, Enable background processing and open
'         drawing.
'       * Button1 with caption, Close after background processing end event 
'         fires.
'    c. Copy and paste Form1.vb's code in your form's code window. 
'    d. Modify the path in Form1.vb to open a huge drawing document that
'       contains many parts.
' 2. Press F5 to start and close the debugger.
' 3. Click Build > Build macro_name to build a DLL for the macro. 
' 4. Save and close the macro.
'
' Postconditions:
' 1. Open the Windows Task manager, click the Processes tab, and click the CPU column
'    header to sort the processes in descending order.
' 2. In SolidWorks, click Tools > Macro > Run.
'    a. Locate your macro's \SwMacro\bin folder.
'    b. Select macro_name.dll.
'    c. Click Open.
'       The form opens.
' 3. Select the Enable background processing and open drawing checkbox on the form.
'    A checkmark is displayed in the check box.
' 4. Click OK to close the Background processing enabled message box. 
' 5. The specified drawing opens.
'    Background processing start events fires.
' 6. Click OK to close the Background processing start event fired message box.
' 7. In the Windows Task Manager, observe that several sldbgproc.exe processes are
'    occupying most of the CPU.
' 8. Click OK to close the Background processing end event fired message box.
' 9. Click Close after background processing end event fires button on the form.
'    Form1 unloads.
'----------------------------------------------------------------------------------
 
'SolidWorksMacro.vb
Imports SolidWorks.Interop.sldworks
Imports System.Runtime.InteropServices
Imports System
 
Partial Public Class SolidWorksMacro
 
    Public swApp As SldWorks
 
    Public Sub Main()
 
        'Create and show an instance of the form
        Dim myForm As New Form1
        myForm.Show()
 
    End Sub
 
End Class
'Form1

Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Windows.Forms
Imports System.Diagnostics
Imports System.Collections
Imports System.Runtime.InteropServices
 
Public Class Form1
 
    Public WithEvents swApp As SldWorks
    Public checkBoxClicked As Boolean
 
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.ObjectByVal e As System.EventArgsHandles CheckBox1.CheckedChanged
 
        Try
            swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks)
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
 
        Dim swModelDoc As ModelDoc2
        Dim swDrawingDoc As DrawingDoc
 
        Dim filePath As String
        filePath = "Path_and_filename_of_huge_drawing"
 
        Dim docSpecification As DocumentSpecification
 
        ' Set up events
        AttachEventHandlers()
 
        ' Enable background processing
        swApp.EnableBackgroundProcessing = True
        MsgBox("Background processing enabled")
 
        ' Open huge drawing
        docSpecification = swApp.GetOpenDocSpec(filePath)
        docSpecification.Silent = True
        swModelDoc = swApp.OpenDoc7(docSpecification)
 
        swDrawingDoc = swModelDoc
 
        ' Set document background processing to application setting
        swDrawingDoc.BackgroundProcessingOption = swBackgroundProcessOption_e.swBackgroundProcessing_DeferToApplication
 
    End Sub
 
    Sub AttachEventHandlers()
        AttachSWEvents()
    End Sub
 
    Sub AttachSWEvents()
        AddHandler swApp.BackgroundProcessingStartNotifyAddressOf Me.mySwApp_BackgroundProcessingStartNotify
        AddHandler swApp.BackgroundProcessingEndNotifyAddressOf Me.mySwApp_BackgroundProcessingEndNotify
    End Sub
 
    Private Function mySwApp_BackgroundProcessingStartNotify(ByVal filename As StringAs Integer
        MsgBox("Background processing start event fired")
    End Function
    Private Function mySwApp_BackgroundProcessingEndNotify(ByVal filename As StringAs Integer
        MsgBox("Background processing end event fired")
        swApp.EnableBackgroundProcessing = False
    End Function
    Public Sub CheckBox1_Click(ByVal sender As ObjectByVal e As System.EventArgsHandles CheckBox1.Click
        checkBoxClicked = True
    End Sub
    Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button1.Click
        Close()
    End Sub
End Class


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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Fire Notifications for Background Processing Events Example (VB.NET)
*Comment:  
*   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:

x

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
x

Web Help Content Version: API Help (English only) 2014 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.