没关系,伙计们,我设法找到了它的代码。
- Dim swApp As SldWorks.SldWorks
- Dim swModel As SldWorks.ModelDoc2
- Dim swDraw As SldWorks.DrawingDoc
- Dim swCustProp As CustomPropertyManager
- Dim valOut As String
- Dim valOut1 As String
- Dim valOut2 As String
- Dim resolvedValOut As String
- Dim resolvedValOut1 As String
- Dim resolvedValOut2 As String
- Dim Filepath As String
- Dim FileName As String
- Dim ConfigName As String
- Sub main()
- Set swApp = Application.SldWorks
- Set swDraw = swApp.ActiveDoc
- ' Check to see if a drawing is loaded.
- If (swDraw Is Nothing) Or (swDraw.GetType <> swDocDRAWING) Then
- ' If no model currently loaded, then exit
- Exit Sub
- End If
- Set swView = swDraw.GetFirstView
- Set swView = swView.GetNextView
- Set swModel = swView.ReferencedDocument
- ConfigName = swView.ReferencedConfiguration
- Set swCustProp = swModel.Extension.CustomPropertyManager(ConfigName)
- swCustProp.Get2 "NewPartNo", valOut, resolvedValOut 'Change the custom property name here
- swCustProp.Get2 "AssyDescription", valOut1, resolvedValOut1 'Change the custom property name here
- swCustProp.Get2 "CurrentRev", valOut2, resolvedValOut2 'Change the custom property name here
- Filepath = "C:\Drawings"
- FileName = Left(swDraw.GetTitle, Len(swDraw.GetTitle) - 9)
- swDraw.SaveAs (Filepath + resolvedValOut + " - " + resolvedValOut1 + " - Rev" + resolvedValOut2 + ".PDF") 'Change the custom property text here
- MsgBox resolvedValOut + " - " + resolvedValOut1 + " - Rev" + resolvedValOut2 + " Saved as a PDF"
- End Sub
|