How To Read / Write Third-Party Storage

Blog 8.1.2019 No Comments

Often-times developers will need to store information inside a model that should not be exposed to the user in any way. While attributes might solve this need, the downside is that attributes are designed to hold only string and numeric data, and usually not large quantities of either of these.

Enter third-party storage. These allow developers to store complex data of any amount, including binary streams (i.e., serialization), into the model for use by third-party macros, addins, and stand-alones. (I have never seen a macro use third-party storage, but is possible.) Morever, this third-party storage can be sub-divided into “folders” called “third-party storage stores”, allowing the developer to create an organized structure of third-party storage data. By analogy you can think of third-party storage and third-party storage store in the same way you think of files and folders in your operating system.

Case Study

I needed a customer’s models to always contain the input data that the addin would use to process the models correctly. Otherwise I would have to constantly remind them to send me that input data, because they regularly forgot. Since my addin used an Inputs class to store all of the input data, the addin would serialize the input data and store it in the third-party storage of the model being processed. If the model failed and the customer needed to send it to me for debugging, I could open up the model in a special debugging mode that would extract the Inputs class and automatically apply the inputs for that model into the addin’s user interface. As you can imagine, this is saving me quite a bit of time and headache as I continue developing the addin.

See “Developer Tools and Examples” below for information on how to see an example of this study.

Using Third Party Storage

Third Party Storage is used when application only needs to read and write a single data structure, whether it be binary, text, xml, etc. You can access a document’s third-party storage using the SOLIDWORKS API or Document Manager API:

Both of these methods return an IStream object, which you can read or write to.


string StringIn – Name of the third-party storage. The name should be less than 30 characters and must be unique and qualified among all of the software parties storing within the current session.
boolean IsStoring – True if writing the data, false if reading the data.

Using Third Party Storage Store

Third-party storage store is used when a hierarchy of storage is necessary and/or when only certain data is required to be accessed at certain time. Third-party storage store will allow to create sub storage store and sub storage and only certain sub storage or sub store can be accessed without loading whole storage store. Third-party storage store is managed by IStorage interface and is obtained using the SOLIDWORKS API and Document Manager API:


SubStorageName – Name of the third-party storage store.
IsStoring – True if writing the data, false if reading the data.

Reading / Loading Data

When a document is opened in SolidWorks, external application receives LoadFromStorageNotify event if event handler is registered. When LoadFromStorageNotify event is raised, it is safe to call IModelDoc2::IGet3rdPartyStorage method to read the data from steam or IModelDocExtension::IGet3rdPartyStorageStore method to read the data from storage store. When the document is fully loaded in SolidWorks, both methods can be called anytime to read the data. However, if is not a good idea to call these methods when FileSaveNotify or FileSaveNotify2 events are raised as conflicts can occur.

Visit SolidWorks API help for more information about Part, Assembly and Drawing document’s LoadFromStorageNotify delegate.

ISwDMDocument19::Get3rdPartyStorage and ISwDMDocument19::Get3rdPartyStorageStore methods can be called anytime even if the document is open in SolidWorks to read the data. All of the above methods will return NULL if the storage or storage store is never saved in the SolidWorks document.

IModelDoc2::IRelease3rdPartyStorage method must be called after IModelDoc2:: IGet3rdPartyStorage method, IModelDocExtension::IRelease3rdPartyStorageStore method must be called after IModelDocExtension::IGet3rdPartyStorageStore method, ISwDMDocument19::Release3rdPartyStorage method must be called after ISwDMDocument19::Get3rdPartyStorage method and ISwDMDocument19::Release3rdPartyStorageStore method must be called after ISwDMDocument19::Get3rdPartyStorageStore method even if application fails to obtain storage or storage store, otherwise storage or storage store may remain locked and prevent future access.

Writing / Storing Data

Writing to Third Party Storage using IModelDoc2::IGet3rdPartyStorage method or Third Party Storage Store using IModelDocExtension::IGet3rdPartyStorageStore is only possible when document is being saved and SaveToStorageNotify event is raised. In an active session, if data needs to be stored to Third Party Storage or Third Party Storage Store, use IModelDoc2::SetSaveFlag method to flag the model as dirty which will prompt the user to save the document if the user tries to close the document without saving the changes. If user clicks YES, SaveToStorageNotify event will be raised and data will be stored to Third Party Storage or Third Party Storage Store. SaveToStorageNotify event can also be raised programmatically using IModelDoc2::Save3 method.

Visit SolidWorks API help for more information about Part, Assembly and Drawing document’s SaveToStorageNotify delegate.

ISwDMDocument19::Get3rdPartyStorage and ISwDMDocument19::Get3rdPartyStorageStore can be called anytime to store the data as long as the document is not ready-only or locked. Document must be saved and closed afterwards. If you want to avoid using event handlers in your addin but want to write to the storage of an open document, you can set the document’s read-write state to read-only using IModelDoc2::SetReadOnlyState.

