Setting the Referenced Documents in SW options

I'm trying to write a macro to solve a SW 2010 "bug" and not quite getting it working yet.  I need to setup all the users to point to a series of Referenced Documents folders in the SW options.  Using the swSettings file does not carry them over.  I even tried making a regestry file to add them and it does not work.  From what I can tell it was a problem in SW 2010 and we cannot update for ~4 more months (due to other factors inside the company).  It stinks to be this far behind but there are other factors in play here.  So I figured I would create a macro to do this for me and I started by recording the steps.  It records and gives me several boolean lines of code.  Even if I rereun that macro it will only add the last one in the list, weather it be a list of 2 or 22.  Anybody got any thoughts for me here?

Set swApp = Application.SldWorks

boolstatus = swApp.SetUserPreferenceStringValue(swUserPreferenceStringValue_e.swFileLocationsDocuments, "C:\\SolidWorks Data\\Pièces\\SOLIDPARTS\\Fasteners\\US Washers")

boolstatus = swApp.SetUserPreferenceStringValue(swUserPreferenceStringValue_e.swFileLocationsDocuments, "C:\\SolidWorks Data\\Pièces\\SOLIDPARTS\\Fasteners\\US Stud Weld")

End Sub

Thanks in advance for your thoughts

Tom

SolidworksApi macros
Answers 5
RJ
RJ 2012-03-28 Best Answer

Tom,

I am not sure if this is going to work but you can quickly try it.

In SW settings, if you want to set multiple files then your string should contain all the file names separated by a new line character. Thus, your new code becomes: -

Set swApp = Application.SldWorks

dim strFiles as string

strFiles = "C:\SolidWorks Data\Pièces\SOLIDPARTS\Fasteners\US Washers" & vbcrlf & "C:\SolidWorks Data\Pièces\SOLIDPARTS\Fasteners\US Stud Weld"

boolstatus = swApp.SetUserPreferenceStringValue(swUserPreferenceStringValue_e.swFileLocationsDocuments, strFiles)

End Sub

Please check that the 2 locations are separated by a new line character now. You can add more locations similarly.

Hope it helps!!!

Rajat Jain

TC
TC 2012-03-28

Rajat,

The code functions but it still puts all the folders on all one line in the Referenced Doc's setting in SW.

Thanks for the thought and idea.

Tom

WM
WM 2012-03-28

Try using a GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swFileLocationsDocuments) to see what the separator between the file names should be.

I just tested and the separator should be a semicolon ;

\

FV
FV 2012-03-28

Tom, you need to use a semicolon instead (character 59 of the ascii table).

Here's what the code should look like:


<p>Dim strFiles As String</p><p>strFiles = "C:\TEST\" & Chr(59) & "C:\SolidWorks Data\"</p><p>MsgBox(swApp.SetUserPreferenceStringValue(swUserPreferenceStringValue_e.swFileLocationsDocuments, strFiles))</p>

Hope this helps,

Filipe

FV
FV 2012-03-28

That's exactly what I was in the middle of doing just now!

Cheers