Download 3DExperience World Presentations

3DExperience World, formerly known as SOLIDWORKS World, has come and gone. We exhibited at booth 118 and had a fantastic time meeting hundreds of you from around the world. Keith Rice, our Technical Director, presented three times on SOLIDWORKS API topics. You can download the files for the presentations below:
<> Macros vs Addins vs Stand-Alones – [files][video]
<> SOLIDWORKS API for Total Beginners – [files][video]
<> Write A SOLIDWORKS Addin From Scratch – [files]
If you missed us and want to chat, please reach out to us.
See you next year in Nashville!
If you want to stay up with more great content, be sure to join our newsletter.
New PDM Product: Convert DWG Task

Overview
CADSharp is partnering with EhCanadian and is pleased to present one their flagship products, “Convert DWG Task”. Formerly called, “Convert With DraftSight”, Convert DWG Task is a SOLIDWORKS PDM task add-in that converts DWG files to PDF and DXF. This program comes with its own built-in PDF generator but also supports DraftSight and AutoCAD scripting.
SOLIDWORKS includes a DWG to PDF add-in using DraftSight but its functionality is quite limited compared to Convert DWG Task, as you can see in the table below.
| Features Comparison | DRAFTSIGHT | OUR ADDIN |
| Output file in or out of vault type | ||
| Variables in the filename | ||
| Secondary output paths | ||
| Secondary output paths can be relative | ||
| Duplicate file handling | ||
| Create reference from the destination file | ||
| Custom menu command | ||
| Use DraftSight for conversion | ||
| Use AutoCAD or AutoCAD LT for conversion | ||
| Includes built-in PDF generator | ||
| VB.NET scripting | ||
| C# scripting | ||
| Page setup by default, layout, block, file name, etc | ||
| Export all or specific sheets | ||
| Export sheets based on file name or sheet name | ||
| Export sheets to one or seperate PDFs | ||
| Ignore model layout when exporting all | ||
| Combine all PDFs from the task into one file | ||
| Full API for scripting | ||
| Watermark PDF on export with image or text | ||
| Apply password protection to PDFs | ||
| Separate email notifications with PDF attachments | ||
| Email notification supports SSL | ||
| Full logging |
Requirements
- SolidWorks EPDM/PDM Professional.
- DraftSight or AutoCAD must be installed on the computer running the task if you’re using scripting.
- .NET 4.5 is required, so as of version 201, this add-in will not run on EPDM 2013 and earlier.
Pricing
999 USD sign-up fee, followed by 150 USD per year
Please visit EhCanadian for more details.
Want to keep up with new CADSharp product offerings like Convert DWG Task? Sign up for our newsletter.
How To Read / Write Third-Party Storage
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.
Arguments:
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:
- IModelDocExtension::IGet3rdPartyStorageStore method using SolidWorks API &
- ISwDMDocument19.Get3rdPartyStorageStore
Arguments:
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
CADSharp.com 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.