It is not required but recommended that IModelDoc2::IRelease3rdPartyStorage method is called after IModelDoc2:: IGet3rdPartyStorage method, IModelDocExtension::IRelease3rdPartyStorageStore method is called after IModelDocExtension::IGet3rdPartyStorageStore, ISwDMDocument19::Release3rdPartyStorage method is called after ISwDMDocument19::Get3rdPartyStorage method and ISwDMDocument19::Release3rdPartyStorageStore method is called after ISwDMDocument19::Get3rdPartyStorageStore.

IStream::Commit method should not be called during storing the data to Third Party Storage or Third Party Storage Store otherwise Method not Implemented exception will be thrown.

Deleting Third Party Storage / Store

Currently, Third Party Storage and Third Party Storage Store can only be deleted from the document using Document Manager API.

Use ISwDMDocument20::Delete3rdPartyStorage(string StringIn) method to delete Third Party Storage from the document and ISwDMDocument20::Delete3rdPartyStorageStore(string SubStorageName) method to delete Third Party Storage Store from the document. The document must not be ready-only or locked and must be saved and closed afterwards. Both methods return boolean value (True or False) indicating the success or failure.

Developer Tools and Examples Power Users have access to these tools and examples:

  • CADSharpTools is a powerful library for using the SOLIDWORKS API and Document Manager API more easily. This library includes CTDocumentManager and CTSerialization, which when used together can allow you to easily replicate the solution described in the case study described earlier.
  • ThirdPartyStorage is the name of an addin created by CADSharp and hosted on our BitBucket, which Power Users can learn how to access here. This example demonstrates how to replicate the solution described in the case study described earlier.

SOLIDWORKS users who have a SOLIDWORKS license with an active subscription (available through a reseller) can access the following example by Scott Stanley, which demonstrates how to use third-party storage in VB.NET and C++.

Thanks for reading and let us know if you have any questions in the comments below.

Want to keep up with future content and training events? Sign up for our newsletter.

Leave Comment

The Power of the PDM API Explained: Part 1

Blog 5.14.2019 No Comments

This is the first post in a series PDM management and integration by Guy Edkins. If you have any need for SOLIDWORKS PDM customization, do not hesitate to contact us.

When SOLIDWORKS Corporation purchased Conisio (the creators of EPDM) in 2006, it quickly become the mainstay of file management for SOLIDWORKS files. PDM Workgroup, the first file manager for SOLIDWORKS, simply could not hold up in the face of rapid business globalization. Sharing files across countries and continents became the principal downfall for companies trying to share large amounts of data across multiple sites in Workgroup PDM.

SOLIDWORKS EPDM was rebranded in late 2016 to PDM Standard and PDM Professional with PDM Workgroup being deprecated and replaced by PDM Standard. Standard and Professional are both SQL-based tools which lends a higher level of all around capability to the platform.

Today PDM Professional is SOLIDWORKS primary tool for SOLIDWORKS file management. Additionally, PDM Pro can manage just about any file type equally as well as it can SOLIDWORKS files. Companies around the world now rely on PDM Pro to provide document management for multiple departments across multiple disciplines. The operative word in the last sentence is document. Make no mistake: PDM Pro, while an expansive product is a document manager, is not a records manager as is the case with any standard PLM system such as Agile, Windchill, or TeamCenter. That being said, a large niche for PDM Pro exists in the enterprise environment.

Twenty-five years ago as a consultant to engineering industry, I was often asked by clients, How do we choose the right data management software? My answer has not changed one bit from those days: buy the best tool that fits your primary needs and has a robust, sophisticated API to allow customization. Further, I would prefer a tool that uses accepted industry standards. A company can rarely go wrong under these guidelines.

Industrial software of any kind rarely provides 100% of the needed functionality out of the box. Even if it does provide the functionality, it might not provide it in an efficient manner. Hence the need to integrate business systems using an API. This where SOLIDWORKS PDM Professional shines.

Consider PDM from an integration standpoint. First and foremost, PDM Pro runs on top of Microsoft SQL Server. MS SQL is now number two behind Oracle in total sales of RDBMS, although in 2016 MS SQL grew faster than Oracle did: 10.3% versus 3.3%. Consequently, it is safe to say PDM Pro is running on an established standard database technology. PDM is a Microsoft OS only tool and therefore runs in an established operating system. This alone gives it great flexibility as far as interacting with the OS and other MS toolsets.

The real crown jewel of PDM, however, is its API: a rich programming library that allows companies to customize at will and integrate PDM with their business systems, creating seamless data transmission and removing any need for double data entry within an enterprise. If the API doesn’t contain the tools necessary, many times data can be read from SQL database directly. As a result, the possibilities are endless for integrations with other systems, whether passing single fields of data found in PDM data cards to passing entire PDM BOMs to MRP and ERP systems. Even linking PDM to the newer cloud based business and PLM systems is possible with via web services, typically utilizing REST technology.

CADSharp has created numerous integrations for our customers within the PDM environment. From task addins to complex web services integrations, each piece of software we write one has increased efficiencies across departments and resulted in immediate bottom-line savings. In the coming months this blog will highlight some of the integrations specifically. Stay tuned!

How has the SOLIDWORKS Professional PDM API benefited you? Let us know in the comments!

Want to keep up with future content and training events? Sign up for our newsletter.

