1 Reply Latest reply on Jul 23, 2009 1:35 PM by chris.smith

    Automatic check for Backannotation. Expedition / DC workflow

    chris.smith

      For the transition between WG2005 and EE2007.3; automatic backannotation was removed due to some form of Dx requirement or decision?.

       

      This is a serious issue with DC/Expedition users because it will NOT warn you if there is a pending backannotation before exiting a

      design and the "status lights in the corner do not indicate a pending back-anno" You have to rely on users remembering to open PCB Intergration

      and checking the status manually. Of course this is prone to human errors and I personally have seen corrupt jobs because of this

      at our company and other users.You can reproduce this by renumbering the design and exiting (no warning & no status light).

       

      I hope mentor will recognize the issues they are creating by this removal of this fundamental process.

       

       

      Anyhow, pleading and wishing aside...... Add your complaint to "SR 2239238751".

       

      We were forced to write our own automation to watch for the exit and then check the status and allow users to back annotate or not.

       

      Attached is the code that we are using: You will need to tweak relative paths for

       

      "Const strFile = "\\immortal\apps\nitools\statmon\stats.csv""

      and "\\immortal\apps\NITools\StatMon"

       

      Use and tweak at your own risk, blah blah

       

      Essentially this will check if the job needs to be backannotated before you exit> Allows you to review the "backanno preview" report
      and back annotates or not w/user logging to a metric csv file

        • 1. Re: Automatic check for Backannotation. Expedition / DC workflow
          chris.smith

          '(Declarations)

          Option Explicit 'All variables must be declared using the 'Dim' statement

           

          Const eprjintStatusRequired = 1

           

          'Statmon

          Dim sobjSM, sobjNet

          Const ForAppending = 8

          Const strFile = "\\immortal\apps\nitools\statmon\stats.csv"

          Set sobjSM = CreateObject("Scripting.FileSystemObject")

          Set sobjNet = CreateObject("WScript.Network")

           

          '------------------------------------------------------------------------------

          ' Main routine

          '------------------------------------------------------------------------------

          Call Scripting.AddTypeLibrary("MGCPCB.ExpeditionPCBApplication")

           

          ' Get the application object

          Dim pcbApp

          Set pcbApp = Application

           

          Dim sbPrompt : sbPrompt = True ' Global variable to enable/disable checking back anno status

          ' If this global variable is not used, then the user will be prompted to run back anno

          ' when an operation such as Renumber Ref Des is run.  Apparently, reloading the DB causes

          ' OnPreClose to fire?!?

           

          If (Not pcbApp Is Nothing) Then

          ' Get the active document

          Dim pcbDoc

          Set pcbDoc = pcbApp.ActiveDocument

           

          If (ValidateServer(pcbDoc)) Then

          ' Main code

          Call Scripting.AttachEvents(pcbDoc, "pcbDoc")

          Scripting.DontExit = True

          Else

          MsgBox "Error: Licensing failed"

          End If

          End If

           

          'Note: Using the event pcbDoc_OnPreClose causes problems.  It will fire

          'whenever the database changes and potentially cause lock-ups if a dialog

          'cannot not display (aka "Save libraries?").  This event works beautifully.

          Function pcbDoc_OnClosing()

          Dim objPrjInt : Set objPrjInt = pcbDoc.ProjectIntegration

           

          If (sbPrompt = True) Then

          If (objPrjInt.BackAnnotationStatus = eprjintStatusRequired) Then

          If (objPrjInt.IsBackAnnotationAllowed = True) Then

          ' Back anno required

          Dim response

          response = MsgBox("Back annotation is required.  Preview changes?", 36, "Preview?")

          '36 = vbYesNo | vbQuestion

          If (response = vbYes) Then

          If (PromptForSave() = True) Then

          On Error Resume Next

          Call pcbApp.Gui.ProcessKeyin("xr backannopreview")

          If Err <> 0 Then

          Call MsgBox("Back annotation preview failed", 48, "Failure!")

            '48 = vbOK | vbExclamation

          End If

          Err.Clear

          On Error GoTo 0

          End If

          End If

           

          response = MsgBox("Run back annotation?", 36, "Run?")

            '36 = vbYesNo | vbQuestion

          If (response = vbYes) Then

          On Error Resume Next

          Dim bSuccess : bSuccess = objPrjInt.BackAnnotate

          If (Err.Number = 0) Then

          If (bSuccess = True) Then

          Call MsgBox("Back annotation completed successfully.", 64, "Success!")

             '32 = vbOK | vbInformation

          Call PhoneHome("Saved!")

          Else

          Call MsgBox("Back annotation failed.", 48, "Failure!")

          '48 = vbOK | vbExlamation

          End If

          Else

          Call MsgBox(Err.Description, 48, "Failure!")

          '48 = vbOK | vbExclamation

          End If

          Err.Clear

          On Error GoTo 0

          End If

          Else

          Call MsgBox("A back annotation is possible, but it is not allowed." & vbLf & _

          "Please review your settings in Design Capture", 64, "Back Annotation Disabled")

          '64 = vbOK | vbInformation

          End If

          End If

          End If

          End Function

           

          'Check to see if the database is being updated.  If it is, prevent prompting the user

          'to back annotate.

          Sub pcbDoc_OnNotify(eType)

          If (eType = epcbOnNotifyReloadStart) Then

          sbPrompt = False

          ElseIf (eType = epcbOnNotifyReloadComplete) Then

          sbPrompt = True

          End If

          End Sub

           

          Function PromptForSave

          If (pcbDoc.IsSaved = False) Then

          Dim response

          response = MsgBox("Document MUST be saved before preview.  Save now?", 36, "Save?")

          '36 = vbYesNo | vbQuestion

          If (response = vbYes) Then

          'Give saving a shot - might not work, oh well

          PromptForSave = pcbDoc.Save()

          Else

          'User opted not to save

          PromptForSave = False

          End If

          Else

          PromptForSave = True 'Document is already saved

          End If

          End Function

           

           

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

          ' Function that returns a licensed doc object

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

          Function ValidateServer(doc)

          Dim keyInt

          Dim licenseTokenInt

          Dim licenseServer

           

          'Ask Expedition's document for the key

          keyInt = doc.Validate (0)

           

          'Get license server

          Set licenseServer = CreateObject ("MGCPCBAutomationLicensing.Application")

           

          'Ask the license server for the license token

          licenseTokenInt = licenseServer.GetToken (keyInt)

           

          '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(licenseTokenInt)

          If Err Then

          ValidateServer = 0

          Else

          ValidateServer = 1

          End If

          End Function

           

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

          ' Subroutine that writes data to \\immortal\apps\NITools\StatMon

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

          Sub PhoneHome(strMsg)

          On Error Resume Next

           

          Dim objFileWrite, objFile

           

          Set objFile = sobjSM.GetFile(strFile)

          'If the file is read-only, make it not

          If objFile.Attributes And 1 Then

          objFile.Attributes = objFile.Attributes - 1

          End If

           

          'Append data to file

          Set objFileWrite = sobjSM.OpenTextFile(strFile, ForAppending, True)

           

          objFileWrite.WriteLine("Back Anno Check," & sobjNet.UserName & "," & Time & "," & Date & "," & strMsg)

          objFileWrite.Close

           

          'Make the file read-only again

          objFile.Attributes = objFile.Attributes + 1

           

          Err.Clear

          On Error Goto 0

          End Sub