将 Solidworks 零件保存为 dxf 文件的宏

Macro for Saving Solidworks parts as dxf files

我必须从 solidworks 中保存大量 dxf 文件以用于 CNC 机床。

我正在寻求帮助来创建一个宏,以将零件的顶视图保存为 .dxf,保存位置与保存 solidworks 文件的位置相同。

我希望它首先保存 solidworks 零件,并替换任何现有的 dxf(如果该位置已保存同名的 dxf)。

我可以找到工程图文件和 sheet 金属零件的宏,但无法编辑它们以用于普通零件。

如果有人能指出正确的方向,我将不胜感激。

试试这个。

它将零件的俯视图导出为dxf

(改编自ExportToDWG2

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim sModelName As String
Dim sPathName As String
Dim varAlignment As Variant
Dim dataAlignment(11) As Double
Dim varViews As Variant
Dim dataViews(0) As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
sModelName = swModel.GetPathName
sPathName = Left(sModelName, Len(sModelName) - 6) & "dxf"
dataAlignment(0) = 0#
dataAlignment(1) = 0#
dataAlignment(2) = 0#
dataAlignment(3) = 1#
dataAlignment(4) = 0#
dataAlignment(5) = 0#
dataAlignment(6) = 0#
dataAlignment(7) = 0#
dataAlignment(8) = -1#
dataAlignment(9) = 0#
dataAlignment(10) = 1#
dataAlignment(11) = 0#
varAlignment = dataAlignment
dataViews(0) = "*Top"
varViews = dataViews
swPart.ExportToDWG2 sPathName, sModelName, swExportToDWG_e.swExportToDWG_ExportAnnotationViews, True, varAlignment, False, False, 0, varViews
End Sub