4 Replies Latest reply on Jun 20, 2009 12:46 PM by ed_smith

    why does this script not work

    mans.joling

      I try to print a screen to a postscriptfile and i does not work

      Here is the code :

       

      Option Explicit

      ' Get the application object
      Dim pcbApp
      Set pcbApp = GetObject(,"MGCPCB.ExpeditionPCBApplication")

      ' Get the active document
      Dim pcbDoc
      Set pcbDoc = pcbApp.ActiveDocument

      ' License the document
      ValidateServer(pcbDoc)

      ' add a reference to the MGCPCB type library in order to use enums
      Scripting.AddTypeLibrary("MGCPCB.ExpeditionPCBApplication")

      ' Invoke Idf Import dialog
      pcbApp.Gui.ProcessCommand("File->Print")

      ' Get a reference to this dialog
      dim dlgObj
      dim buttonObj
      Dim retBool,diaObj
      ' Display the HKP dump dialog by executing the command
      retBool = app.Gui.ProcessCommand("File->Print",True)
      Set diaObj = app.Gui.FindDialog("Print")
      If (retBool = False) Then
      Call app.Gui.StatusBarText("Print" + _
                                   Err.Description,epcbStatusFieldError)
      app.Gui.SuppressTrivialDialogs = False
      end if
      Set buttonObj = diaObj.FindButton("OK")
      If (buttonObj Is Nothing) Then
        Call app.Gui.StatusBarText("Print- OK button not found " + _
                                   Err.Description,epcbStatusFieldError)
        app.Gui.SuppressTrivialDialogs = False
        end if
       
      Call butObj.Click

       

      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Local functions

      Private Function ValidateServer(doc)
         
          dim key, licenseServer, licenseToken

          ' Ask Expedition’s document for the key
          key = doc.Validate(0)

          ' Get license server
          Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")

          ' Ask the license server for the license token
          licenseToken = licenseServer.GetToken(key)

          ' Release license server
          Set licenseServer = nothing

          ' Turn off error messages.  Validate may fail if the token is incorrect
          On Error Resume Next
          Err.Clear

          ' Ask the document to validate the license token
          doc.Validate(licenseToken)
          If Err Then
              ValidateServer = 0   
          Else
              ValidateServer = 1
          End If

      End Function

        • 1. Re: why does this script not work
          yu.yanfeng

          app-> pcbApp

          • 2. Re: why does this script not work
            mans.joling

            It's still not working.

            I am a newbie in vbs.

            What I am doing wrong

            Changed code.

             

            Option Explicit

            ' Get the application object
            Dim pcbApp
            Set pcbApp = GetObject(,"MGCPCB.ExpeditionPCBApplication")

            ' Get the active document
            Dim pcbDoc
            Set pcbDoc = pcbApp.ActiveDocument

            ' License the document
            ValidateServer(pcbDoc)

            ' add a reference to the MGCPCB type library in order to use enums
            Scripting.AddTypeLibrary("MGCPCB.ExpeditionPCBApplication")

            pcbApp.Gui.ProcessCommand("File->Print")
            dim dlgObj
            dim buttonObj
            Dim retBool,diaObj
            retBool = pcbApp.Gui.ProcessCommand("File->Print",True)
            If (retBool = False) Then
            Call pcbApp.Gui.StatusBarText("Print" + _
                                         Err.Description,epcbStatusFieldError)
            pcbApp.Gui.SuppressTrivialDialogs = False
            end if
            Set diaObj = pcbApp.Gui.FindDialog("Print")
            Set buttonObj = diaObj.FindButton("OK")
            If (buttonObj Is Nothing) Then
              Call pcbApp.Gui.StatusBarText("Print- OK button not found " + _
                                         Err.Description,epcbStatusFieldError)
              pcbApp.Gui.SuppressTrivialDialogs = False
              end if
             
            Call butObj.Click

             

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            'Local functions

            Private Function ValidateServer(doc)
               
                dim key, licenseServer, licenseToken

                ' Ask Expedition’s document for the key
                key = doc.Validate(0)

                ' Get license server
                Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")

                ' Ask the license server for the license token
                licenseToken = licenseServer.GetToken(key)

                ' Release license server
                Set licenseServer = nothing

                ' Turn off error messages.  Validate may fail if the token is incorrect
                On Error Resume Next
                Err.Clear

                ' Ask the document to validate the license token
                doc.Validate(licenseToken)
                If Err Then
                    ValidateServer = 0   
                Else
                    ValidateServer = 1
                End If

            End Function

            • 3. Re: why does this script not work
              yu.yanfeng

              Sorry. i didn't test this script in my side.

              In your source code, butObj should be changed to buttonObj. However, diaObj.FindButton("OK")  return null so the code does't work at all.

              yanfeng

               

              消息编辑者为:yu.yanfeng

              • 4. Re: why does this script not work
                ed_smith

                The script doesn't work because the Print dialog is a standard Windows dialog and is not internal to the Expedition product - that's why your script can't 'find' it. I don't have a solution for you at this moment...