|
经典图书
參考
- '
- ' 工程圖(SLDDRW)批量另存為PDF及DWG文件
- '
- ' 測試版 2012 SP4 2018/12/4
- '
- Dim swApp As SldWorks.SldWorks
- Dim swModel As SldWorks.ModelDoc
- Dim Part As Object
- Dim sFileName As String
- Dim path As String
- Dim Name_ As String
- Dim nErrors As Long
- Dim nWarnings As Long
- Dim longstatus As Long
- Sub Main()
- Set swApp = Application.SldWorks
- Set swModel = swApp.ActiveDoc
- aa:
- path = InputBox("Enter a folder path containing any Solidworks files (For example '' C:\test\ '' )", "Parts path location") '鍵入處理文件之路徑
- sFileName = Dir(path & "*.slddrw") '取出檔名 *.slddrw
- n = 0
- Do Until sFileName = ""
- Set swModel = swApp.OpenDoc6(path + sFileName, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings) '開檔
- n = n + 1
- ' 另存成 DWG 及 PDF 檔~~~~~~~~~~~~~
- Name_ = Left(sFileName, Len(sFileName) - 7) '取出目前檔案的名稱(不含副檔名)
- For i = 1 To 2
- If i = 1 Then
- X_Path_Name = path & Name_ & ".DWG"
- Else
- X_Path_Name = path & Name_ & ".PDF"
- End If
- 'Debug.Print "File name: " & X_Path_Name
- Set Part = swApp.ActiveDoc
- longstatus = Part.SaveAs3(X_Path_Name, 0, 0) '儲存 DWG,PDF之文件
- Next
- swApp.CloseDoc swModel.GetTitle '關檔
- Set swModel = Nothing
- sFileName = Dir '同路徑取出下個檔名
- Loop
- Response = MsgBox("Press ''Yes'' key to continue ,Press ''No'' key to end.This path changes the Drawings Number= " & n, vbYesNo, "~~ Continue or End ~~")
- If Response = vbYes Then GoTo aa ' 若使用者按下 [是] 就再循環處理另個路徑的工程圖。
- End Sub
复制代码
|
|