10 Replies Latest reply on Feb 18, 2011 1:35 AM by a.gieger

    Any idea how to detect several Expedition application?

    a.gieger

      Hi all,

      we have a lot of small Visual Basic programs created for Expedition PCB. These are stand alone *.exe programs which connect to the running Expedition application with  GetObject(, "MGCPCB.ExpeditionPCBApplication"). They are used e.g. for creating Gerber data or bill of material.

       

      My problem is now: If more than one Expedition application is running, I can't affect the connection.

      It always connects to the first running Expedition application. You go mad if you forgot to close the first starting Expedition and you're still working in another 'second' Expedition application. You run the Basic program, but you don't get results from your 'second' application where you are working on.

       

      Any idea?

        • 1. Re: Any idea how to detect several Expedition application?
          Satoru

          Hello gieger-san,

           

          When there are two or more applications, the application can be got by FindApplication method.

          Please refer to two of my sample code.

           

          VBScript:  starter_template(Multi Application).vbs

          VB6:   VB6_Starter_Template(Multi Application)

           

          Regards,

          Satoru

          • 2. Re: Any idea how to detect several Expedition application?
            Andreas.Schaefer

            Hi,

             

            in addition to the code from satoru-san:

             

            In every case you are runnig a script you shpuld use the Application.InstanceGUID to verify your script is running in the correct application instance.

            Then your script connects to the right design, although two or more expedition designs are open.

             

            regards,

            Andreas

            • 3. Re: Any idea how to detect several Expedition application?
              a.gieger

              Thanks,

              great stuff, that solves my problem

               

              Andreas

              • 4. Re: Any idea how to detect several Expedition application?
                a.gieger

                Just one cent.....

                 

                With your help I created a vbs script that works fine

                 

                Option Explicit    


                Dim objPCBApp

                Set objPCBApp = Application


                Dim objPCBDoc

                Set objPCBDoc = objPCBApp.ActiveDocument

                 

                msgbox("Design name " & objPCBDoc.name & vbCRLF & objPCBApp.InstanceGUID)

                 

                It works well even with the run command or with an added custom toolbar in scripts.ini.

                 

                But......we prefer Visual Basic Express created with free Microsoft Visual Studio. This is more comfortable with breakpoints, steps and debug values. I tried to convert the vbs script to basic, but I failed

                 

                Module Module1

                 

                    Sub Main()

                        Dim objPCBApp As MGCPCB.Application

                        objPCBApp = Application


                        Dim objPCBDoc As MGCPCB.Document

                        objPCBDoc = objPCBApp.ActiveDocument

                 

                        MsgBox("Design name " & objPCBDoc.name & vbCRLF & objPCBApp.InstanceGUID)

                    End Sub


                End Module

                 

                The redlined command doesn't work.

                Do you have any idea???

                 

                Andreas

                • 5. Re: Any idea how to detect several Expedition application?
                  Andreas.Schaefer

                  Hi Andreas,

                   

                  the issue is, that with Visual Studio you are running your code outside the Expedition.

                  So you need a

                  App = GetObject(,"MGCPCB.ExpeditionPCBApplication")

                  first to look for any Application.

                   

                  Then you can go through all of them.

                   

                  hope this helps,

                  Andreas

                  • 6. Re: Any idea how to detect several Expedition application?
                    a.gieger

                    Hello Andreas, 

                     

                    I know this command and use it in all my programs. But it always returns the first running application and not the application it was startet from.  A bit uncomfortable would be a choice box where the user choices the application/design. Because the user started the program from the tool bar in his design he would ask for the reason to choice

                     

                    MenuBar.jpg

                     

                    It would be nice to have the same solution as it works with vbs script.

                     

                    Regards

                    Andreas

                    • 7. Re: Any idea how to detect several Expedition application?
                      Andreas.Schaefer

                      Hi,

                       

                      go with a Counter loop (while Counter <> "") using

                      App.Utility.FindApplication(Counter)

                      through all Application instances and compare GUID with your documents application GUID.

                       

                      When found the right application instance, set this as your local Application to run the script in.

                       

                      regards,

                      Andreas

                      • 8. Re: Any idea how to detect several Expedition application?
                        a.gieger

                        Hi Andreas, thanks for your help,

                         

                        but I don't understand  "compare GUID with your documents application GUID".

                         

                        I created a loop and get all open applications, also I can report the belonging objPCBApp.InstanceGUID of these applications.

                        But where I can get from the "documents application GUID" you told me? I don't understand where it should come from.

                         

                        If you like, you may call me tomorrow 0231 75 88 793

                         

                        Thanks

                        Andreas

                        • 9. Re: Any idea how to detect several Expedition application?
                          Andreas.Schaefer

                          Hi Andreas,

                           

                          as I can see, you start your script from a cusomized menu.

                           

                          There you should add a parameter ActiveDocument.Application.InstanceGuid . Then your script knows the GUID of the application instance irt was started (your "localApp")

                          although running outside expedition.

                          Next you create your loop, go trough all instances.

                          If inside your loop your "localApps.InstanceGUID" is same than Application.Utility.FindApplication(LoopCounter),

                          set the instance as your new localApp, where to run the script in:

                          localApp = App.Utility.FindApplication(Loop Counter, where InsranceGUID is same than parameter given to script)

                           

                          Hope this helps you,

                          Andreas

                          • 10. Re: Any idea how to detect several Expedition application?
                            a.gieger

                            Hi Andreas,

                             

                            it works......

                            Thank you for your ideas and help.

                             

                            The solution is :

                            The custom menu bar get the application object and sends the GUID as parameter to the basic program 'Main'.

                             

                            Dim objpcbApp

                            Set objpcbApp = Application

                            ..

                            ..

                            cmdTest.OnAction = "run C:\Test.exe " & objPCBApp.InstanceGUID

                             

                            The Basic program gets the GUID and searches all applications until the GUID is found.

                                Public Sub Main(ByVal strCallingByApplGUID() As String)

                                    Dim objPCBApp As MGCPCB.Application

                                    Dim objPCBDoc As MGCPCB.Document

                                    Dim strApplGUID As String

                                    strApplGUID = strCallingByApplGUID(0).Trim             ' den 1. Parameter nehmen, das Leerzeichen am Ende des GUID entfernen

                             

                                    objPCBApp = GetLocalAppInstance(strApplGUID)     ' hole die Application die zur GUID passt

                             

                                    objPCBDoc = objPCBApp.ActiveDocument

                                    MsgBox("Called by: " & objPCBDoc.Name)

                                End Sub

                             

                                Public Function GetLocalAppInstance(ByVal CallingByApplGUID As String)

                                    Dim Counter As Integer

                                    Dim objPCBApp, objLocalApp As MGCPCB.Application

                                    ' connect to an Expedition

                                    objPCBApp = GetObject(, "MGCPCB.ExpeditionPCBApplication")

                                    objPCBApp.LockServer()

                                    Counter = 0

                             

                                    objLocalApp = objPCBApp.Utility.FindApplication(Counter)

                                    Do While Not objLocalApp Is Nothing

                                        objLocalApp = objLocalApp.Utility.FindApplication(Counter)

                             

                                        If (CallingByApplGUID = objLocalApp.InstanceGuid) Then

                                            Exit Do

                                        End If

                                        Counter = Counter + 1

                                    Loop

                             

                                    objPCBApp.UnlockServer()

                                    GetLocalAppInstance = objLocalApp

                                End Function

                             

                            Kind Regards

                            Andreas