DSOFile beaten by SOLIDWORKS Document Manager

EmailFacebookGoogle+LinkedInTwitterShare

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!

6 comments on “DSOFile beaten by SOLIDWORKS Document Manager

  1. Jeff,

    After reading this article, I was wondering how this differs from the Task Scheduler by using the Update Custom Properties option?

  2. The task scheduler is a good tool. I’ll often use it for quick and dirty applications. However:

    A. It is slower, it opens each file one at a time to update the properties, (this can be an issue depending on how many files you are updating). Neither the DSOFile nor Document manager needs to open the files.

    B. The task scheduler has no ability for you to add any logic. All chosen file properties will have the same value. As an example, you couldn’t have one value added for a purchased part and another for a manufacturer part. Or “Take the first two characters of the file name, then if it is for this customer add the letter “M” unless it is in this directory then use a “R” …”

  3. Where do I get the SOLIDWORKS Document manager? I have a pretty extensive DSOfile Excel VBA program, but I’m really interested in renaming, replacing solidworks files.

Comments are closed.