|
大神帮忙出个一键转PDF,DWG,STEP,,带路径选择的,在程序里改路径也行!
Dim swApp As Object '让程序以相同的文件名把PDF/DXF/STEP文件保存在指定的文件夹内
Dim swdraw As SldWorks.DrawingDoc
Dim drawcom As DrawingComponent
Dim compenent As Component2
Dim part As Object
Dim swview As View
Dim Filename As String
Dim No As Integer
Dim Title As String
Dim configname As String
Sub main()
Dim partname As String
Set swApp = Application.SldWorks
Set swdraw = swApp.ActiveDoc
Set swview = swdraw.GetFirstView
Set swview = swview.GetNextView
Set part = swview.ReferencedDocument
configname = part.ConfigurationManager.ActiveConfiguration.Name
Filename = part.GetPathName()
No = Len(Filename)
Filename = Left(Filename, No - 7)
partname = Get_Property_value(part, "零件号")
leibie = Get_Property_value(part, "零件类别")
Title = Right(Filename, Len(Filename) - InStrRev(Filename, "\"))
swdraw.SaveAs3 Filename & ".DWG", 0, 0
part.SaveAs2 Filename & ".STEP", 0, True, False
swdraw.SaveAs2 Filename & ".PDF", 0, True, False
X = MsgBox(" 一键转图 " & vbCrLf & " 已保存为 PDF/DWG/STEP 文件 ", 0)
End Sub
Public Function Get_Property_value(swDoc As ModelDoc2, Property_Name As String) As String
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim val As String '属性值
Dim valout As String '属性评估值
Dim bool As Boolean
Set swModelDocExt = swDoc.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager(configname) '从配置里获取属性值
'Set swCustProp = swModelDocExt.CustomPropertyManager("") '从自定义属性里获取属性值
bool = swCustProp.Get4(Property_Name, False, val, valout)
Get_Property_value = valout
End Function
这是之前用的,一键转三种格式,只能在原来文件夹保存 |
|