Instructions
Opens all documents in a folder and saves them as parasolid to the same folder.
- Preconditions
- SolidWorks is open.
Files
Save all parts in a folder as parasolid
Code
Module: mMain
'Opens all part documents in a folder and saves them as parasolids to the same folder.
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
'Preconditions: SolidWorks is open.
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swApp = Application.SldWorks
If swApp.GetDocumentCount <> 0 Then
MsgBox "Please close all documents before running macro."
Exit Sub
End If
Dim strFolder As String
Dim strFileName As String
Dim intCount As Integer
intCount = 0
strFolder = GetFolder
If strFolder = Empty Then Exit Sub
strFileName = Dir(strFolder & "*.sldprt", vbNormal)
Do While strFileName <> ""
'open file
swApp.OpenDoc6 strFolder & strFileName, swDocPART, 0, "", Empty, Empty
Set swModel = swApp.ActiveDoc
'save out as parasolid
Dim strExtension As String
strExtension = Right(strFileName, 6)
swModel.Extension.SaveAs strFolder & Replace(strFileName, strExtension, "x_t"), swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, Empty, Empty
'close doc
swApp.CloseDoc Empty
'get the next file in the directory
strFileName = Dir
intCount = intCount + 1
Loop
MsgBox "Finished exporting " & intCount & " documents."
End Sub
Private Function GetFolder() As String
Dim strInput As String
strInput = InputBox("Please enter the folder containing the parts you wish to export to parasolid.")
If strInput = Empty Then
GetFolder = Empty
Else
If Right(strInput, 1) <> "\" Then strInput = strInput & "\"
GetFolder = strInput
End If
End Function