Welcome
Collapse Getting StartedGetting Started
Overview
Expand Types of SolidWorks API ApplicationsTypes of SolidWorks API Applications
Expand SolidWorks API Object Model and Class HierarchySolidWorks API Object Model and Class Hierarchy
Collapse Programming with the SolidWorks APIProgramming with the SolidWorks API
Expand Add-insAdd-ins
API Dependent on SolidWorks Being Visible
Arrays
Attributes Imported from ACIS SAT Files
Bitmasks
Block Definitions and Block Instances
Bodies in Body Folders
BOOL and VARIANT_BOOL
Bounding Box and Note Text
COM vs. Dispatch
CommandManager and CommandGroups
Components, Configurations, and Suppression States
Compound Note
ComVisibleAttribute in VSTA macros
Controls, Visual Basic 6.0, and Windows XP
Expand Double Arrays and Integer PairsDouble Arrays and Integer Pairs
Drawing Views and Model Entities
Early and Late Binding
Collapse EventsEvents
Events
Programming Events
Features of Components
Helper Functions
Hole Wizard Features and Objects
IDispatch Object Arrays as Input in .NET
Implementation Guidelines
Import and Export File Options
In-process Methods
Instantiate ActiveX Controls as Tabs
Interface Pointers
Keystrokes and Accelerator Keys
Library Features and Objects
Lightweight Components
Line Attributes for View::GetPolyLinesAndCurves
Line Weights
Long vs. Integer
Expand Macro FeaturesMacro Features
Manipulators
Mass Properties
Expand Multibody PartsMultibody Parts
Option Explicit Statement
Partition Rollback and API Handles
Persistent Reference IDs
Presentation Transforms
Expand PropertyManager PagesPropertyManager Pages
.NET Interop Assemblies
Quick Tips and Bubble ToolTips
Return Values
Expand SafeArraysSafeArrays
Selection Criteria
Selection Lists
Selections that Define Features
Setup Project to Distribute SolidWorks Add-in
Smart Pointers
SolidWorks Objects
Sorting Tables
SQLite
STL Container Classes and Smart Pointers
Suspend Automatic Rebuilds
swdisp.cpp and swdisp.h Files
System Options and Document Properties
Tessellation and Edges
Tracking IDs
Expand Type LibrariesType Libraries
VBA and SolidWorks x64
Units
Unmanaged C+ and C++/CLI Code Differences
Examples and Projects
Expand SolidWorks API HelpSolidWorks API Help
Expand FeatureWorks API HelpFeatureWorks API Help
Expand SolidWorks Document Manager API HelpSolidWorks Document Manager API Help
Expand eDrawings API HelpeDrawings API Help
Expand SolidWorks Routing API HelpSolidWorks Routing API Help
Expand SolidWorks Simulation API HelpSolidWorks Simulation API Help
Expand SolidWorks Utilities API HelpSolidWorks Utilities API Help
Expand SolidWorks Workgroup PDM API HelpSolidWorks Workgroup PDM API Help
Hide Table of Contents

Programming Events

 

Code for all of these events, unless otherwise noted, can be automatically generated by the SolidWorks add-in wizards. See Events for additional information about these events.

C++

Typical steps for creating a C++ COM object that support events for a new SolidWorks interface are:

  1. Create a SolidWorks C++ add-in with the SolidWorks add-in wizard. SolidWorks recommends a non-attributed add-in that supports IModelView events (see the SwOptions tab).

  2. Study the model view event host COM object in DocView.h and DocView.cpp. You will create a similar one for another interface that supports events, such as IMouse.

  3. Create a new COM object class that derives from IDispEventImpl.

    1. Click Project > Add Class (e.g., MyMouseHandler).

    2. Click ATL > ATL Simple Object > Add button.

    3. Click Options > leave all default options selected > Finish button.

  1. Add a sink event map and a sink entry for each event you want to support. For example:
     

BEGIN_SINK_MAP(CSwMouse)

SINK_ENTRY_EX(ID_MOUSE_EVENTS, DIID_DMouseEvents, swMouseMoveNotify, MouseMoveNotify)

SINK_ENTRY_EX(ID_MOUSE_EVENTS, DIID_DMouseEvents, swMouseSelectNotify, MouseSelectNotify)

SINK_ENTRY_EX(ID_MOUSE_EVENTS, DIID_DMouseEvents, swMouseLBtnDownNotify, MouseLBtnDownNotify)

END_SINK_MAP())

 

VB.NET

Typical steps for creating a VB.NET COM object that supports events for a new SolidWorks interface are:

  1. Create a SolidWorks VB.NET add-in with the SolidWorks add-in wizard.

  2. Study the DocView class. You will create a similar one for another interface that supports events, such as IMouse.

  3. Create a new class to host your interface’s events (e.g. MyMouseHandler) and write an initialization function to store a reference to the main add-in object (e.g., IMouse), and the add-in’s document event handler (as shown in EventHandling.vb)

  4. Write methods to call the .NET AddHandler to associate class methods with the events on the events (e.g., IMouse events). Call these methods in your initialization code when your add-in is loaded.
     

     



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:   Programming Events
*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) 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.