9 Replies Latest reply on May 15, 2013 12:56 PM by kendall_hiles

    Expedition Script to Get NetclassClearance from 2 Nets

    michael.weber

      Hi All!

       

      I'm looking for a script, that in best case ... should do the following:

       

      - With Left-Mous-Click select a net

      - with next click select 2nd net

       

      then I would see in epcbStatusField3 the names of netclass and the clearance of the 2 different netclasses.

       

      Something like : "-UG <> +UG 5.7mm".

       

      I look into Inside-Outside script for Mouse-Handling, but at the Moment I haven't enough time .... I can read out netclass from a net with "net.NetClass"

       

      Did have anyone a script, where I can look into it ? And, is it possible to bind this script to a "Hotkey", always available in pcb?

       

      BR Michi

        • 1. Re: Expedition Script to Get NetclassClearance from 2 Nets
          Patrick.Cashman

          As far as implementation it will be much simpler to first select two (or more) nets, then work on them.  The mouse event handling in Expedition is difficult, and you will spend a ton of time just getting that to work when it's not really necessary.

           

          Also there is the issue of CES automation being unavailable.  There is still a Clearance object in the PCB Document automation available, but I get exceptions thrown using it.  Clearance.GetNetClearanceRuleByType and Clearance.GetClearanceRule both cause errors.

           

          I do not know what is happening under the hood, but I suspect that the Clearance object is no longer valid in the current releases of Expedition. The CES database no doubt has higher level functions that the PCB is now accessing, and the leftover Clearance functionality may not have any data behind it.

           

          What is really going on with that function is a question for the folks at Mentor.

           

          I did a quick try at it, which you might try using as a starting point.  Perhaps you can find a way to overcome the exception errors that crop up with this.

           

          Sub get_clearance()

          Dim nets As MGCPCB.Nets

          Dim net As MGCPCB.Net

          Dim n, i As Integer

          Dim str As String

          Dim a As Object

          Dim b As Object

          Dim clr As MGCPCB.Clearance

          Dim dist as Double

           

          nets = doc.Nets(1)

          clr = doc.Clearance

           

          str = ""

          For n = 0 To nets.Count

          For i = 0 To nets.Count

          If Not i = n Then

          a = nets(n)

          b = nets(i)

          dist = clr.GetClearanceRule(a, b, 1, 1, 0)

          str = str & nets(n).Name & " < > " & nets(i).Name & " = " & dist & vbcrlf

          End If

          Next

          Next

           

          'now do whatever you want with the str value

          End Sub

          • 2. Re: Expedition Script to Get NetclassClearance from 2 Nets
            michael.weber

            Hi Patrick,

             

            mhm. Good Idea with GetClearanceRule.

             

            But when I try, I get an "Invalid Parameters" Error.

             

                 Set pcbNets = pcbDoc.Nets(epcbSelectSelected)

             

                  Set a = pcbNets(1)

                  Set b = pcbNets(2)

             

                  dist = pcbDoc.Clearance.GetClearanceRule(a, b, 1, 1, epcbUnitMM)

             

            Any Idea why ?

             

            BR Michi

            • 3. Re: Expedition Script to Get NetclassClearance from 2 Nets
              Patrick.Cashman

              No, I don't know.  I thought of changing the data type of a and b to MGCPCB.Net, but that yields the same result with an exception error thrown.

               

              I strongly suspect that because Expedition now uses CES for all its rules, and the Clearance object is a holdover from back when all the rules were self-contained (pre-CES) that the Clearance object is no longer valid. 

               

              I would like someone from Mentor who knows for certain to confirm this and let us know how to do this.  Removing the automation hooks to CES cripples us in this regard.

              • 4. Re: Expedition Script to Get NetclassClearance from 2 Nets
                Wolfgang_Antrey

                We use the following snippit to get the minimal distance between 2 nets ....

                 

                 

                        For Layer_tmp = 1 to pcbDoc.LayerCount step 1

                          MinClearanceLayer = 99

                          For Each NetComp1 In pcbDoc.Nets

                            For Each NetComp2 in pcbDoc.Nets

                               if NetComp1.Name <> NetComp2.Name then

                                 if ( ClearanceObj.GetNetClearanceRuleByType( epcbClearanceTrace, NetComp1, Layer_tmp, epcbClearanceTrace,  NetComp2, Layer_tmp, "(Master)", epcbUnitMM) < MinClearanceLayer) then

                                   MinClearanceLayer = ClearanceObj.GetNetClearanceRuleByType( epcbClearanceTrace, NetComp1, Layer_tmp, epcbClearanceTrace,  NetComp2, Layer_tmp, "(Master)", epcbUnitMM)

                                   NetStr1 = NetComp1.Name

                                   NetStr2 = NetComp2.Name

                                 end if

                               end if

                            next

                          next

                 

                          f1.WriteLine("    Mindestabstand innerhalb Layer " &  Layer_tmp & " (mm): " & MinClearanceLayer )

                 

                 

                Maybe this helps ...

                 

                Wolfgang

                • 5. Re: Expedition Script to Get NetclassClearance from 2 Nets
                  michael.weber

                  Hi Wolfgang,

                   

                  great inspirence for me! I changed your code a little bit. At the Moment I will only check on Layer 1,

                  but in my case, this is no prblem.

                  If so, I have to think about other ways to get Layer from selected Objekt.

                   

                  Here my Code-Snippet ....

                   

                  Sub main()

                   

                      Dim pcbNets, line, net, dist

                      Dim i, j, RealDist

                   

                      pcbApp.lockserver

                   

                      Call pcbApp.Gui.StatusBarText("Get Netclasses Clearance... ", epcbStatusField3)

                   

                      Set pcbNets = pcbDoc.Nets(epcbSelectSelected)

                      'pcbNets.Sort

                   

                      If pcbNets.count = 2 Then

                          'epcbClearancePad 2 Pad

                          'epcbClearancePlane 4 Plane

                          'epcbClearanceSMDPad 5 SMD Pad

                          'epcbClearanceTrace 1 Trace

                          'epcbClearanceVia 3 Via

                          For i = 1 to 5

                              For j = 1 to 5

                                  Call pcbApp.Gui.StatusBarText("i=" & i & " j=" & j, epcbStatusField3)

                                  If (i = 2 And j = 5) or (i = 5 And j = 2) Or (i = 5 And j = 5) Then

                                      'this Clearance Type is not supported

                                  Else

                                      dist = pcbDoc.Clearance.GetNetClearanceRuleByType( i, pcbNets(1), 1, j, pcbNets(2), 1, "(Master)", epcbUnitMM)

                                  End If

                                  If len(dist) > 0 Then

                                      RealDist = Dist

                                  End If

                              Next

                          Next

                          Line = pcbNets(1).NetClass & "(" & pcbNets(1).Name & ") <> " &  pcbNets(2).NetClass & "(" & pcbNets(2).Name & ") : " & RealDist & "mm"

                          Call pcbApp.Gui.StatusBarText(Line, epcbStatusField3)

                      Else

                          line = ""

                          select case pcbNets.count

                                  case 0

                                      line = "No net selected"

                                  case 1

                                      line = "only one net selected"

                                  case else

                                      line = "too much nets (" & pcbNets.count & ") selected"

                              end select

                          Call pcbApp.Gui.StatusBarText(Line, epcbStatusFieldError)

                      End If

                      pcbApp.unlockServer

                  End Sub

                  • 6. Re: Expedition Script to Get NetclassClearance from 2 Nets
                    steve_shively

                    iCES provides exactly this functionality in Expedition without the need to write any automation. Select the two nets, and open the clearances bar. iCES displays the actual clearnace as well as the specific rule area, net classes and class to class rule for these nets.

                    • 7. Re: Expedition Script to Get NetclassClearance from 2 Nets
                      michael.weber

                      Hi Steve,

                       

                      that's correct. iCES can do this ... but is only available with DX-Designer. But we are using the good old Design Capture....

                       

                      BR Michi

                      • 8. Re: Expedition Script to Get NetclassClearance from 2 Nets
                        Wolfgang_Antrey

                        Yes, iCES could do that, but if you need a report that shows you the actual minimal distance between two traces you have to read this out with automation.

                        I did not find any other way ...

                         

                        Wolfgang

                        • 9. Re: Expedition Script to Get NetclassClearance from 2 Nets
                          kendall_hiles

                          I wrote this about a month before iCES came out and depricated it.