AnsweredAssumed Answered

Macro save all configurations as "filename" - "Configuration name"

Question asked by Ben Richardson on Feb 25, 2020
Latest reply on Feb 26, 2020 by Ben Richardson

I have successfully modified another macro to save a part as a STL file, I just need to add one more function to it: save all the configurations of the part with the naming convention - "filename" - "Configuration name".STL in the same folder as the open part.

 

I saw this thread:

 

Macro to Export Multiple Configurations 

 

Not sure if I can just cut and paste that section into my code or not, without knowing exactly what each step is doing.

 

My code so far is:

 

 

Option Explicit
    Dim swApp               As SldWorks.SldWorks 'Solidworks
    Dim swModel             As SldWorks.ModelDoc2
    Dim swModelDocExt       As SldWorks.ModelDocExtension
    Dim swExportData        As SldWorks.ExportPdfData
    Dim boolstatus          As Boolean
    Dim filename            As String
    Dim lErrors             As Long
    Dim lWarnings           As Long


Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    If swModel Is Nothing Then
        MsgBox "No current document", vbCritical
        End
    End If
    If swModel.GetType <> swDocPART Then
        MsgBox "This Macro only works on Parts", vbCritical
        End
    End If
    Set swModelDocExt = swModel.Extension
    Set swExportData = swApp.GetExportFileData(swExportStlUnits)
    filename = swModel.GetPathName
    If filename = "" Then
        MsgBox "Please save the file first and try again", vbCritical
        End
    End If
    
    'Save STL
    filename = Strings.Left(filename, Len(filename) - 6) & "STL"
    boolstatus = swModelDocExt.SaveAs(filename, 0, 0, swExportData, lErrors, lWarnings)
    If boolstatus Then
        MsgBox "Save as STL successful" & vbNewLine & filename
    Else
        MsgBox "Save as STL failed, Error code:" & lErrors
    End If
    
    
    
    
End Sub

 

Any help greatly appreciated.

Outcomes