The SOLIDWORKS Object Model + API explained (part 1)

The SOLIDWORKS 2023 API has 445 interfaces.

It’s impossible to know and understand them all. But once you know the basics, you should be able to figure out the rest.

To help you get started, I am writing down everything I know.

All blog posts in this series

  1. The SOLIDWORKS Object Model + API explained
  2. SOLIDWORKS API: the basics - SldWorks, ModelDoc2
  3. How to work with Features 
  4. Persistent ID and sketch segment ID and more
  5. All identifiers in the SOLIDWORKS API
  6. About return values
  7. Entities and GetCorresponding
  8. How to work with selections
  9. How to use custom properties
  10. Understanding math, MathVector and MathTransform
  11. Toolbars, menus and the Command Manager
  12. How to create task panes and Property Manager Pages
  13. How to create your own SOLIDWORKS add-in
  14. Creating add-ins with SolidDNA: the basics

I will add links to the posts when I finish them. Follow CAD Booster on LinkedIn or via our newsletter to get notified of new posts.

In this blog post, you’ll find

  1. What is the SOLIDWORKS Object Model?
  2. What are properties and methods?
    1. Properties
    2. Methods
  3. How to read the documentation to understand the Object Model
  4. Understanding the help pages for interfaces
    1. .NET Syntax
    2. Example
    3. Remarks
    4. Accessors
    5. Access diagram
    6. See also
    7. Knowledge base

1. What is the SOLIDWORKS Object Model?

Microsoft has a great explanation of what an Object Model is:

Developers organize programming objects in a hierarchy, and that hierarchy is called the object model of the application. Word, for example, has a top-level Application object that contains a Document object. The Document object contains Paragraph objects and so on. Object models roughly mirror what you see in the user interface. They are a conceptual map of the application and its capabilities.

The object model is a fancy name for the structure and relations between different object types. In the case of the SOLIDWORKS API, we have a top-level SldWorks object, the application itself. From that object, you get the current model and from the model, you can get features and other properties.

2. What are properties and methods?

Every object in the SOLIDWORKS API has properties and methods. Together, we call them members.

Properties

A property is something that the object has, it does not have to be calculated.  A property has a value that you can get and often you can also set it. If you cannot set the property, the documentation will say so.

solidworks object model properties get set

Methods

A method performs an action on an object. This allows you to change the object, to perform an action on it, anything’s possible.

The image below shows the first methods of the SldWorks object, but there are hundreds. A method you will often use is ActivateDoc3, which makes a loaded model the visible, active model.

isldworks methods

Ditch the Toolbox, once and for all

Start using the fastener library that actually follows the standards
  • No more mate errors
  • Made for speed
  • No yearly license fees

3. How to read the documentation to understand the Object Model

There are three ways to find the thing you need in the documentation:

  1. Start from the top document (which includes subtopics like motion study and DimXpert) or from the list of interfaces (for the SOLIDWORKS API only)
  2. Using the search box at the top right
  3. Or my favorite: from your own list of bookmarks

solidworks object model bookmarks

4. Understanding the help pages for interfaces

Say you have this page about the ISldWorks interface:

sldworks interface in object model

.NET Syntax

This section is pretty useless.

Example

This list may contain useful examples, usually in a couple of different languages. The examples are usually cluttered with lines for opening the right file, but they can be helpful if you are just getting started with a topic.

Remarks

The most useful section. It contains explanations of all the weird quirks of this object. If you can’t figure something out, go read this section a couple of times.

Accessors

Every interface except the ISldWorks interface has a list of accessors. The image below shows the first few ways how to get a ModelDoc2 object, there are lots more ways.

It shows you how you can get that object, how to access it. So if you know which interface you need, but don’t know how to get there, check out the list of accessors and work back from there.

solidworks api accessors

Access diagram

Link to the 400+ page PDF with the complete Access Diagram in the object model. The link directly leads you to the correct page.

The image below shows the SldWorks object and the first six objects you get access to from it.

solidworks api access diagram

See also

The top link in this list is the most useful. It leads you to the list of members, aka properties and methods. This is the page that I bookmark, not the interface page.

The other links are related interfaces.

Knowledge base

Entirely at the bottom, there’s a “Search ‘ISldWorks Interface’ in the SOLIDWORKS Knowledge Base.” section. I have never found this useful because there’s no real knowledge stored in the Knowledge Base.

search solidworks knowledge base

All blog posts in this series

  1. The SOLIDWORKS Object Model + API explained
  2. SOLIDWORKS API: the basics - SldWorks, ModelDoc2
  3. How to work with Features 
  4. Persistent ID and sketch segment ID and more
  5. All identifiers in the SOLIDWORKS API
  6. About return values
  7. Entities and GetCorresponding
  8. How to work with selections
  9. How to use custom properties
  10. Understanding math, MathVector and MathTransform
  11. Toolbars, menus and the Command Manager
  12. How to create task panes and Property Manager Pages
  13. How to create your own SOLIDWORKS add-in
  14. Creating add-ins with SolidDNA: the basics

Mis geen enkele post. Krijg een gratis add-in.

Schrijf je in voor onze nieuwsbrief en je krijgt onze TimeSavers add-in cadeau.