1 Reply Latest reply on Jan 5, 2012 12:11 PM by Patrick.Cashman

    DxD - Trying to Generate an X-Ref

    pete.osborne

      I have a couple of designs that are 6 levels of Hierarchy.   Unfortunately, the XREF utility has an issue with the number of levels and buses that we have in these designs (As detailed in http://supportnet.mentor.com/reference/technotes/public/technote.cfm?tn=mg67701).  So, .I thought I'd try my hand at writing an XREF utility for these designs.

       

      Everything was moving along smoothly, byt then I ran into a problem where I think I'm doing something silly, but I can't figure out what it is.  I have two questions:

       

      1)  Is there a way to traverse through the hierarchy to capture the relative location of each comonent without using views?  (i.e. I don't want to have every schematic sheet open if I don't need to)

       

      2) Assuming that the answer to number 1 is no,   Can anyone see anything obviously wrong with the code below:

       

      Specifically, around this section

                  If oProj.pushpath ( sDesignName , sPath, sSheet) Then

                      'Now, go through each component and only look at the ones we care about

      '                msgbox "There are " & oProj.ActiveView.Query(VDM_COMP, VD_ALL).Count & " components on this sheet"

                      For Each oComp In oProj.ActiveView.Query(VDM_COMP, VD_ALL)

                          'For this script, I only want to work with symbols that are of type Pin or Annotate

                          msgbox ocomp.symbolblock.getname(FULL_PATH_NAME)  & " is of type " & ocomp.symbolblock.symboltype

                          If ((oComp.SymbolBlock.SymbolType = VDB_ANNOTATE) Or (oComp.SymbolBlock.SymbolType = VDB_PIN)) Then

       

       

      The code does not fail, it's just not getting into the VDB_ANNOTATE if statement even though, I have specifcally placed symbols of that type on the low level sheets.

       

      Function CreateXREF()

          Dim SheetScope, HierScope

          Dim oTemp, sTemp

          Dim AllComps, oAllBlocks

          Dim oComp, oAttr

          Dim sAttName, oXYpos, lVisibilityFlag, sRefDes, bNuke

          Dim oNet, ocNetAttr

          Dim oBlk, sSymType, sSymName, sSymNum, sSchName, sPath, sBlockName, sSheet

          Dim oConn, oCompPin, oPoint, sXLoc, sYLoc, sNetName, oNetSegment, iSheetCount, iBlockCount, oSheet

       

          Dim collBlocks        ' A collection of all the Blocks in the design

                              ' The Key will be the Block Name

          Dim collSheets        ' A collection of the schematic sheets

                              ' The key will be the schematic sheet name.  The Value will be the Sheet number used for XREF  

       

       

       

          SheetScope = "-1"   ' Indicates to look at all sheets

          HierScope = True    ' Indicates to search through all hierarchies

       

          If Not (Initialize_Design) Then

              msgbox "Design did not initialize properly"

              CreateXREF = False

              Exit Function

          End If

       

          Call oProj.StatusBarText("Xref Attributes removed from Nets")

          'A collection to hold a list of the blocks

          '    The Key is the Path

          '    The Value is the Block Name

          Set collBlocks = CreateObject("Scripting.Dictionary")

      '    iSheetCount = 0

          Call oProj.StatusBarText("Building Schematic Sheet List")

          'Add the root block to the collection of blocks

          collBlocks.add "", sDesignName

          'Find the Hierarchical Blocks in the design

          For Each oComp In Application.DesignComponents("", sDesignName, "-1", "STD", True)

              'Check every composite symbol to see if there is an underlying schematic

              If oComp.SymbolBlock.SymbolType = VDB_COMPOSITE Then

                  sPath = oComp.GetName(FULL_PATH_NAME)

                  On Error Resume Next

                  sSchName = oComp.SymbolBlock.GetChildBlock.GetName(FULL_PATH_NAME)

                  If Err.Number > 0 Then

                      sSchName = objComp.SymbolBlock.GetName(FULL_PATH_FROM_BLOCK)

                  End If

                  err.clear

                  On Error goto 0

                  'Add the Path and the Schematic name to the Collection

                  collBlocks.Add  sPath, sSchName

              End If

          Next

          'This would be the point if you want to renumber the order that your blocks show up in.

       

       

          'Create a collection of Sheets

          '    the Key is the full path to the Sheet

          '    the Value is the Overall Sheet Number

          Set collSheets = CreateObject("Scripting.Dictionary")

          iSheetCount = 0

          For Each sPath In collBlocks.Keys

              sSchName = collBlocks(sPath)

              msgbox "About to open " & sSchName & " from " & sPath

              For Each sSheet In oProj.SchematicSheetDocuments.GetAvailableSheets(sSchname)

                  sTemp =  sPath & "\" & sSchName & "." & sSheet

                  iSheetCount = iSheetCount + 1

                  'msgbox "Adding sTemp=" & sTemp & " and iSheetCount=" & iSheetCount & " to the collection"

                  collSheets.add sTemp, iSheetCount

                  'msgbox "About to Push sDesignName=" & sDesignName & " and sPath=" & sPath & " and sSheet=" & sSheet

                  If oProj.pushpath ( sDesignName , sPath, sSheet) Then

                      'Now, go through each component and only look at the ones we care about

      '                msgbox "There are " & oProj.ActiveView.Query(VDM_COMP, VD_ALL).Count & " components on this sheet"

                      For Each oComp In oProj.ActiveView.Query(VDM_COMP, VD_ALL)

                          'For this script, I only want to work with symbols that are of type Pin or Annotate

                          msgbox ocomp.symbolblock.getname(FULL_PATH_NAME)  & " is of type " & ocomp.symbolblock.symboltype

                          If ((oComp.SymbolBlock.SymbolType = VDB_ANNOTATE) Or (oComp.SymbolBlock.SymbolType = VDB_PIN)) Then

                              'Create a handle to the symbol

                              Set oBlk = oComp.SymbolBlock

                              sSymType = oBlk.SymbolType            'The type = Annotate or Pin in this Case

                              sSymName = oBlk.GetName(FULL_PATH_NAME)    'the name of the Symbol

                              sSymNum = oBlk.SheetNum                'The number of the symbol ie in.1 or in.2

                              'sSchName = oComp.Parent.GetName(FULL_PATH_NAME) & "." & oComp.Parent.SheetNum

                              'I personally don't really care about symbol Type. Just the name of the symbol

                              msgbox sSymName

                              Select Case uCase(sSymName)

                                  Case "IN", "OUT", "IN_OUT", "SHEET_BI", "SHEET_ON", "SHEET_OFF"

                                      'Find all the pins on the symbol. For us, we could check if greater than 1

                                      ' - but later

                                      msgbox "About to look at the connections on " & sSymName

                                      For Each oConn In oComp.GetConnections

                                          'Create a handle to the Component Pin Object

                                          Set oCompPin = oConn.CompPin

                                          'Create a handle to the coordinates of the pin

                                          Set oPoint = oCompPin.GetLocation

                                          sXLoc = oPoint.X

                                          sYLoc = oPoint.Y

                                          'Now, grab the net information

                                          Set oNet = oConn.Net

                                          sNetName = oNet.GetConnectedNetName(oConn.Segment)

                                          'Store the information in an array

                                          MsgBox sSymname & "." & sSymNum & " on " & sSchName & " has a pin at X=" & sXLoc & " Y=" & sYLoc & " connected to net " & sNetName & " on Sheet " & iSheetCount

       

                                      Next

                                  Case Else

                                      'most likely the border  Can use this section in the write section to write the "Sheet a of n"

                              End Select

       

                          End If

                      Next          

       

       

                  Else

                      'Something bad happened if you weren't able to push into that schematic sheet

                      msgbox "Something failed using sDesignName=" & sDesignName & ", sPath=" &  sPath & ", sSheet=" & sSheet

                  End If

              Next

          Next

       

      'dbg    For Each sTemp In collSheets.Keys

      'dbg        msgbox sTemp & " is sheet number " & collSheets(sTemp)

      'dbg    Next

       

          Exit Function

       

       

       

          Call oProj.StatusBarText("")

          CreateXREF=TRUE

      End Function

        • 1. Re: DxD - Trying to Generate an X-Ref
          Patrick.Cashman

          I think the answer to 1) may be yes.

           

          Try using Application.DesignComponents, then Component.GetName.  DesignComponents gives you a reference to all the components in the design.  I use it like this:

           

           

           

                  scomps = Nothing

                  'load all components into scomps.  scomps will get a reference to every component in the design

                  design_name = app.GetProjectData.GetiCDBDesignRootBlock(app.GetActiveDesign())

                  scomps = app.DesignComponents("", design_name, "-1", , False)    'gets all the components in the design

           

                  refdes.Clear

                  ref_data.Clear

                  For Each scomp In scomps

                      if scomp.refdes = "" then goto next_scomp

                      If instr(scomp.refdes, "ITAR") >= 1 Then GoTo next_scomp

                      If instr(scomp.refdes, "aero_logo") >= 1 Then GoTo next_scomp

           

                      'load up the ref_data dictionary: refdes, x & y values, sheet number

                      redim ary(2)

                      pt = scomp.getlocation

                      x = pt.X

                      y = pt.Y

                      ary(0) = x

                      ary(1) = y

                      ary(2) = scomp.Parent.SheetNum

                      if not ref_data.ContainsKey(scomp.refdes) then

                          ref_data.Add(scomp.refdes, ary)

                      End If

           

                      'load up the refdes arraylist (just reference designators)

                      refdes.Add(scomp.refdes)

                      next_scomp:

                  Next

           

           

          You can put anything in the For/Next loop you want, from all the properties of each component.

           

          Using this method doesn't open any sheets, so it's much faster than cycling through all the sheets.  You might need to put another loop to cycle through all the schematics in your design for what you are trying to do, but that's not too hard either.