AnsweredAssumed Answered

Save as stl

Question asked by Kelson Lachance on Aug 18, 2015
Latest reply on Aug 18, 2015 by Kelson Lachance

I am missing something very obvious here.


Just making a simple save to stl macro.  May be I am a little rusty.  First part is to adjust user settings.  I need to activate the model I think.


Private Sub smdstl_Click()

    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim swModelExt As SldWorks.ModelDocExtension
    Dim Save2Name As String
     Dim SaveErrors As Long
    Dim SaveWarnings As Long

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swModelExt = swModel.Extension
            test = swApp.GetUserPreferenceDoubleValue(swUserPreferenceDoubleValue_e.swSTLDeviation)
            Silent = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swSTLQuality, swSTLQuality_Custom)
            Silent = swApp.SetUserPreferenceDoubleValue(swUserPreferenceDoubleValue_e.swSTLAngleTolerance, 5)
            Silent = swApp.SetUserPreferenceDoubleValue(swUserPreferenceDoubleValue_e.swSTLDeviation, 0.002)

            test = swApp.GetUserPreferenceDoubleValue(swUserPreferenceDoubleValue_e.swSTLDeviation)

            ' output as STL file
            'Save2Name = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".stl"
            Save2Name = "C:\SolidworksExport\test.stl"
            Silent = swModelExt.SaveAs(Save2Name, 0, swSaveAsOptions_Silent, Null, SaveErrors, SaveWarnings)

      'Silent = swModelExt.SaveAs(Save2Name, 0, swSaveAsOptions_Silent, Null, SaveErrors, SaveWarnings)

            ' close the document
            'swApp.CloseDoc swModel.GetTitle


End Sub