以下代码为API VBA源码,在下部倒数第二个参数是钣金输出选项,参见API帮助。以下代码略加修改可以做成批量处理工具。我用VB.NET写的代码给你应该没什么用如下图。
VBA代码:
- 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(1) As String
- Dim options As Long
- Sub main()
- Set swApp = Application.SldWorks
- Set swModel = swApp.ActiveDoc
- sModelName = swModel.GetPathName
- sPathName = swModel.GetPathName
- sPathName = Left(sPathName, Len(sPathName) - 6)
- sPathName = sPathName + "dwg"
- Set swPart = swModel
- dataAlignment(0) = 0#
- dataAlignment(1) = 0#
- dataAlignment(2) = 0#
- dataAlignment(3) = 1#
- dataAlignment(4) = 0#
- dataAlignment(5) = 0#
- dataAlignment(6) = 0#
- dataAlignment(7) = 1#
- dataAlignment(8) = 0#
- dataAlignment(9) = 0#
- dataAlignment(10) = 0#
- dataAlignment(11) = 1#
- varAlignment = dataAlignment
- dataViews(0) = "*Current"
- dataViews(1) = "*Front"
- varViews = dataViews
- 'Export each annotation view to a separate drawing file
- swPart.ExportToDWG2 sPathName, sModelName, swExportToDWG_ExportAnnotationViews, False, varAlignment, False, False, 0, varViews
-
- 'Export sheet metal to a single drawing file
- options = 1 'include flat-pattern geometry
- swPart.ExportToDWG2 sPathName, sModelName, swExportToDWG_ExportSheetMetal, True, varAlignment, False, False, options, Null
-
- End Sub
复制代码
|