AnsweredAssumed Answered

import stl file as solid

Question asked by Jerome Maiere on Sep 19, 2018

I can import properly a STL file manually with SW2018 as a Solid or Surface or Graphics (using Options/Import/STLFiles), but when I use a macro to open the same STL file, I only get a Mesh result (without errors) rather than a Solid or Surface for instance.

I tried many things including changing swImportStlVrmlModelType to 2 for Solid, but the result is always a Mesh.

Once again, everything works well when importing manually.

Anyone have an idea of the problem with the macro? Thanks.

Here is my macro:

 

Option Explicit

Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim retVal As Boolean

    Dim ImportStlVrmlModelType As Long

    Dim ImportStlVrmlUnits As Long

    Dim Err As Long

    Dim Errors As Long

     Dim stlFileName As String

    

    Set swApp = CreateObject("SldWorks.Application")

  

   ImportStlVrmlModelType = swApp.GetUserPreferenceIntegerValue(swImportStlVrmlModelType)

    swApp.SetUserPreferenceIntegerValue swImportStlVrmlModelType, 2  '0 = Graphics body . 1 = Surface,  2 = Solid

  

    swApp.SetUserPreferenceIntegerValue swImportStlVrmlUnits, swMETER

 

' just in case, I tried to enable/disable  the 3dInterconnect but it doesn't help

  swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swMultiCAD_Enable3DInterconnect, False

    

     stlFileName = "XXX.stl"

     retVal = swApp.LoadFile2(stlFileName, "r")

    Debug.Print ("Error (0 = no error): " & Err)

End Sub

Outcomes