3 Replies Latest reply on Feb 25, 2013 5:04 PM by fenghaili

    Why batch engine SilkscreenGen.Go doesn't work ?

    fenghaili

      I can not generate the silkscreen with Object  SilkscreenGen.

      Maybe SilkscreenGen.Go doesn't work.

      Below is the script.

       

      Option Explicit

      Dim app 'As Application
      Dim docObj 'As Document
      Dim jobName, jobConfigPath
      Dim sPath
      main

      Sub main()

          Set app = Application
          Set docObj = GetLicensedDoc(app)
          jobName = docObj.FullName
          sPath = docObj.Path
             
          Scripting.AddTypeLibrary ("MGCPCBEngines.SilkscreenGen")
         
          Call app.Gui.CursorBusy(True)
         
          Call RunSilkscreenGen

          Call app.Gui.CursorBusy(False)
         
      End Sub

      '************************************************************************
      Sub RunSilkscreenGen()
          'On Error Resume Next
         
          Dim oSilkscreenGenEngine 'As PDFOutput
          Set oSilkscreenGenEngine = CreateObject("MGCPCBEngines.SilkscreenGen")
          oSilkscreenGenEngine.DesignFileName = jobName
          jobConfigPath = docObj.Path & "Config\"
          oSilkscreenGenEngine.SetupFileName = jobConfigPath + "SilkGenDlg.hkp"

          Call SetupSilkscreenGenEngine(oSilkscreenGenEngine)

          oSilkscreenGenEngine.Go
         
      '    Dim oErrors
      '    Set oErrors = oSilkscreenGenEngine.Errors
      End Sub

      Function SetupSilkscreenGenEngine(oSilkscreenGenEngine)
      '    On Error Resume Next
         
          oSilkscreenGenEngine.SilkScreenProcessSide = eengCellSideBoth
          oSilkscreenGenEngine.BreakSilkscreenBy = eengConductivePads
          oSilkscreenGenEngine.ProcessAllGroups = True
          oSilkscreenGenEngine.Groups.Add eengCellTypeAll
          oSilkscreenGenEngine.BreakGraphicsPadClearance(eengUnitMM) = 0.1
          oSilkscreenGenEngine.UseBreakGraphicsPadClearance = True
          oSilkscreenGenEngine.BreakGraphicsViaClearance(eengUnitMM) = 0.1
          oSilkscreenGenEngine.UseBreakGraphicsViaClearance = False
          oSilkscreenGenEngine.BreakTextPadClearance(eengUnitMM) = 0.1
          oSilkscreenGenEngine.UseBreakTextPadClearance = True
          oSilkscreenGenEngine.BreakTextViaClearance(eengUnitMM) = 0
          oSilkscreenGenEngine.UseBreakTextViaClearance = False
          oSilkscreenGenEngine.GraphicsLineWidth(eengUnitMM)= 0.2
          oSilkscreenGenEngine.TextLineWidth(eengUnitMM)= 0.15
          oSilkscreenGenEngine.TopSideSilkscreenLayers = Array( eengSilkscreenOutline,eengSilkscreenReferenceDesignators)
          oSilkscreenGenEngine.BottomSideSilkscreenLayers= Array( eengSilkscreenOutline,eengSilkscreenReferenceDesignators)

      End Function

      Public Function GetLicensedDoc(appObj)
          On Error Resume Next
          Dim key, licenseServer, licenseToken, docObj
          Set GetLicensedDoc = Nothing
          ' collect the active document
          Set docObj = appObj.ActiveDocument

          If Err Then
              Call appObj.Gui.StatusBarText("No active document: " & Err.Description, epcbStatusFieldError)
              Exit Function
          End If

          ' Ask Expedition抯 document for the key
          key = docObj.Validate(0)
          ' Get token from license server
          Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
          licenseToken = licenseServer.GetToken(key)
          Set licenseServer = Nothing
          ' Ask the document to validate the license token
          Err.Clear
          Call docObj.Validate(licenseToken)

          If Err Then
              Call appObj.Gui.StatusBarText("No active document license: " & Err.Description, epcbStatusFieldError)
              Exit Function
          End If

          ' everything is OK, return document
          Set GetLicensedDoc = docObj
      End Function

        • 1. Re: Why batch engine SilkscreenGen.Go doesn't work ?
          Patrick.Cashman

          I have a script that is very similar to yours.  I wrote it some time ago and don't remember the details of what I discovered when I wrote it.

           

          However, just after executing the .go command, I do two more things:

           

          1. output errors:

           

          'Note: my silkscreen engine variable is ssgen

           

                  ssgen_errors = ssgen.Errors

           

                  tmp = "SS Gen Errors:" & vbcrlf

                  If Not ssgen_errors Is Nothing Then

                      For Each ssgen_error In ssgen_errors

                          tmp = tmp & ssgen_error.ErrorString.ToString & vbcrlf

                      Next

                      msgbox(tmp)

                  End If

           

          2. Run the gui.processcommand function to run the Output>Silkscreen Generator function:

           

          gui = pcbapp.Gui

                   gui.SuppressTrivialDialogs = true

                   gui.ProcessCommand("Silkscreen Generator", True)

                   dlg = gui.FindDialog("Silkscreen Generator")

                   btn = dlg.FindButton("OK")

                   btn.Click

                   gui.SuppressTrivialDialogs = False

                   btn = Nothing

                   dlg = Nothing

                   gui = Nothing

           

          The error trap probably doesn't do much; I had commented out the messagebox output shortly after the script was put in service.

           

          The second part, the ProcessCommand, is most likely there because I discovered that the .go command doesn't work. The good thing is that it most likely rewrites the config file SilkGenDlg.hkp, so when you execute the ProcessCommand("Silkscreen Generator", True) command, it utilizes the config file so it comes out exactly how you set it up for the Silkscreen Engine.

           

          Sorry I can't remember what actually happened when I wrote this.  It does work this way; we use it all the time with good results.

           

          -Patrick

          1 of 1 people found this helpful
          • 2. Re: Why batch engine SilkscreenGen.Go doesn't work ?
            al_layson

            Your script works fine. All Automation Pro Engines read & write disk data directly. You may be executing the script from within an Application Session (Expedition), but to read the new data that was written directly to disk by an Automation Pro engine you will need to close the Application (Expedition) - without saving - and then reopen to have the Application read in the new disk data.

             

            The Automation Pro engines are provided for the "Batch" execution of a process without the need to have the owner application open - this is why they read & write directly from/to disk data (not Application Memory). You have written the script so that it can only be executed from within the Application (Expedition), giving the user the incorrect expectation of "instant update" to his graphics - which is not the case. The only thing you get out of this is the design input/output paths extracted from the opened design.

             

            See technote at : http://supportnet.mentor.com/reference/technotes/public/technote.cfm?id=MG555585

             

            Regards,

            Al

            • 3. Re: Why batch engine SilkscreenGen.Go doesn't work ?
              fenghaili

              Thanks al_layson for your reply. This is usefull for me .

               

              Best Regards.