3 Replies Latest reply on Feb 20, 2018 4:20 AM by Patrick Reinke

    Problems starting SolidWorks 2017 through API

    Patrick Reinke

      Hello all together,


      first at all, I am new in this forum and thanks for let me beeing here. Second: sry 4 my english if it doesn't pleases you. ;-)


      I have a Problem starting SolidWorks 2017 through the API. I Have heard the experts are hiding in here.  I hope you can help me troubleshooting this error and thanks 4 even reading until the end.


      As a CAD-Manager I am trying to find corrupted assemblys regarding to missing file references ans corrupted mates. So i am writing an makro that starts SolidWorks and checks each assembly stored in a folderstructure. The Problems begins with starting SolidWorks. Because SolidWorks 2015 und 2017 coexists, the engine allways runs 2015 by default. So I checked the following solution, to descide which Version I want to run.

      Problems with GetObject


      Unfortunately it didnt work well, so I decided to uninstall SolidWorks 2015. Now the Debugger gives back an exception, when running through

      SldWorks app = new SldWorks();


      Do you have an idea what can be the Problem.


      Deep thanks 4 any help!!




        • Re: Problems starting SolidWorks 2017 through API
          Artem Taturevych



          What programming language are you using? If it is .NET, does debugger give something like 'Failed to query interface'? error. if so try to use late binding (as a test) - i.e. use Object instead of ISldWorks. If that works your best option to repair SW (this will repair the corrupted Type Libraries).



            • Re: Problems starting SolidWorks 2017 through API
              Patrick Reinke

              Hi Artem,


              Correct I am using .NET with C#. Well i typed in Object swObject = (Object) new SldWorks();. but debugger still gives the same error, which is:




              "Die COM-Klassenfactory für die Komponente mit CLSID {D66FBAAE-4150-402F-8581-75D1652D696A} konnte aufgrund des folgenden Fehlers nicht abgerufen werden: 80040154 Klasse nicht registriert (Translation: "(...)class not registered") (Ausnahme von HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."


              Next step is to repair SolidWorks.





              • Re: Problems starting SolidWorks 2017 through API
                Patrick Reinke

                Hi Artem,


                Problem half solved. I dont know why SolidWorks is started by Default even when you have uninstalled this Version. But I do know now how to avoid this "default.behavior"- thanks of SolidWorks Support.


                You have to start SolidWorks by the Activator.CreateInstance method: For example like this:




                SldWorks app = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application.25")

                25 stands for Version 2017.

                Further codes:

                for SW 2012


                for SW 2013


                for SW 2014


                for SW 2015


                for SW 2016


                for SW 2017



                This also should work with CreateObject("SldWorks.Application.25")


                Hope this helps everyone who has the same Problem.