8 Replies Latest reply on May 22, 2014 12:16 AM by henry.yiu

    Dialog Object -

    henry.yiu

      Hello,

       

      I am using Xpedition and want to write a simple VBS script to place via array.  Okay, so I can use the script to open the "Edit->Place->Via" dialog box, but how can I enter the X and Y location into the text box using the script?  There are only three methods: FindButton Method, FindCheckBox Method, and ProcessCommand Method, and none of these is useful to get to the text input box.  Why there are no FindTextInputBox Method for dialog box, etc?

       

      I can enter <Tab> four times using the keyboard to get to the text input box, but I don't see a way to send keys using the script.

       

      The other way is to use the KeyIn command, but unfortunately, the "pv" keyin command does not support coordinate input: "pv xy=100,100".

       

      So is there any simple way to place via array using script?

       

      Regards,

      Henry

        • 1. Re: Dialog Object -
          henry.yiu

          Okay, no one answer.  But I finally use the document.PutVia method, and I can use it to place via array as shown in below VBS script.

          Unfortunately, the PutVia method will cause a VBS runtime error when the via is put in a location with DRC violation - kind of a disgraceful error handling.

          Ideally, I want it to be able to continue the placement.  Any idea how to do it?

           

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

          ' Subroutine to place via array.

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

          Sub myPlaceViaArrayMethod(nID)

           

              Dim docObj,padStackObj,netObj,viaObjColl,viaObj

              Dim xStart,yStart,xStep,yStep,xEnd,yEnd,px,py,found

           

              ' collect document object

              Set docObj = GetLicensedDoc(app)

              If (docObj Is Nothing) Then Exit Sub

           

              ' Get the via

              Set viaObjColl = docObj.Vias(epcbSelectAll)

              found = False

              For k = 1 To viaObjColl.count Step 1

                  If ( (viaObjColl.Item(k).Name = "HDIVIA") And (viaObjColl.Item(k).StartLayer = 1) And (viaObjColl.Item(k).EndLayer = 2) ) Then

                      Set padStackObj = viaObjColl.Item(k).CurrentPadstack

                      found = True

                      Exit For

                  End If

              Next

              If (Err Or (Not found)) Then

                  Call app.Gui.StatusBarText("Via not found", epcbStatusFieldError)

                  Exit Sub

              End If

           

              ' Get the net

              Set netObj = docObj.FindNet("GND")

              If (Err Or (netObj Is Nothing)) Then

                  Call app.Gui.StatusBarText("Net not found", epcbStatusFieldError)

                  Exit Sub

              End If

           

              ' Get X and Y location

              xStart = CDbl ( app.Gui.InputBox("X Start Location", "Via Array", "0.00") )

              yStart = CDbl ( app.Gui.InputBox("Y Start Location", "Via Array", "0.00") )

              xStep = CDbl ( app.Gui.InputBox("X Via Spacing", "Via Array", "1.00") )

              yStep = CDbl ( app.Gui.InputBox("Y Via Spacing", "Via Array", "1.00") )

              xEnd = CDbl ( app.Gui.InputBox("X Stop Location", "Via Array", "0.00") )

              yEnd = CDbl ( app.Gui.InputBox("Y Stop Location", "Via Array", "0.00") )

           

              ' Place via array

              For j = 0 To 1000 Step 1

                  py = yStart + j * yStep

                  If (py > yEnd) Then Exit For

                  For i = 0 To 1000 Step 1

                      px = xStart + i * xStep

                      If (px > xEnd) Then Exit For

                      Set viaObj = docObj.PutVia (px,py,padStackObj,netObj,Nothing,epcbAnchorNone,epcbUnitCurrent)

                      If (Err Or (viaObj Is Nothing)) Then

                          Call app.Gui.StatusBarText("Via place error", epcbStatusFieldError)

                          Exit Sub

                      End If

                  Next

              Next

           

              ' Placed

              MsgBox "Via Array Placed"

           

          End Sub

          • 2. Re: Dialog Object -
            michael.weber

            Hi,

             

            try this:

             

            docObj.TransactionStart(epcbDRCModeNone)

             

            BR Michi

            • 3. Re: Dialog Object -
              henry.yiu

              Hi Michi,

               

              This statement:

              docObj.TransactionStart(epcbDRCModeNone)


              allows me to place all the vias.  But actually what I want is to place the vias one by one, and do not place if there is DRC violation.  Then I tried the transaction method with epcbDRCModeDRC as follows.  Now the VBS runtime error occurred at the TransactionEnd(True) statement.  Ideally, the TransactionEnd(True) statement should return false and not cause any VBS runtime error.

               

                          If (docObj.TransactionStart(epcbDRCModeDRC) = True) Then

                              Set viaObj = docObj.PutVia (px,py,padStackObj,netObj,Nothing,epcbAnchorNone,epcbUnitCurrent)

                              If (Err Or (viaObj Is Nothing)) Then

                                  docObj.TransactionEnd(False)

                              Else

                                  docObj.TransactionEnd(True)

                              End If

                          End If

              • 4. Re: Dialog Object -
                Patrick.Cashman

                I have used this and it works:

                 

                pcbdoc.TransactionStart(1)

                via = pcbdoc.PutVia(x, y, pstack, net)

                pcbdoc.TransactionEnd(True)

                 

                It doesn't check for a via being outside the board outline, so you'd have to add that.  Also note, I do this in VB.net, so it might be slightly different if you are using vbscript or something.

                • 5. Re: Dialog Object -
                  henry.yiu

                  Hi Patrick,

                   

                  I am not able to get it to work with Transaction, as it always produce VBS runtime error for any DRC violation.  Now I have found a way to put via, using ActualPlaneShapes.  The via need to be within the plane shape to be placed.  The user only needs to adjust the plane spacing for this to work.  See below script:

                   

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

                  ' Subroutine to place via array.

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

                  Sub myPlaceViaArrayMethod(nID)


                      Const VIALAYER1 = 3

                      Const VIALAYER2 = 4

                      Const VIANET = "GND"

                      Const VIANAME = "HDIVIA"

                      Dim docObj,padStackObj,netObj,viaObjColl,viaObj,planeObjColl,planeObj

                      Dim xStart,yStart,xStep,yStep,xEnd,yEnd,px,py,found,inside1,inside2,i,j,k,msg,ans


                      ' Prompt user to change plane setting

                      ans = Gui.DisplayMessage ("To avoid DRC violation, change all planes thermals spacing and all planes object clearances to be > the via " &_

                                                "radius plus the DRC clearance.  Once the script is done placing vias, you can change back the settings.  " &_

                                                "you might want to play around with the plane hatch width also to see what is the optimal setting.  " &_

                                                "Otherwise, you can continue with the script and run DRC afterwards and delete those added vias that violate DRC.  " &_

                                                "If you have change the plane clearance, click YES.  If you want to delete the vias manually afterwards, click NO.  ", _

                                                "",epcbMsgBoxYesNoCancel)

                      If (ans = epcbMsgAnsCancel) Then Exit Sub


                      ' collect document object

                      Set docObj = GetLicensedDoc(app)

                      If (docObj Is Nothing) Then Exit Sub


                      ' Get the via

                      Set viaObjColl = docObj.Vias(epcbSelectAll)

                      found = False

                      For k = 1 To viaObjColl.count Step 1

                          If ( (viaObjColl.Item(k).Name = VIANAME) And (viaObjColl.Item(k).StartLayer = VIALAYER1) And (viaObjColl.Item(k).EndLayer = VIALAYER2) ) Then

                              Set padStackObj = viaObjColl.Item(k).CurrentPadstack

                              found = True

                              Exit For

                          End If

                      Next

                      If (Err Or (Not found)) Then

                          Call app.Gui.StatusBarText("Via not found", epcbStatusFieldError)

                          Exit Sub

                      End If


                      ' Get the net

                      Set netObj = docObj.FindNet(VIANET)

                      If (Err Or (netObj Is Nothing)) Then

                          Call app.Gui.StatusBarText("Net not found", epcbStatusFieldError)

                          Exit Sub

                      End If


                      ' Get the plane collection

                      Set planeObjColl = docObj.ActualPlaneShapes(epcbSelectAll,0)

                      For k = 1 To planeObjColl.count Step 1

                          Set planeObj = planeObjColl.Item(k)

                          If (planeObj.Net Is Nothing) Then

                              planeObjColl.Remove(k)

                          Else

                              If (planeObj.Net.Name <> VIANET) Then planeObjColl.Remove(k)

                          End If

                      Next


                      ' Prompt user to get X and Y location

                      msg = app.Gui.InputBox("X Start Location", "Via Array", "0.00")

                      If (msg = "") Then Exit Sub

                      xStart = CDbl(msg)

                      msg = app.Gui.InputBox("Y Start Location", "Via Array", "0.00")

                      If (msg = "") Then Exit Sub

                      yStart = CDbl(msg)

                      msg = app.Gui.InputBox("X Via Spacing", "Via Array", "1.00")

                      If (msg = "") Then Exit Sub

                      xStep = CDbl(msg)

                      msg = app.Gui.InputBox("Y Via Spacing", "Via Array", "1.00")

                      If (msg = "") Then Exit Sub

                      yStep = CDbl(msg)

                      msg = app.Gui.InputBox("X Stop Location", "Via Array", "0.00")

                      If (msg = "") Then Exit Sub

                      xEnd = CDbl(msg)

                      msg = app.Gui.InputBox("Y Stop Location", "Via Array", "0.00")

                      If (msg = "") Then Exit Sub

                      yEnd = CDbl(msg)


                      ' Place via array

                      For j = 0 To 1000 Step 1

                          py = yStart + j * yStep

                          If (py > yEnd) Then Exit For

                          For i = 0 To 1000 Step 1

                              px = xStart + i * xStep

                              If (px > xEnd) Then Exit For

                              inside1 = False

                              inside2 = False

                              For k = 1 To planeObjColl.count Step 1

                                  Set planeObj = planeObjColl.Item(k)

                                  If (planeObj.Layer = VIALAYER1) Then

                                      If (planeObj.Geometry.IsPointEnclosed(px, py)) Then inside1 = True

                                  ElseIf (planeObj.Layer = VIALAYER2) Then

                                      If (planeObj.Geometry.IsPointEnclosed(px, py)) Then inside2 = True

                                  End If

                              Next

                              If (inside1 And Inside2) Then

                                  If (ans = epcbMsgAnsYes) Then

                                      docObj.TransactionStart(epcbDRCModeDRC)

                                  Else

                                      docObj.TransactionStart(epcbDRCModeNone)

                                  End If

                                  Set viaObj = docObj.PutVia (px,py,padStackObj,netObj,Nothing,epcbAnchorNone,epcbUnitCurrent)

                                  Call app.Gui.StatusBarText("Placing Via at " & px & " " & py, epcbStatusFieldPrompt)

                                  If (Err Or (viaObj Is Nothing)) Then

                                      docObj.TransactionEnd(False)

                                  Else

                                      docObj.TransactionEnd(True)

                                  End If

                              End If

                          Next

                      Next


                      ' Placed

                      MsgBox "Via Array Placed"


                  End Sub

                   

                   


                  • 6. Re: Dialog Object -
                    matthias.cosaert

                    Hi,

                     

                    You can use 'on error resume next'

                     

                    on error resume next

                    docObj.TransactionEnd(true)

                    on error Goto 0

                     

                     

                    If you want to group the actions in one undo you can also group all vias inside one transaction:

                      - Do a transaction of all vias with docObj.TransactionEnd (false) at the and detect & store which locations have an DRC error

                      - Do a second transaction with docObj.TransactionEnd (true) at the end but without placing the vias with DRC errors.

                    • 7. Re: Dialog Object -
                      henry.yiu

                      Matthias,

                       

                      The On error statement fixed the problem!

                      But it is strange that these statements have to be placed this way or else it will not work.

                       

                      Henry

                      • 8. Re: Dialog Object -
                        henry.yiu

                        Matthias,

                         

                        Actually it also works if I put "on error resume next" at the beginning of the subroutine, and put "Err.clear" after the "docObj.TransactionEnd(True)" statement.

                         

                        Henry