2 Replies Latest reply on Aug 18, 2015 3:59 PM by Kelson Lachance

    Save as stl

    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

        • Re: Save as stl
          Deepak Gupta

          Nothing should be used in place of NULL

           

          Private Sub smdstl_Click()

              Dim swApp                   As SldWorks.SldWorks

              Dim swModel                 As SldWorks.ModelDoc2

              Dim SaveErrors              As Long

              Dim SaveWarnings            As Long

           

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

                     

                      swApp.GetUserPreferenceDoubleValue swUserPreferenceDoubleValue_e.swSTLDeviation

                      swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swSTLQuality, swSTLQuality_Custom

                      swApp.SetUserPreferenceDoubleValue swUserPreferenceDoubleValue_e.swSTLAngleTolerance, 5

                      swApp.SetUserPreferenceDoubleValue swUserPreferenceDoubleValue_e.swSTLDeviation, 0.002

                      swApp.GetUserPreferenceDoubleValue swUserPreferenceDoubleValue_e.swSTLDeviation

                 

                  ' output as STL file

                      swModel.Extension.SaveAs Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".stl", 0, swSaveAsOptions_Silent, Nothing, SaveErrors, SaveWarnings

               

                  ' close the document

                      swApp.CloseDoc swModel.GetTitle

           

          End Sub