This is a snippet from my macro to export a SW drawing to pdf, dwg, and/or parasolid. It exports to PDF always, dwg when the model contains a "sheet metal" part, and parasolid otherwise except for our actual assemblies based on our part numbering scheme.
Sub CheckDrawing()
Set swDraw = swModel
InitialDocName = swModel.GetPathName
Set swInitialSheet = swDraw.GetCurrentSheet
InitialSheet = swInitialSheet.GetName
ToggleShtMtl = 0
ToggleModel = 0
ToggleShtSize = 0
SheetNumber = 1
'Check all Sheet Views for Sheet Metal Flat Pattern
SheetCount = swDraw.GetSheetCount
vSheetName = swDraw.GetSheetNames
For i = 0 To SheetCount - 1
SheetName = vSheetName(i)
boolstatus = swDraw.ActivateSheet(SheetName)
Set swSheet = swDraw.Sheet(SheetName)
If ToggleShtMtl = 0 Then
Call FindShtMtlFlat
End If
Next i
Call GetModelProps
If ToggleShtSize = 0 And ToggleShtMtl = 0 Then
Call SaveParasolid
Call SavePDF
ElseIf ToggleShtSize = 0 And ToggleShtMtl = 1 Then
Call SaveDWG
Call SavePDF
ElseIf ToggleShtSize = 1 And ToggleShtMtl = 0 Then
Call SavePDF
ElseIf ToggleShtSize = 1 And ToggleShtMtl = 1 Then
MsgBox "Drawing has a Sheet Metal flat pattern view, but the PartShtSize is not 01, 02, 03, or 04." & vbNewLine & "Please correct PartShtSize or remove view/configuration."
ElseIf ToggleShtSize = 2 Then
MsgBox "PartShtSize in model is not recognized." & vbNewLine & "PartShtSize must be 01, 02, 03, or 04 to export as a parasolid with this macro."
End If
End Sub
Sub FindShtMtlFlat()
Set swView = swDraw.GetFirstView
Do Until (Right(ViewConfigName, 15) = "SM-FLAT-PATTERN") Or swView Is Nothing
ViewConfigName = swView.ReferencedConfiguration
If Right(ViewConfigName, 15) = "SM-FLAT-PATTERN" And (ToggleShtMtl = 0) Then
Set swModel = swView.ReferencedDocument
ToggleShtMtl = 1
SheetNumber = SheetNumber + i
ShtMtlSheet = swSheet.GetName()
Exit Do
ElseIf (ViewConfigName <> "") And (ToggleShtMtl = 0) Then
Set swModel = swView.ReferencedDocument
End If
Set swView = swView.GetNextView
Do Until (Right(ViewConfigName, 15) = "SM-FLAT-PATTERN") Or swView Is Nothing
ViewConfigName = swView.ReferencedConfiguration
If (Right(ViewConfigName, 15) = "SM-FLAT-PATTERN") And (ToggleShtMtl = 0) Then
Set swModel = swView.ReferencedDocument
ToggleShtMtl = 1
SheetNumber = SheetNumber + i
ShtMtlSheet = swSheet.GetName()
Exit Do
ElseIf (ViewConfigName <> "") And (ToggleShtMtl = 0) Then
Set swModel = swView.ReferencedDocument
End If
Set swView = swView.GetNextView
Loop
Loop
End Sub
Sub GetModelProps()
CheckPartShtSize = swModel.GetCustomInfoValue(ViewConfigName, "PartShtSize")
CheckPartBase = swModel.GetCustomInfoValue(ViewConfigName, "PartBase")
CheckRevision = swModel.GetCustomInfoValue(ViewConfigName, "Revision")
If CheckRevision = "-" Then
CheckRevision = "0"
End If
If Len(CheckPartShtSize) = 2 And Left(CheckPartShtSize, 1) = "0" And 0 < Right(CheckPartShtSize, 1) And Right(CheckPartShtSize, 1) < 5 Then
ElseIf Len(CheckPartShtSize) = 2 And Left(CheckPartShtSize, 1) = "0" And 4 < Right(CheckPartShtSize, 1) And Right(CheckPartShtSize, 1) < 10 Then
ToggleShtSize = 1
Else
ToggleShtSize = 2
End If
End Sub
Sub SaveParasolid()
boolstatus = swModel.Extension.SelectByID2(ViewConfigName, "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = swModel.ShowConfiguration2(ViewConfigName)
If Len(SheetNumber) = 1 And IsNumeric(CheckPartBase) And Len(CheckPartBase) = 6 And Len(CheckRevision) = 1 Then
longstatus = swModel.SaveAs3(PreReleasePath & CheckPartBase & SheetNumber & CheckRevision & ".X_T", 0, 0)
End If
End Sub
Sub SaveDWG()
Set swDraw = swApp.ActivateDoc2(InitialDocName, True, 2)
swDraw.ActivateSheet (ShtMtlSheet)
Set swSheet = swDraw.Sheet(ShtMtlSheet)
swModel.ViewZoomtofit2
swModel.ClearSelection2 True
If Len(CheckPartShtSize) = 2 And Left(CheckPartShtSize, 1) = "0" And 0 < Right(CheckPartShtSize, 1) And Right(CheckPartShtSize, 1) < 5 And Len(SheetNumber) = 1 And IsNumeric(CheckPartBase) And Len(CheckPartBase) = 6 And Len(CheckRevision) = 1 Then
longstatus = swDraw.SaveAs3(PreReleasePath & CheckPartBase & SheetNumber & CheckRevision & ".DWG", 0, 0)
End If
End Sub
Sub SavePDF()
Set swDraw = swApp.ActivateDoc2(InitialDocName, True, 2)
swDraw.ActivateSheet (InitialSheet)
Set swSheet = swDraw.Sheet(InitialSheet)
swModel.ViewZoomtofit2
swModel.ClearSelection2 True
If ToggleShtSize = 0 And IsNumeric(CheckPartBase) And Len(CheckPartBase) = 6 And Len(CheckRevision) = 1 Then
longstatus = swDraw.SaveAs3(PreReleasePath & CheckPartBase & "1" & CheckRevision & ".PDF", 0, 0)
ElseIf ToggleShtSize = 1 And IsNumeric(CheckPartBase) And Len(CheckPartBase) = 6 And Len(CheckRevision) = 1 Then
longstatus = swDraw.SaveAs3(PreReleasePath & CheckPartBase & "1" & CheckRevision & ".PDF", 0, 0)
End If
End Sub
Sub SaveECNNumber()
If IsNumeric(ECNNumber) And Len(ECNNumber) = 5 Then
Set fs = CreateObject("Scripting.FileSystemObject")
Set MyFile = fs.OpenTextFile(ECNTextPath, 2, True)
MyFile.Write ECNNumber
MyFile.Close
End If
End Sub
James Spisich
Design Engineer, CSWP