DSOFile beaten by SOLIDWORKS Document Manager

Hey macro lovers! Have to change a lot of SOLIDWORKS file properties, but don’t want your code to have to open each file one at a time?

Most web searches are going to point you to use Microsoft’s DSOFile. It’s a good solution, but using it means you need to install it on your client machines (and watch out there is a 32 and 64 bit version out there!) or create a release package. Neither option is very fun if you are just writing a quick SOLIDWORKS macro.

Luckily, the SOLIDWORKS Document Manager is a great option. It gives you write access to many properties inside of a SOLIDWORKS file.

Add “SwDocumentMgr 20XX Type Library” to the list of your macro’s references and your wish is the Document Manager’s command.

refs

IMHO, the documentation is a very “tedious” so here is a little VBA snippet showing how easy this COM object is. This snippet will add the custom property “Material” to the file and assign it the value “Adamantium”:

Dim swDoc As SwDMDocument12
Dim swDM As SwDMApplication
Dim mOpenErrors As SwDmDocumentOpenError
Dim objClassfac As SwDMClassFactory
Set objClassfac = CreateObject("SwDocumentMgr.SwDMClassFactory")
Set swDM = objClassfac.GetApplication(<This is a string/key that you need to request from SolidWorks>)
Set swDoc = swDM.GetDocument(strDocFileName, SwDmDocumentType.swDmDocumentPart, False, mOpenErrors)
swDoc.AddCustomProperty "Material", SwDmCustomInfoType.swDmCustomInfoText, "Adamantium"
swDoc.Save
swDoc.CloseDoc

Just as easy as DSOFile, and more powerful -if you are wanting to update configuration specific properties, DSOFile is going to let you down.

DSOFile is still the best tool for working with file properties of other OLE type (read: Office) documents but when it comes to SOLIDWORKS documents, all the cool kids are using the SOLIDWORKS Document Manager.

By the way, if you are looking for a way to impress your date, read more about the Document Manager. It gives you more control over your SOLIDWORKS files than just messing with file properties. With it you can write applications that emulate file management tools to perform such tasks as renaming, replacing, and copying SOLIDWORKS documents -you don’t even have to have SOLIDWORKS installed!

  • Share this
Find Your Design Solution in the CATI Store.
Browse Products