13 Replies Latest reply on Apr 4, 2016 11:52 AM by Patrick.Cashman

    appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?

    michael.weber

      Hi Guys,

       

      I are on rewriting all our scripting emperium to new VX release. With most of scripts I did not have a problem.

      But with our library-Checker versus SAP I have.

      In Expedition 7.9.4 Script is running well.

       

      I write scripts in Visual Basic Express 2010.

       

      What I have do:

      I add a reference to ...SDD_HOME\common\win32\lib\PDBEditor.dll. With 7.9.4 it works perfect.

       

      When I add a reference to VX1...PDBEditor.dll

      appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") will do nothing.

       

      How did you open your VX Partseditor ?

       

      Any hints are welcome!

       

      BR Michi

        • 1. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
          jeremy_parker

          Are you directly referencing the .dll or are you going through the "Add Reference", browsing through the com objects and selecting the PDB Editor?

           

          Are you running 32-bit or 64-bit VX?

           

          That very statement works for me in all my implementations:

           

               Dim pedApp As MGCPCBPartsEditor.PartsEditorDlg

               Dim pedDoc As MGCPCBPartsEditor.PartsDB

           

               RaiseEvent eUpdateStatus("Creating instance of PDB Editor.")

           

               'pedApp = libDoc.PartEditor 'Connect directly to PDB Editor using LM license

               'pedDoc = pedApp.ActiveDatabaseEx

           

               pedApp = CreateObject("MGCPCBLibraries.PartsEditorDlg")

           

                 Try

                     pedDoc = pedApp.OpenDatabaseEx(frmMain.librarydata.LibPath, False)

                 Catch ex As Exception

                     RaiseEvent eUpdateStatus("Failed to create instance of PDB Editor.")

                     pedApp.Quit()

                     pedApp = Nothing

                     RaiseEvent eExportFailed()

                     Exit Sub

                 End Try

          • 2. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
            Patrick.Cashman

            You will need to make some changes to the way your scripts work.  There is now a big push to enable automation tools to reference multiple installed versions of the Mentor software on the fly.  This is done by way of a COM version system.  The COM version should be available by way of an environment variable, and your automation will need to get this value every time it starts in order to apply it to the different application startups such as your CreateObject statement above.

             

            More information on this can be found in the help.  Under Automation and Scripting, find the Common Automation Reference.  Look at chapter 2 of that, Scripting with Multiple Installs. There are some examples there on how to do it. 

             

            You will also need to change the references in your project to many of the dlls.  They are now in a different location, not in the Mentor install tree.  So in your project, you will delete the references and then add them back again.  This will incorporate the new path of the referenced objects. 

             

            CellEditorAddin

            MGCPCB

            MGCPCBEngines

            MGCPCBPartsEditor

            All the Variant Manager references

            ViewDraw

             

            All these need to be changed.  Perhaps some more which I've forgotten about.

             

            Next you will discover that even after you add the COM version suffix to the CreateObject statement, the PartsEditor will still not work.

             

            I encountered this problem with all of the PCB Engines. And the PartEditor. All failed in exactly the same way.  I put in SR's with Mentor, exchanged a bunch of emails back and forth to resolve the problem, and got nowhere.  I was told that it was a problem with the way I installed the software.  Which is odd, since all I do is run the standard Mentor Install program with default settings and it does all the rest.  If there was a problem with how this was installed, I have no way of knowing what to do differently, since I control almost nothing about it.   These scripts all worked perfectly fine in 7.9.4, and in VX they do not.

             

            The second problem you will run into is that the Mentor AE will not look at your code.  They do not debug customer automation code.  All you can do is tell them what function failed and what arguments you used with it.  So don't bother sending them your code.

             

            What I did to solve some of the problem was to start the PCB Engines with a vbscript that I run from inside my VB.net program.  That works.  I have no idea why the same function works from vbscript but not from VB.net. I suspect that there is something in the COM that they do not yet know about that is not quite right.  The AE I worked with assured me that it had all be tested and that the COM was certainly not the problem.  Unfortunately I do not know of a way to run the Parts Editor from a script and have it interact with .net, so you are going to be a bit stuck there until this gets resolved.

             

            I have waited to raise these issues here until someone other than me has encountered the same problem. I encourage you to start your own SR's and report back what you find.  Anyone else with the same issues should also chime in and put in their own SR's, so that we can get this problem looked at by the engineering team at Mentor. 

            • 3. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
              jeremy_parker

              Are you running your scripts through the MGC PCB Command Window or through MGC Launch?

               

              Environment variables are no longer set while installing or running the VX tools to allow for side by side installation. To get around this, you run your compiled automation code through the MGC PCB Command Window or wrap it using MGC Launch. These set up temporary environment variables for our programs to use when working with the COM objects, if not...PDB Editor has no clue which version of VX you want it to launch and fails.

              • 4. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                Patrick.Cashman

                Neither.  I run them just like I always have, externally, with the same hooks GetObject for running applications, CreateObject for ones that I am starting. Like this:

                 

                com_version = 9

                mskeng = CreateObject("MGCPCBEngines.MaskEngine." & com_version)

                 

                Even when I have explicitly stated the com version like this, the engines and Parts editor have failed to launch.  I had previously verified that the com version was 9, using uncompiled code to do the same thing.

                 

                Thanks for your help, Jeremy.  It's much appreciated.

                • 5. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                  jeremy_parker

                  No problem Patrick.

                   

                  As I mentioned, in VX we (the users and even mentor employees like myself) have to run our compiled programs through wrappers or through the new command window for them to work properly. In all my splash screens, I check to see if the user is running in a VX or EE enviroment by looking to see if SDD_Version exists in the environment variables. If it is, then I know they are either running the program in the 7.9.X flow where it is always set or they are running it through a wrapper in VX. If I can't find the environment variable, I end the program and tell the user they must run it through the MGC PCB Command Window in VX.

                  • 6. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                    Patrick.Cashman

                    So when you get the SDD_Version, what do you do with it?  Like I said above, even when I know the correct version, and put it in the code, it still doesn't work.

                     

                    And, how exactly do you run it through the MGC PCB Command Window in VX?  Forgive my ignorance, but I've never needed to do that. 

                    • 7. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                      jeremy_parker

                      With VX1.1, the COM version is different than VX.1, so this can let you know what version the user is running. In my case, I just look to ensure that the environment variable is set so that I know my automation calls will run externally of the program.

                       

                      Here are two different examples of running through the command window.

                       

                      Debugging using Visual Studio:

                      I launch my project through the command window so when I go to debug, the environment variables are set and I know it will create the appropriate objects such as PDB Editor, ect.

                       

                      It's the same thing for running a script:

                       

                      Which results in ALE opening:

                       

                      If I try to run ALE outside the command window, but still configured for VX...I have added this message:

                       

                      With the MGC Launch feature, it is a batch file that you wrap your executable in. I haven't really used it since I am a developer and not a user, but a user can take my executables, wrap them with the MGC Launch and it works like a batch script. First setting up a temporary environment, then running the program in that environment. The difference is they double click the wrapper and the program "works", where as in the command window you have to browse to the file (or be lazy like myself and drag the executable into the command window).

                       

                      Hope this helps!

                      • 8. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                        michael.weber

                        Hi Guys,

                         

                        THX for your help.

                        At first, all my other scripting is working with licensing Automation like listed at the end. Only my Library Script will do not.

                        I going through "Add Reference" and then parse to the dll. That works in 7.9.4 greatly, but not in VX (32bit).

                        I compile Scripts to exe.

                        So I will do have to read the manual now first....

                         

                        All other VB-Express Scripts have add the COM. With this, I have no Problems. Ok. When I have to recompile,

                        I have to add correct COM, but existing Scripts compiled to exe works. Don't ask me, why.

                         

                         

                        This is, what I use for Open Object:

                         

                         

                        Option Strict Off

                        Option Explicit On '

                         

                        Public Module mod_Automation_Module

                         

                            'DxDesigner Automation Globals

                            'Public dxapp As ViewDraw.Application

                            'Public dxdoc As Object

                            'Public prj As ViewDraw.IProjectData

                            'Public dxd_running As Boolean

                            'Public dxd_project_open As Boolean

                         

                            'Expedition Automation Globals

                            Public pcbapp As MGCPCB.Application

                            Public pcbdoc As MGCPCB.Document

                            Public pcb_running As Boolean

                         

                            '    Public Sub DX_Connect()

                            '        Dim errmsg As String

                            '        errmsg = ""

                            '        dxd_running = False

                            '        dxapp = Nothing

                            '        On Error GoTo dxd_error

                            '        errmsg = "Error: No active DxDesigner Application found."

                            '        dxapp = GetObject(, "ViewDraw.Application")

                            '        dxd_running = True

                         

                            '        prj = dxapp.GetProjectData

                         

                            'dxd_error:

                            '        If Not errmsg = "" Then

                            '            'msgbox(errmsg)

                            '        End If

                            '    End Sub

                         

                            '    Public Sub DX_Disconnect()

                            '        dxapp = Nothing

                            '    End Sub

                         

                            Public Sub MGCPCB_Connect()

                                ' connects to MGCPCB

                                Dim retVal As Short

                                pcb_running = False

                                On Error GoTo OnErrorGetObject

                                pcbapp = GetObject(, "MGCPCB.Application")

                                pcbdoc = pcbapp.ActiveDocument

                                If Not pcbdoc Is Nothing Then

                                    pcb_running = True

                                End If

                                ' make sure the doc is licensed

                                retVal = licenseDoc(pcbdoc)

                                If (retVal <> 1) Then pcbdoc = Nothing

                                Exit Sub

                         

                        OnErrorGetObject:

                                'MsgBox("MGCPCB needs to be running!")

                            End Sub

                         

                         

                            Public Sub MGCPCB_Disconnect()

                                ' disconnects from MGCPCB.

                                pcbdoc = Nothing

                                pcbapp = Nothing ' Disconnect from MGCPCB server

                            End Sub

                         

                            Public Function licenseDoc(ByRef docObj As MGCPCB.Document) As Short

                                ' =======================================================================

                                ' Retrieve a licence for the document

                                ' =======================================================================

                                On Error GoTo exit_with_error

                                Dim retState As Short

                                Dim licenseServer As Object

                                Dim key As Integer

                                Dim licenseToken As Integer

                                Dim outErrMess As String

                         

                                If (docObj Is Nothing) Then GoTo end_of_function

                                ' Ask the document for a key

                                key = docObj.Validate(0)

                                ' Get license server

                                On Error GoTo err_create_serverobj

                                licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")

                                If (licenseServer Is Nothing) Then GoTo err_create_serverobj

                                On Error GoTo exit_with_error

                         

                                ' Ask the license server for the license token

                                licenseToken = licenseServer.GetToken(key)

                         

                                ' Validate the document with the license token

                                On Error GoTo err_validate

                                Dim lRetval As Integer

                                lRetval = docObj.Validate(licenseToken)

                         

                                On Error GoTo exit_with_error

                         

                                retState = 1

                         

                        end_of_function:

                         

                                ' release licence server

                                licenseServer = Nothing

                                licenseDoc = retState

                         

                                Exit Function

                         

                        show_error:

                                Dim ioptions As Integer

                                ioptions = MsgBoxStyle.DefaultButton1 + MsgBoxStyle.ApplicationModal + MsgBoxStyle.Critical + MsgBoxStyle.OkOnly

                                MsgBox(outErrMess, ioptions, "Retrieving license for document")

                                GoTo end_of_function

                         

                        exit_with_error:

                                outErrMess = "** Error ** " & ErrorToString()

                                retState = -1

                                GoTo show_error

                         

                        err_create_serverobj:

                                outErrMess = "** Error ** Could not create license server object"

                                retState = -2

                                GoTo show_error

                         

                        err_validate:

                                outErrMess = "** Error ** Failed to validate document object"

                                outErrMess = outErrMess & vbCrLf & "    License token : " & Trim(Str(licenseToken))

                                outErrMess = outErrMess & vbCrLf & "    Document key  : " & Trim(Str(key))

                                retState = -3

                                GoTo show_error

                         

                            End Function

                         

                        End Module

                        • 9. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                          michael.weber

                          Hi Guys,

                           

                          in the meantime I get some support from a Mentor Guy. Thanks!

                           

                          Problem is to register correct DLL.Version in VisualBasic Express. So I have to run my ExpressStudio via mglaunch.exe :

                           

                          C:\MentorGraphics\EEVX.1.1\SDD_HOME\common\win32\bin\mglaunch.exe "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"

                          (for vbExpress use vbexpress.exe instead of devenv.exe)

                           

                          Now I can compile and run my app. But for generated exe...this I have to run also via mglaunch.exe. But this is not very comfortable....

                           

                          BR Michi

                          • 10. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                            michael.weber

                            Hi Guys,

                             

                            in the meantime VX 1.2 is available and .... you can not run

                             

                            appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg")

                             

                            anymore.

                            You must have a PartsManager License to do that. Only a Libraymanager License is not enough.

                            Mentor did some changes in licensing and I think, this was a worst thing, they do.

                            Now we have to decide, wether not intruducing VX1.2 or on worst case cancel support.

                            Sorry Mentor, this was not a good idea to cancel automation in VX1.2 if you don't have a partsmanager license.

                             

                            Michi

                            • 11. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                              Patrick.Cashman

                              Michi,

                               

                               

                              Have you tried this:

                              appPED= CreateObject("MGCPCBLibraries.PartsEditorDlg" & "." & prog_id)

                               

                              where prog_id is the COM Version.

                               

                              I have done this and it works.  I have to start my IDE with mglaunch, but it does run PDBEditor (in debug mode from the IDE) and executes functions normally.  Same for the executable - start with mglaunch and it works as expected.

                               

                              We do not have a Parts Manager license so I'm pretty sure that is not the issue. Per my Mentor AE, the Parts Manager license should not be required for any automation tools.

                              • 12. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                                michael.weber

                                Hi Patrick,

                                 

                                I tried this. Same Error. Problem is, that you MUST HAVE a PartsManager License in VX1.2 to run Librarymanager via automation.

                                Or more than 1 Librarymanager licenses…..

                                 

                                So: Did you have more than 1 Library Manager Licenses or 1 LIbMan + 1 PartMan ? Than everthing is ok….

                                 

                                BR Michi

                                 

                                Von: Patrick.Cashman

                                Gesendet: Dienstag, 29. März 2016 21:31

                                An: Weber, Michael - SAG

                                Betreff: Re:  - appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?

                                 

                                Mentor Graphics Communities <https://communities.mentor.com/?et=watches.email.thread>

                                 

                                 

                                appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?

                                 

                                reply from Patrick.Cashman<https://communities.mentor.com/people/Patrick.Cashman?et=watches.email.thread> in Automation and Scripting - View the full discussion<https://communities.mentor.com/message/61798?et=watches.email.thread#comment-61798>

                                • 13. Re: appPED = CreateObject("MGCPCBLibraries.PartsEditorDlg") in VX not work?
                                  Patrick.Cashman

                                  Yes, we have 2 library manager licenses. So in my case we can't tell if it's an issue. 

                                  Sorry I could not be of more help.