10 Replies Latest reply on Jan 31, 2018 11:49 AM by Ioan Bordei

    Hybrid add-in projects

    Ioan Bordei

      I have the following scenario:

      A SolidWorks third-party add-in (ADDIN1) offers an API for customizing diverse function/operations of it.

      I like to start SolidWorks from a console app (an .exe file) and access the API of the ADDIN1, but taking into consideration that the .exe  runs in a separate process than SolidWorks/ADDIN1. 

      My though was to access the ADDIN1 functions through another add-in (ADDIN2) which communicates with the exe in real time

      It is possible this scenario?

      How can this be accomplished?

      There are any examples/directions to look for?

      Any idea is welcome!

      Ioan

        • Re: Hybrid add-in projects
          Jacob Corder

          Just write the addin.

          Then anything else can communicate with that add-in using

          Isldworks.getaddinobject

           

          So dim myaddin as addintype = swappable.GetAddinObject(Guid of your addin)

           

          Now you have the live instance of your addin inside of solidworks.

           

          Anything made public is accessible. Basically you can do whatever you want it to do.

           

          No need to run solidworks in a separate .exe.

           

          Since the solidworks objects are thread safe as i understand (because they are com objects ), you shouldn't have any issues with that.

            • Re: Hybrid add-in projects
              Ioan Bordei

              Are you sure that no ADDIN2 is needed in order to access ADDIN1 API? The exe runs in different process that ADDIN1 ..

              Ioan

                • Re: Hybrid add-in projects
                  Jacob Corder

                  I have addins talking to addins.

                   

                  I have externals talking to addins that launch externals.

                   

                  I can assure you you can do it without launching it in a .exe.

                   

                  What is the purpose. Is it to do a client server application?

                  • Re: Hybrid add-in projects
                    Jacob Corder

                    Addin1 is com visible. Kind of means it can be accessed by anything.

                      • Re: Hybrid add-in projects
                        Jacob Corder

                        Unless of course you have the code locked or something weird like that

                          • Re: Hybrid add-in projects
                            Ioan Bordei

                            My intention is to lunch SolidWorks from an console application (.exe file) in the background and to access the API functions of a particular add-in. I'm not sure but you can consider it similar with a client server application because the computer with SolidWorks is like a server. Ideally I like to have the exe runs on o different computer in the network using the SolidWorks from the "server"

                            In this moment I need to test the communication@ mechanism only on the computer with SolidWorks .

                            I will test your idea it sounds too simple!

                            Best wishes!

                            Ioan

                              • Re: Hybrid add-in projects
                                Jacob Corder

                                To do this you will need to basically call the server with the code requests.

                                 

                                The server side will need to have basically every method that your add-in contains so it can basically act as a marshaller.

                                 

                                What i did to accomplish this was create a single exe.  That exe had the capability to be local or talk to a remote system if local it executes against it's self. However if it is remote it calls to the server which is through interop also. Basically this exe needs to have the methods exposed that your add-in has.  Then it wraps those methods to execute either remote or local.

                                 

                                The remote side is the exact same .exe as the local.

                                 

                                One install, one set of code to maintain.

                                 

                                So like.

                                 

                                Class swclientserver

                                 

                                Dim serverside as swclientserver

                                Sub new(byval executeremotely as boolean)

                                 

                                End sub

                                 

                                Function getface as face2

                                If islocal then

                                     Do something

                                Else

                                    Return serverside.getface

                                End if

                      • Re: Hybrid add-in projects
                        Ioan Bordei

                        After spending hours I can get the IDispatch pointer to ADDIN1 (the third party add-in which includes the API I try to access).

                        Unfortunately I'm blocked in the early binding access from pDisp to AddinObject.

                         

                        int _tmain(int argc, _TCHAR* argv[])

                        {

                             ::CoInitialize(NULL);

                             ATL::CComPtr<SldWorks::ISldWorks> pSwApp;

                          

                             if(SUCCEEDED(pSwApp.CoCreateInstance(__uuidof(SldWorks::SldWorks),NULL, CLSCTX_LOCAL_SERVER)))

                             {

                                   int status = 0;

                                  pSwApp->Visible=TRUE;

                                  status=pSwApp->LoadAddIn(_T("C:\\Program Files\\ADDIN1.dll"));

                                  CComPtr<IDispatch> pDisp;

                                  pDisp=pSwApp->GetAddInObject(_T("ADDIN1.ADDIN1")); // OK!!

                         

                        //        CComPtr<IADDIN1interface> AddinObject; // no type library (ADDIN1.tbl)  file access for ADDIN1

                        //        pDisp.QueryInterface(&AddinObject);

                        //        AddinObject->ADDIN1_API_Function1(); // the final stage..

                         

                                  pSwApp->ExitApp();

                             }

                             pSwApp = NULL;

                             ::CoUninitialize();

                             return 0;

                        }

                         

                        Any idea is welcome!

                        Ioan

                          • Re: Hybrid add-in projects
                            Jacob Corder

                            I don't know  c++ at all but i can read what you are doing. 

                            Does addin1 not implement idispatch?

                             

                            If not i read possibly use memberinfo.invoke?

                             

                            These are shots in the dark here.  If you wrote this in .net it would more than likely work.

                              • Re: Hybrid add-in projects
                                Ioan Bordei

                                Hi Jacob!

                                After look in the registry and searching all interfaces available on my computer for ADDIN1 I do not found any interfaces that I can access. The API functions of ADDIN1 are available for accessing only through LoadLibrary(.dll) and functions import at runtime using GetProcAddress() so I try to figure out how to create the second add-in ADDIN2 and link those 2 by some inter-processing mechanism,  I do not know...

                                Anyway, thank you very much for your suggestions, I learn from it!

                                Ioan