Hide Table of Contents

Fire Notification After Adding a Mate Example (VB.NET)

This example shows how to fire a post-notify event when adding mates.

'-----------------------------------------------------------
' Preconditions:
' 1. Verify that the specified assembly to open exists.
' 2. Click Tools > Options > clear the Stop VSTA debugger 
'    on macro exit check box if it is selected.
' 3. Open the Immediate window.
'
' Postconditions:
' 1. Opens the assembly.
' 2. Interactively add a mate between two entities
'    (Click Insert > Mate). For example, add a lock mate
'    between the plate and cup.
' 3. Adds a mate between the selected entities.
' 4. Examine the Immediate window.
' 5. Click Debug > Stop Debugging in SOLIDWORKS Visual
'    Studio Tools for Applications.
' 6. Click Tools > Options > Stop VSTA debugger on macro exit
'    check box in SOLIDWORKS.
'
' NOTE: Because this assembly is used elsewhere, do not save
' changes.
'-----------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics
Imports System.Collections
 
Partial Class SolidWorksMacro
 
    Public WithEvents swAssemblyDoc As AssemblyDoc
 
    Public Sub Main()
        Dim swModel As ModelDoc2
 
        Dim errorstatus As Long, warningstatus As Long
        Dim openAssem As Hashtable
 
        ' Open assembly document
        swApp.OpenDoc6("C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\api\toaster_scene.sldasm", swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errorstatus, warningstatus)
        swModel = swApp.ActiveDoc
 
        ' Set up event
        swAssemblyDoc = swModel
        openAssem = New Hashtable
        AttachEventHandlers()
 
    End Sub
 
    Sub AttachEventHandlers()
        AttachSWEvents()
    End Sub
 
    Sub AttachSWEvents()
        AddHandler swAssemblyDoc.AddMatePostNotify, AddressOf Me.swAssemblyDoc_AddMatePostNotify
    End Sub
 
    Private Function swAssemblyDoc_AddMatePostNotify() As Integer
        Debug.Print("A mate was added to the assembly.")
    End Function

    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
 
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 Notification After Adding a Mate 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) 2018 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.