AnsweredAssumed Answered

Why batch engine SilkscreenGen.Go doesn't work ?

Question asked by fenghaili on Dec 19, 2012
Latest reply on Feb 25, 2013 by 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

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)

'    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
    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