3 Replies Latest reply on Jan 28, 2011 10:38 AM by matthias.cosaert

    Putvia, how to...

    Alpha


      Hello dear Members,
      i have a 8 Layers Design. There are many vias with the via span 1-8 on the board.

      Now i want to delete all these vias and replace  them with two stacked vias:
      with the via span 1-3 for the first and 3-8 for second.
      Very important here is that, the vias should be deleted and replaced without rerouting
      the design.


      i have written a script for this purpose , but it's not working properlly!
      Problem is that i can delete vias from nets, but cannot place them with the methode
      Putvia of the document object.

       

      In order to place a via manually,i just select the net a place the via with the mouse click.
      i am trying to do the same with a script but is not working.


      here is the entire script:

       

       

       


      Option Explicit

      'Add any type libraries to be used.
      Scripting.AddTypeLibrary("MGCPCB.ExpeditionPCBApplication")

      'Get the Application object
      Dim pcbAppObj
      Set pcbAppObj = Application

      'Get the active document
      Dim pcbDocObj
      Set pcbDocObj = pcbAppObj.ActiveDocument


      'License the document
      ValidateServer(pcbDocObj)
      ' Get the vias collection


      'Get pstkObj1all the paremeters needed to put a via
      Dim pstkObj1,pstkObj2

      Set pstkObj1 = pcbDocObj.PutPadstack(1, 3, "026VIA")
      Set pstkObj2 = pcbDocObj.PutPadstack(3, 8, "STANDARDVIA")


      ' Don't attach it to a component
      Dim cmpObj: Set cmpObj = Nothing

      ' Turn off error handling so the script
      ' can handle DRC violations
      On Error Resume Next
      Err.Clear
      ' Add the via where the user specified.


      Call pcbDocObj.PutVia(200, 200, pstkObj1, netObj, cmpObj)
      Call pcbDocObj.PutVia(200, 200, pstkObj2, netObj, cmpObj)


      Dim viaColl
      Set viaColl = pcbDocObj.Vias

      ' Get the number of vias in collection
      Dim countInt
      countInt = viaColl.Count
      MsgBox("There are " & countInt & " vias.")

      Dim viaObj ,viaName,viaPositionX, viaPositionY, viaStartLayer,viaEndLayer,viaNet,pNet
      Dim dX,dY

       


      For Each viaObj In viaColl

      viaName=viaObj.Name
      viaPositionX=viaObj.PositionX
      viaPositionY=viaObj.PositionY
      viaStartLayer=viaObj.StartLayer
      viaEndLayer=viaObj.EndLayer

      If (viaStartLayer=1) And (viaEndLayer=8) Then
          viaNet=viaObj.Net
          MsgBox viaNet

          dX= CDbl(viaPositionX)
          dY=CDbl(viaPositionY)
          netObj = pcbDocObj.FindNet(viaNet)
         
          MsgBox "netObject: "&netObj &" via_PosX:"&dX &"  via_posY:"&dY

         
          viaObj.delete
          netObj.Selected=True
          
        Call pcbDocObj.PutVia(dX, dY, pstkObj1, netObj, cmpObj)
        Call pcbDocObj.PutVia(dX, dY, pstkObj2, netObj, cmpObj)
       


      '' See if there was an error
      ' If Not Err.Number = 0 Then
      '' Display the error on the status bar
      ' Call pcbAppObj.Gui.StatusBarText(Err.Description, pcbStatusFieldError)
      '' Clear the error
      ' Err.Clear
      ' Else
      '' No error. Let the user know what happened
      ' Call pcbAppObj.Gui.StatusBarText("Placed via.",epcbStatusField3)
      ' End If
            
      End If

      'MsgBox "ViaName:"& viaName &"  PositionX:"& viaPositionX &"   PositionY:"& viaPositionY  &"   StartLayer:"& viaStartLayer  &"   EndLayer:"&viaEndLayer
        
      NExt
       

       

      Function ValidateServer(docObj)
         
      Dim keyInt    
      Dim licenseTokenInt    
      Dim licenseServerObj    
      ' Ask Expedition's document for the key         
      keyInt = docObj.Validate(0)    
      ' Get license server      
      Set licenseServerObj =  CreateObject("MGCPCBAutomationLicensing.Application") 
      ' Ask the license server for the license token   
      licenseTokenInt = licenseServerObj.GetToken(keyInt)
      ' Release license server   
      Set licenseServerObj = 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   
      docObj.Validate(licenseTokenInt)
      If Err Then  
      ValidateServer = 0     
      Else  
      ValidateServer = 1   
      End If  

      End Function


        • 1. Re: Putvia, how to...
          matthias.cosaert

          Hi,

           

          You should use transactionstart/end to disable the DRC so you still get the script errors (also makes it faster and all the actions are grouped into one undo).

          ViaObj.net returns an object so use 'set netObj = viaObj.Net'

           

           

          pcbDocObj.TransactionStart(epcbDRCModenone)
              'Get pstkObj1all the paremeters needed to put a via
              Dim pstkObj1,pstkObj2
          
              Set pstkObj1 = pcbDocObj.PutPadstack(1, 3, "VIA H=250, T=I=B=O700, M=No")
              Set pstkObj2 = pcbDocObj.PutPadstack(3, 8, "VIA H=250, T=I=B=O700, M=No")
          
          
              ' Don't attach it to a component
              Dim cmpObj: Set cmpObj = Nothing
          
          
          
              Dim viaColl,netobj
              Set viaColl = pcbDocObj.Vias
          
              'Get the number of vias in collection    Dim countInt
              countInt = viaColl.Count
              MsgBox("There are " & countInt & " vias.")
          
              Dim viaObj ,viaName,viaPositionX, viaPositionY, viaStartLayer,viaEndLayer,viaNet,pNet
               Dim dX,dY
          
              For Each viaObj In viaColl
          
                  viaName=viaObj.Name
                   viaPositionX=viaObj.PositionX
                   viaPositionY=viaObj.PositionY
                   viaStartLayer=viaObj.StartLayer
                   viaEndLayer=viaObj.EndLayer
          
                  If (viaStartLayer=1) And (viaEndLayer=8) Then
                      set netObj = viaObj.Net
          
                      dX= CDbl(viaPositionX)
                      dY=CDbl(viaPositionY)
                      
                      viaObj.delete
                      'netObj.Selected=True
                       
                      Call pcbDocObj.PutVia(dX, dY, pstkObj1, netObj,nothing)
                      Call pcbDocObj.PutVia(dX, dY, pstkObj2, netObj,nothing)
                     
                   End If
               NExt
                    
           pcbDocObj.TransactionEnd (True)
          
          • 2. Re: Putvia, how to...
            Alpha

            Hello Matthias,

            thank you first of all for your answer.

            I have added,  pcbDocObj.TransactionStart(epcbDRCModenone) and pcbDocObj.TransactionEnd (True) in my Testcase, but it's

            unfortunatly still not working.

            Did you test it ?

            I am hopping to hear from you very soon.

            • 3. Re: Putvia, how to...
              matthias.cosaert

              I tested it and it worked for me (I aslo deleted the first 2 putvia calls).

               

              currently it uses 'epcbDRCModenone' mode but If you define the via ranges in the setup parameters and set same net 1-3 <-> 3-8 via clearance 'P' as 0 (see attached image) then it should also work with 'epcbDRCModeDRC' (if no other DRC errors).

               

              This should work:

               

              Option Explicit
              
              'Add any type libraries to be used.
              Scripting.AddTypeLibrary("MGCPCB.ExpeditionPCBApplication")
              
              'Get the Application object
              Dim pcbAppObj
              Set pcbAppObj = Application
              
              'Get the active document
              Dim pcbDocObj
              Set pcbDocObj = pcbAppObj.ActiveDocument
              
              'License the document
              ValidateServer(pcbDocObj)
              
              
              
              
                  'Get pstkObj1all the paremeters needed to put a via
                  Dim pstkObj1,pstkObj2
               
                  Set pstkObj1 = pcbDocObj.PutPadstack(1, 3, "026VIA")
                  Set pstkObj2 = pcbDocObj.PutPadstack(3, 8, "STANDARDVIA")
              
                  ' Don't attach it to a component
                  Dim cmpObj: Set cmpObj = Nothing
              
                  Dim viaColl
                  Set viaColl = pcbDocObj.Vias
              
                  ' Get the number of vias in collection
                  Dim countInt
                  countInt = viaColl.Count
                 
              
                  Dim viaObj ,viaName,viaPositionX, viaPositionY, viaStartLayer,viaEndLayer,viaNet,netObj
                  Dim dX,dY
              
                  dim vialog
                  'pcbDocObj.TransactionStart(epcbDRCModeDRC)
                  pcbDocObj.TransactionStart(epcbDRCModeNoneWithBatchQuery)
                      For Each viaObj In viaColl
                          
                          viaName=viaObj.Name
                          viaPositionX=viaObj.PositionX
                          viaPositionY=viaObj.PositionY
                          viaStartLayer=viaObj.StartLayer
                          viaEndLayer=viaObj.EndLayer
              
                          If (viaStartLayer=1) And (viaEndLayer=8) Then
              
                              set netObj = viaObj.Net
              
                              dX = CDbl(viaPositionX)
                              dY = CDbl(viaPositionY)
                              vialog = vialog & viaObj.name & "    dX/dY = " & dX  & "/" & dY & vbnewline
                              viaObj.delete
              
                              Dim newViaObj1,newViaObj2
                              set newViaObj1 = pcbDocObj.PutVia(dX, dY, pstkObj1, netObj, cmpObj)
                              set newViaObj2 =  pcbDocObj.PutVia(dX, dY, pstkObj2, netObj, cmpObj)
              
                              newViaObj1.highlighted = true
                              newViaObj2.highlighted = true
                            
                          End If
                        
                      NExt
              
                      MsgBox("There are " & countInt & " vias." & vbnewline & vialog)
                   
                  pcbDocObj.TransactionEnd (True)
              
               
              
              Function ValidateServer(docObj)
                 
              Dim keyInt    
              Dim licenseTokenInt    
              Dim licenseServerObj    
              ' Ask Expedition's document for the key         
              keyInt = docObj.Validate(0)    
              ' Get license server      
              Set licenseServerObj =  CreateObject("MGCPCBAutomationLicensing.Application") 
              ' Ask the license server for the license token   
              licenseTokenInt = licenseServerObj.GetToken(keyInt)
              ' Release license server   
              Set licenseServerObj = 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   
              docObj.Validate(licenseTokenInt)
              If Err Then  
              ValidateServer = 0     
              Else  
              ValidateServer = 1   
              End If  
              
              End Function