2 Replies Latest reply on Jan 25, 2017 2:41 PM by Wouter Van Den Hoek

    Open doc silent doesn't work

    Wouter Van Den Hoek



      I only recently started working with the SolidWorks API. Now I'm trying to change the material and appearance of a few parts in an assembly. I figured the easiest (for me that is) way to do this, is by opening the parts in the background and then changing the things I want to change. But everytime I run the macro, I still see parts opening.


      I narrowed what I have down to this:


      Sub main()


          Dim swApp       As SldWorks.SldWorks

          Dim Part             As SldWorks.ModelDoc2

          Dim longstatus  As Long, longwarning As Long

          Dim boolstatus  As Boolean

          Dim macrfolder  As String

          Dim Materiaal   As String


          Set swApp = Application.SldWorks

          macrofolder = swApp.GetCurrentMacroPathFolder() & "\"

          Materiaal = "Pure Gold"


          swApp.DocumentVisible False, swDocPART


          Set Part = swApp.OpenDoc6("schaar_onder.SLDPRT", swDocPART, swOpenDocOptions_Silent, "", longstatus, longwarning)

          Set Part = swApp.ActivateDoc2("schaar_onder", True, longstatus)


          Part.SetMaterialPropertyName2 "Default", "C:/Program Files/SOLIDWORKS Corp/SOLIDWORKS/lang/english/sldmaterials/SOLIDWORKS Materials.sldmat", Materiaal


          swApp.DocumentVisible True, swDocPART

          swApp.CloseDoc "schaar_onder"


      End Sub