Leave Comment

What’s New In the 2019 SOLIDWORKS API

Blog 3.4.2019 No Comments

Another year, another round of great updates for the SOLIDWORKS API. Although I’m not going to change the title of this blog series, this post is also going to contain updates for the PDM API and Document Manager API as well. Anyway, the continual improvement of these APIs should give amateur and professional developers confidence that SOLIDWORKS Corporation is investing in their API for the long-haul.

Below are lists of the most notable API calls and interfaces added in the 2019 versions of SOLIDWORKS, PDM, and Document Manager. You can see all additions and their related API calls in the Release Notes article in the API Help. You can find it in the local API Help by searching for “Release Notes” in the category tab. Note that the local API Help Release Notes will only be as up-to-date as the service pack you have downloaded.

New SOLIDWORKS API Calls and Interfaces
  • Access Bounding Box feature data.
  • Access Ground Plane feature data.
  • Access Tab and Slot feature data.
  • Convert an existing balloon to a stacked balloon.
  • Create a geodesic sketch offset along the curvature of a surface.
  • Create a pattern feature with a smaller subset of parameters and then extend or modify
    it using a pattern-specific feature data object.
  • Create an assembly mate with a smaller subset of parameters and then extend or
    modify it using a mate-specific feature data object.
  • Get a component’s suppression state or, if an internal ID mismatch exists, an error
  • Get an annotation’s text scale in the 3D View.
  • Get data from the Hole Wizard database.
  • Get or set more properties on linear, linear component, and circular component pattern
  • Get or set more table column types, including the equation-driven type.
  • Get or set the orientation of text in table cells.
  • Get or set whether an angle or distance mate is a limit mate.
  • Get or set whether to bidirectionally project a curve.
  • Get or set whether to enable the pushpin of an add-in’s callout.
  • Get or set whether to enable the Select Identical Components menu item in the
    context menu of a PropertyManager page selection box.
  • Get or set whether to exclude a component from the bills of materials in specified
  • Get or set whether to generate a display list for a part’s configuration.
  • Get or set whether to load external references in memory when opening a document.
  • Get or set whether to reverse the direction of a specified reference of a reference plane
  • Get the error status of an assembly mate.
  • Insert a Delete Hole feature for selected hole edges on a surface.
  • Insert, open, and update models developed in other CAD packages.
  • Repeatedly detect collisions among groups of components in a variety of
  • Specify whether to include a specified component when saving an assembly as a part.
New PDM API Calls and Interfaces

New API calls

  • Add users by login type to the vault. See IEdmUserMgr10::AddUsers3.
  • Get whether a specified user must add a state change comment for specified workflow transitions for specified documents. See IEdmVault20::GetTransitionCommentPermissions.
  • Get specified files from a vault. See IEdmVault20::GetFiles.
  • Get the archive server log. See IEdmVault20::GetArchiveServerLog.

New structure

  • EdmDocIds. Contains information about one document in the vault. Used in IEdmVault20::GetFiles.
New Document Manager API Calls and Interfaces

New API calls

  • ISwDMDocument23::GetLicenseType

Improved API calls

  • ISwDMConfiguration16::GetCutListItems (obsoletes ISwDMDocument13::GetCutListItems2)
  • ISwDMConfigurationMgr2::GetConfigurationByName2 (obsoletes
  • ISwDMConfigurationMgr::GetConfigurationByName)
  • ISwDMConfigurationMgr2::GetConfigurationCount2 (obsoletes ISwDMConfigurationMgr::GetConfigurationCount)
  • ISwDMConfigurationMgr2::GetConfigurationNames2 (obsoletes ISwDMConfigurationMgr::GetConfigurationNames)
VSTA 1.0 End-Of-Life Announcement

VSTA 1.0, which was the only way a developer could create .NET macros up until SOLIDWORKS 2018, is going to be replaced entirely by VSTA 3.0 macros in SOLIDWORKS 2021, meaning that SOLIDWORKS 2020 is the last version that will support VSTA 1.0. I wrote about my opinion about VSTA 3.0 last year but I’ll reiterate here what I said then: I have no intention of using VSTA / .NET macros anymore. Its so much simpler to just set up a stand-alone sandbox if one needs to test .NET code.

Anyway, if you want to hear the official announcement concerning VSTA 1.0, it was delivered by Daniel Seaman of SOLIDWORKS Corporation in his presentation “Upgrading SOLIDWORKS Macros to Visual Studio Tools for Applications 2015”. This is the same presentation he delivered at SOLIDWORKS World 2018, FYI. I am not sure when they will post the video of this year’s presentation (if it was even recorded) so here are the instructions for watching his 2018 presentation:

1. Visit the SolidWorks World 2018 agenda
2. Search the Sessions tab for the name “Seaman”
3. The result for “Upgrading SOLIDWORKS Macros to Visual Studio Tools for Applications 2015” should appear and you can click Watch Video on the right (requires a free account)

Does anything we’ve covered stand out to you as particularly useful or exciting? If so then let us know in the comments!

Want to keep up with future content and training events? Join our newsletter!

Leave Comment