SHOPPING CART
SHOPPING CART
Engineer analyzing a 3D CAD model of a car wheel on a computer monitor in an office setting

Top 5 Commonly Used Interfaces in the SOLIDWORKS API

Table of Contents

In a previous post, we discussed the SOLIDWORKS Object Model and how its hierarchical structure impacts the way you access API functionality in SOLIDWORKS. But how do you find what you need within the hundreds of interfaces and functions within the API?

Fortunately, you don’t need to know all – or even most – of the API in order to start doing useful things.

Here are the top five commonly used SOLIDWORKS interfaces and functions that will get you up and running:

1. ISldWorks for Connecting to SOLIDWORKS Application

The top-level SldWorks interface is accessed automatically when a new macro is created. The auto-generated β€œSet swApp = Application.SldWorks” line makes this initial connection and gives the macro access to doing things like opening, closing, creating, and saving documents, turning toolbars on and off, and loading and unloading add-ins.

Almost anything you want to do within the SolidWorks application requires first connecting to the ISldWorks interface.

2.Β  ModelDoc2 for Working with SOLIDWORKS Documents

The IModelDoc2 interface is exposed by the ISldWorks interface. This interface (also referred to as the ModelDoc2 object) gives the macro access to things like rebuilding a document and adding configurations. ModelDoc2 also exposes several other interfaces (see below) that can be used to create and modify features and sketches.

The following is an example of an implementation of the ModelDoc2 object:

Dim swApp As SldWorks.SldWorks
Set swApp = Application.SldWorks

Dim swModel As ModelDoc2
Set swModel = swApp.ActiveDoc

In this example, the variable swModel is used to store a reference to the active SOLIDWORKS document’s ModelDoc2 interface. This step isn’t always strictly necessary, but typing swModel.function is easier than having to type out swApp.ActiveDoc.function every time.

3.Β  IModelDocExtension for Accessing More Document Tools

The ModelDocExtension object is, as it sounds, an extension of the ModelDoc2 object. ModelDocExtension was created because objects have a limited number of methods and properties that are allowed. The ModelDoc2 object reached its capacity, so the SOLIDWORKS software engineering team created ModelDocExtension to define more things that would otherwise belong to ModelDoc2.

ModelDocExtension is exposed by the IModelDoc2 interface, meaning that it is accessed in the following manner:

Dim swDocExt As ModelDocExtension
Set swDocExt = swModel.Extension

These statements assume that swModel has been declared as a ModelDoc2 object and assigned to a valid SOLIDWORKS document (both of which are done in the previous example). ModelDocExtension controls functionality like adding custom properties, getting mass properties, and adding BOM and revision tables.

4.Β  IFeatureManager for Controlling Features & the Feature Tree

The IFeatureManager interface is exposed by the ModelDoc2 object, just like the IModelDocExtension interface. This means that its implementation is almost identical:

Dim swFeatMgr As FeatureManager
Set swFeatMgr = swModel.FeatureManager

The FeatureManager object controls things normally done in the Feature Manager Tree when using the graphical user interface.

Examples include editing and creating features, hiding and showing solid bodies, and changing the rollback state of the Feature Manager Tree.

5.Β  ISketchManager for Accessing Sketch Tools

As the name suggests, the SketchManager object allows your macro to access sketch tools for creating sketches and sketch entities. It is also exposed by the ModelDoc2 object, so its implementation looks something like this:

Dim swSketchMgr As SketchManager
Set swSketchMgr = swModel.SketchManager

The Final Note

Hopefully, this short list of commonly used interfaces gives you a better sense of how the SOLIDWORKS Object Model is organized and what terms you might need to search for in the SOLIDWORKS API Help File to find more functions to use.

You can search the API Help File for β€œ_______ interface” (fill in the blank with one of the interfaces above) ini SOLIDWORKS and see the first search result for a full list of properties and methods that you can access through each of the above objects.

If you’re interested in the SOLIDWORKS API, make sure to check out the webinars and blogs:

We’re here to help if you have questions. Contact us.

Picture of Hawk Ridge Systems Resource Hub

Hawk Ridge Systems Resource Hub

It often takes a team to solve a problem – and sometimes it takes a team to write about it. The Hawk Ridge Systems Engineering Team is comprised of our Product Managers, Applications Engineers, and Support Engineers. They've collaborated on this article to bring you the most accurate information about the solutions you use for design and manufacturing.

Register Now

Thank you for registering! A confirmation email is on its way. Please check your spam folder if you did not receive one. See you soon!

While you are waiting, check out our Resource Center or read our Blog!

success

Register Now

Thank you for registering! A confirmation email is on its way. Please check your spam folder if you did not receive one. See you soon!

While you are waiting, check out our Resource Center or read our Blog!

success

Register Now

Thank you for registering! A confirmation email is on its way. Please check your spam folder if you did not receive one. See you soon!

While you are waiting, check out our Resource Center or read our Blog!

success

Get Your Download Today!

Thank you for registering! A confirmation email is on its way. Please check your spam folder if you did not receive one. See you soon!

While you are waiting, check out our Resource Center or read our Blog!

success