Syndicate content

SolidWorks API Tips

How to create the user modeless dialog in my SolidWorks add-in?

March 9, 2010
Sometimes you need to create the user modeless dialog in your SolidWorks add-in.

Form::Show method shows the dialog in separate window so it made background on activating new window.

There are two ways to make this dialog as a child Window of SolidWorks:

1) Use the wrapper class that implements IWin32Window and pass it's pointer to Form::Show method.

2) Use Windows API Function: SetParent

To retrieve the handle of SolidWorks Window call IFrame::GetHWnd method.

You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialize correctly.

How to create a temporary geometry?

December 15, 2009
This tip describes how you can create a temporary geometry

Often it is necessary to create some temporary geometry for example for preview purposes.

You can generate a temporary SolidWorks geometry using the IModeler Interface.

To display this body call the Body2::Display3 method.

To hide the body just set its pointer to NULL.

You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialize correctly.

A C# add-in problem: The property Manager Page is declared in a separate DLL

December 2, 2009
Usually while creating a SolidWorks Add-in project, it is more convenient to move the Property Manager Page Interfaces to separate DLL-library.

However, sometimes an "Invalid Cast Exception" message appears in such .NET-applications.

The problem here is the visibility of the assembly. The DLL must be COM-visible. Go to Project Properties -> Assembly Information and then check the "Make Assembly COM-visible" box.

Another issue that can cause this exception is a class access modifier. The PMPage handler class must be declared 'Public' in order to avoid this problem.

You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialize correctly.

How to create a feature in a part that is being edited in the context of an assembly

November 24, 2009
Usually it is more convenient to create or modify some geometry of a component directly in the context of an assembly.

The SolidWorks API provides the proper solution. Using the AssemblyDoc::EditPart2 method we set the selected component into edit mode and are able to use regular IFeatureManager interface's APIs for generating the geometry.

To exit the "Edit Part" mode use the AssemblyDoc::EditAssembly method.

The following video demonstrates a general technique of working in context of assembly.

You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialize correctly.

Retrieving the version of SW that is currently active on your computer

November 12, 2009
Sometimes you need to look the version of SW that is currently active on your computer. You can easily do it using the SldWorks::RevisionNumber method.

This method returns the application revision number string in the major.minor.minor form

Use the table below to identify Versions and Service Packs of SolidWorks by their revision numbers.

1.X.Y All SolidWorks executables prior to the SolidWorks 2000
8.X.Y SolidWorks 2000 SPX.Y
9.X.Y SolidWorks 2001 SPX.Y
10.X.Y SolidWorks 2001Plus SPX.Y
11.X.Y SolidWorks 2003 SPX.Y
12.X.Y SolidWorks 2004 SPX.Y
13.X.Y SolidWorks 2005 SPX.Y
14.X.Y SolidWorks 2006 SPX.Y
15.X.Y SolidWorks 2007 SPX.Y
16.X.Y SolidWorks 2008 SPX.Y
17.X.Y SolidWorks 2009 SPX.Y
18.X.Y SolidWorks 2010 SPX.Y

How to edit the value of a specific dimension

October 28, 2009
In most cases if you want to modify geometry of any feature, it is more convenient to edit the value of a specific dimension directly using Dimension::SetSystemValue3 method instead of editing the definition of the feature with Feature::ModifyDefinition method.

The easiest way to retrieve a pointer to the corresponding dimension is via ModelDoc2::Parameter method that identifies them by name.

Similarly to options available in User Interface, the Dimension::SetSystemValue3 method allows you to modify dimensions in a specific configuration or in all configurations.

For example:

...
swModel.Parameter("D1@Extrude1").SetSystemValue3 0.1, swSetValueInConfiguration_e.swAllConfiguration, ""
...

You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialize correctly.