DSOFile beaten by SolidWorks Document Manager

January 9th, 2012


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!

Jeff Sweeney

CSWE Engineering Data Specialist 3DVision Technologies

Tags: , , ,

Loading Facebook Comments ...

6 Responses to “DSOFile beaten by SolidWorks Document Manager”

  1. Christopher Zona says:

    Jeff,

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

  2. Jeff Sweeney says:

    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. frank says:

    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.

  4. Jeff Sweeney says:

    The Document Manager is installed automatically if you’ve installed SolidWorks or eDrawings. Honestly, when I’ve needed it on a non-SW machine, I’ve just installed eDrawings, though I assume you can download it from some place? I just have never found it. For more info:
    http://help.solidworks.com/2012/English/api/swdocmgrapi/SolidWorks.Interop.swdocumentmgr_GettingStartedSWDocMgrAPI.html

  5. Jeff Sweeney says:

    You can find the Document Manager installer on the SolidWorks DVD.

Follow
Get every new post delivered to your inbox
Join other followers
Powered By WPFruits.com
Bear