关于SW宏程序
昨天略微涉略SW宏程序,今天想整个一键出CAD及PDF的宏,奈何,不会设置宏读取图纸名称,再把红圈那设置成对应图纸名,以致出的CAD及PDF都是固定名称,有没有大佬知道咋先读取图纸名。感谢。描述一下你的需求, 工程图下导出PDF+DWF,部分宏
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Check to see if a drawing is loaded.
If (swModel Is Nothing) Or (swModel.GetType <> swDocDRAWING) Then
swApp.SendMsgToUser ("To be used for drawings only, Open a drawing first and then TRY!")
' If no model currently loaded, then exit
Exit Sub
End If
Set swDraw = swModel
Filepath = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\"))
If Dir(Filepath & "导出图纸", vbDirectory) = "" Then ' Change Sub folder Name here
MkDir Filepath + "导出图纸" ' Change Sub folder Name here
End If
Filepath = Filepath + "导出图纸\" ' Change Sub folder Name here
Set swCustPrpMgr = swModel.Extension.CustomPropertyManager("")
swCustPrpMgr.Get3 "", False, "", Value 'Change here the var revision "Rev"
FileName = Mid(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\") + 1)
FileName = Left(FileName, Len(FileName) - 7) & "" & Value & ".pdf"
swDraw.SaveAs3 Filepath & FileName & "", 0, 0
'-------------------------------------------------- SAVE DXF
Set swDraw = swModel
Filepath = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\"))
If Dir(Filepath & "导出图纸", vbDirectory) = "" Then ' Change Sub folder Name here
MkDir Filepath + "导出图纸" ' Change Sub folder Name here
End If
Filepath = Filepath + "导出图纸\" ' Change Sub folder Name here
Set swCustPrpMgr = swModel.Extension.CustomPropertyManager("")
swCustPrpMgr.Get3 "", False, "", Value 'Change here the var revision "Rev"
FileName = Mid(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\") + 1)
FileName = Left(FileName, Len(FileName) - 7) & "" & Value & ".DXF"
swDraw.SaveAs3 Filepath & FileName & "", 0, 0
swDraw.Save
'swApp.ExitApp '关闭SW软件
End Sub
宏怎么用都不知道:L 大兄弟aa 发表于 2024-3-21 15:42
宏怎么用都不知道
很强大,可以了解了解
本帖最后由 steve_suich 于 2024-3-22 11:25 编辑
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
Set part = swApp.ActiveDoc
If part.GetType = 3 Then
part.SaveAs (Left(part.GetPathName, InStrRev(part.GetPathName, "\")) & Left(part.GetTitle, Len(part.GetTitle) - 6) & ".PDF")
swApp.CloseDoc (part.GetTitle)
End If
End Sub
页:
[1]