From: Ben Eadie on
Thanks!

Now the macro cycles through all the drawings but the units do not
change? Actually any time I run my version of the macro and the original
version of the macro it cycles through the documents like it should but
it does not make any changes to the file... Any idea why?

Again you have been a ton of help Ken thank you! I have learned a lot.

Ben

Tin Man wrote:
> Ben,
>
> Just delete this line:
> Success = ModelDoc.SetUserPreferenceDoubleValue(7, 2699) ' kg/(cu
> meter)
>
> Set ModelDoc = swApp.OpenDoc2(Response, swDocPART, readOnly, viewOnly,
> silent, ReturnVal)
> Note the 'swDocPART', should I change this to 'swDocDRAWING'?
> <<<
> Yes you need to change it.
>
> Part.SetUserPreferenceIntegerValue swUnitsLinear, swINCHES
> Part.SetUserPreferenceIntegerValue swUnitsLinearDecimalDisplay,
> swFRACTION
> Part.SetUserPreferenceIntegerValue swUnitsLinearFractionDenominator, 16
>
> Part.SetUserPreferenceToggle swUnitsLinearRoundToNearestFraction, True
> Part.SetUserPreferenceIntegerValue swUnitsAngularDecimalPlaces, 0
> <<<
> Replace all of the "Part." with "ModelDoc."
>
> Ken
>
From: Tin Man on
Start a new macro. Delete all of the default stuff that is in the
macro. Paste the code below into the macro. Save the macro. Close the
macro. Run the macro.

If it doesn't work I have no idea what to tell you.
Ken

'**********************************************************
'
' batch open.swb - macro recorded on 01/14/00 by
' Joe Jones j...(a)nhcad.com
' New Hampshire CAD www.nhcad.com
'
' This program will do a batch OPEN / CHANGE DENSITY / SAVE / CLOSE
' to all part files ".SLDPRT" found in the working directory.
' With some simple modifications it could be used to batch plot
' or set a host of other user defined values.
'
' to run this program
' 1) start solidworks - do not open any part files
' 2) edit this macro to use the correct working direcotry
' (see "workDir" below)
' 3) run the macro
' ***************************************************************

Option Explicit
Dim swApp As Object
Dim ModelDoc As Object
Dim ReturnVal As Long
Dim Response As String
Dim DocName As String
Dim Success As Boolean
Dim DocType As String
Dim swDocTypeLong As Long

' *********** YOU MAY HAVE TO CHANGE THIS ***********
' change the following constant to target a directory
Const workDir = "C:\New Folder\"
' *********** YOU MAY HAVE TO CHANGE THIS ***********
' change the following constant to target a type of file
Const swDocType = ".SLDDRW" ' I am only want to open part files
' the following constants are used in the OpenDoc2() function
'Const swDocNONE = 0
'Const swDocPART = 1
'Const swDocASSEMBLY = 2
'Const swDocDRAWING = 3
Const readOnly = 0 ' 0-false 1-true
Const viewOnly = 0 ' 0-false 1-true
Const silent = 1 ' 0-false 1-true
' the following constants are used in the
' SetUserPreferenceDoubleValue() function

' start of main program
Sub main()
Set swApp = CreateObject("SldWorks.Application")
ChDir (workDir)
Response = Dir(workDir)
Do Until Response = ""
' see if filename ends with .SLDPRT
If Right(Response, 7) = swDocType Then

' open the SolidWorks file
If UCase$(swDocType) = ".SLDPRT" Then
swDocTypeLong = swDocPART
ElseIf UCase$(swDocType) = ".SLDASM" Then
swDocTypeLong = swDocASSEMBLY
ElseIf UCase$(swDocType) = ".SLDDRW" Then
swDocTypeLong = swDocDRAWING
Else
Stop 'Error Occured
End If
Set ModelDoc = swApp.OpenDoc2(Response, swDocTypeLong,
readOnly, viewOnly, silent, ReturnVal)

' add your own code here to do
' whatever you want to the part file
ModelDoc.SetUserPreferenceIntegerValue swUnitsLinear,
swINCHES
ModelDoc.SetUserPreferenceIntegerValue
swUnitsLinearDecimalDisplay, swFRACTION
ModelDoc.SetUserPreferenceIntegerValue
swUnitsLinearFractionDenominator, 16
ModelDoc.SetUserPreferenceToggle
swUnitsLinearRoundToNearestFraction, True
ModelDoc.SetUserPreferenceIntegerValue
swUnitsAngularDecimalPlaces, 0

' close the part
DoEvents

DocName = ModelDoc.GetTitle
ReturnVal = ModelDoc.Save2(silent)

swApp.CloseDoc DocName
Set ModelDoc = Nothing

End If
' get the next filename

Response = Dir
Loop

Set swApp = Nothing
End Sub