Using the SolidWorks COM Non-Attributed Add-in Wizard
to Create a C++/CLI Add-in
This topic describes how to use the SolidWorks
COM Non-Attributed Add-in Wizard to create Visual C++/CLI add-ins in
Microsoft Visual Studio .NET 2005 or later.
NOTES:
- The SolidWorks COM
Non-Attributed Add-in Wizard is included in the SolidWorks
API SDK.
- The Visual C++/CLI Add-in allows the use of MFC objects.
Creating a Visual C++/CLI Add-in
Using the SolidWorks COM Non-Attributed Add-in Wizard
Click Start > Programs
> Microsoft Visual Studio version_number > Microsoft
Visual Studio version_number.
Click the New
Project button.
Select Visual C++
> SolidWorks
COM Non-Attributed Addin from the templates list.
Enter the name of your project in Name.
-
Enter the directory of your project in Location.
Click OK.
Type the name of your add-in in Short
name. The other fields are automatically filled in using this name.
Click Options.
Under Threading,
select the threading option for the project.
Under Interface,
select whether or not to add the oleautomation
attribute to your code by selecting Automation
Compatible.
Click SwOptions.
Under AddinEvents,
select the events for which you want to listen:
SolidWorks
Events. Fired by the SolidWorks application.
Part
Events. Fired by individual part documents.
Assembly
Events. Fired by individual assembly documents.
Drawing
Events. Fired by individual
drawing documents.
Model
View Events. Fired by individual model views in each document.
It is recommended that you leave the SolidWorks Events check box selected
because:
Model views are created in individual documents.
To listen for a model view event, you must be listening to the basic document.
Thus, the Model View Events check
box is not available until you select at least one of these check boxes:
Part Events, Assembly
Events, or Drawing Events.
Under Addin
User Interface, select Create
Property Page to include an add-in PropertyManager page. This page
is displayed in the SolidWorks application and should contain controls
to extend the add-in's user interface.
Click Finish.
Wait for the SolidWorks COM Non-Attributed
Addin Wizard to
customize your add-in and set up the project.
Back
to top
Examining Visual C++/CLI Add-In Files Created by the SolidWorks COM Non-Attributed
Add-in Wizard
C++ Add-in File |
Description |
SwAddinn.rgs |
This file contains the information that automatically
registers your
add-in with SolidWorks when it is compiled. You can change Name
and Description to better indicate the purpose of your add-in.
NOTE: SwAddinn.rgs is the generic name for this file. The
letter n
is automatically inserted and incremented by the wizard to make the
project files unique. |
BitmapHandler.cpp and corresponding .h file |
Images for COM add-ins (toolbars, bitmap buttons, and so
on) are bitmaps stored in the DLL as resources. To use any of these
images with SolidWorks, you must retrieve the image and save it to a
file. You can then pass the path to the file as an argument to the
methods that use the image. The BitmapHandler object facilitates this
effort.
To use the BitmapHandler object, call CreateFileFromResourceBitmap
and pass it the resource name of the image you want to retrieve. The
function creates the file in the system's temporary folder and returns
the full path. If you then pass this path to a method, SolidWorks can
load the image. |
CSwAddinnDialog.cpp and corresponding .h file |
This file is included to demonstrate compatibility with MFC. |
DocView.cpp and corresponding .h file |
This file contains the definition of the DocView object. If
an add-in
is listening for ModelView events, then there is a DocView instance for
each open ModelView. |
PMPageHandler.cpp and corresponding .h file |
This file contains the class that implements the
IPropertyManagerPage2Handlern interface. An instance of this
object is passed to SolidWorks when creating a PropertyManager page.
When a control on the page is manipulated, the corresponding function in
this object is called. |
stdafx.cpp and corresponding .h file |
This file contains the #import statements for the
SolidWorks type libraries and any other necessary SolidWorks #include
statements.
Because a PropertySheet member exists in the VC7 libraries,
IModelDoc2::PropertySheet was redefined to IModelDoc2::SwPropertySheet
in the #import statement for sldworks.tlb. |
SwAddinn.cpp and corresponding .h file |
This is the main add-in file. It contains the
implementation of the
ISwAddin interface.
ISwAddin::ConnectToSw and ISwAddin::DisconnectFromSw are the entry and
exit functions for this add-in. This file also contains the user
interface and SolidWorks event callback functions.
NOTE: SwAddinn.cpp is the generic name for this file. The
letter n
is automatically inserted and incremented by the wizard to make the
project files unique. |
SwAddinn.def |
This file declares DLL function exports. |
SwAddinn.idl |
This file is used to generate the type library for the
add-in. |
SwAddinn_module.cpp |
Generated by Visual Studio, this file contains COM
definitions for the DLL. |
SwDocument.cpp and corresponding .h file |
This file contains the CSwDocument class that handles
events thrown
by open model documents. There is an instance of this class for every
open model document. |
UserPropertyManagerPage.cpp and corresponding
.h file |
This file contains the wrapper class for the SolidWorks
IPropertyManagerPage2. A PropertyManager page allows you to extend the
user interface for your add-in with standard buttons, check boxes, and
so on.
The function AddControls controls the layout of the PropertyManager
page. All controls must be added to group boxes on the page. Group boxes
are displayed in the order in which they are added. Controls in a group
box are displayed in the order in which they are added to the group box. |
Back
to top