Hide Table of Contents

Fire Notification After Adding a Mate Example (C#)

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


// ******************************************************************************


// Preconditions:

//    (1) Specified assembly document exists.

//    (2) The Tools > Options > Stop VSTA debugger on macro exit

//        check box is not selected.

//    (2) Run this macro in debug mode (press F5).

//    (3) Interactively add a mate between two entities

//        (Insert > Mate). For example, add a lock mate

//        between the plate and cup.


// Postconditions:

//    (1) A mate is added between the selected entities.

//    (2) A message box informing you of a new mate being

//        added to the assembly is displayed. Check the

//        taskbar for the message box.

//    (3) Close the message box.

//    (4) Close the document.


//        NOTE: Because this assembly document is used by

//              a SolidWorks online tutorial, do not save

//              any changes when closing the document.


//    (5) Stop the macro by clicking Debug > Stop Debugging.


// ******************************************************************************

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

using System.Windows.Forms;

using System.Collections;


namespace AddMatePostNotifyAssemblyDocCSharp.csproj


    public partial class SolidWorksMacro


        public AssemblyDoc swAssem;


        public void Main()


            ModelDoc2 swModel;

            int errors = 0;

            int warnings = 0;

            Hashtable openAssem;

            swModel = (ModelDoc2)swApp.OpenDoc6("C:\\Program Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\api\\toaster_scene.sldasm", (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);


            //Set up events

            swAssem = (AssemblyDoc)swModel;

            openAssem = new Hashtable();



        /// <summary>

        ///  The SldWorks swApp variable is pre-assigned for you.

        /// </summary>

        public SldWorks swApp;


        public void AttachEventHandlers()





        public void AttachSWEvents()


            swAssem.AddMatePostNotify += this.swAssem_AddMatePostNotify;



        public int swAssem_AddMatePostNotify()

        //Send message after user adds a mate


            MessageBox.Show("A mate has been added to the assembly.");

            return 1;





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 Notification After Adding a Mate Example (C#)
*   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) 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.