Page tree
Skip to end of metadata
Go to start of metadata

Summary

  • For some applications, you might need to set a top level schematic and then find all objects in all schematics below them.

  • The example code is a simple example of this.

Code Snippets

 ' Code Module
Sub Main
     Dim sch As Schematic
     Debug.Clear

     Set sch = Project.Schematics("top")
     process_hierarchy(sch)
End Sub
Function process_hierarchy(s As Schematic)
     Dim ele As Element
     Dim ns As Schematic
     Debug.Print "Schematic = " & s.Name
     For Each ele In s.Elements
          Debug.Print vbTab & "Element = " & ele.Name
          If InStr(ele.Name,"SUBCKT") Then
               nt = Mid(ele.Parameters(2).ValueAsString,2,Len(ele.Parameters(2).ValueAsString)-2)
               If Project.EMStructures.Exists(nt) Then ' this is here because em structures show up as schematics in the .exists call.
                    ' do nothing
               ElseIf Project.Schematics.Exists(nt) Then
                    Set ns = Project.Schematics(nt)
                    process_hierarchy(ns)
               End If
          End If
     Next ele
End Function

 

  • This works by recursively calling the same function, called "process_hierarchy" in this case.

  • The script works by setting a top-level schematic and then calling the function and passing the schematic to the function.

  • In the function, it looks at all elements, if they are a subcircuit, it determines if the net of the subcircuit refers to a schematic (since it could be a netlist, sparameter file, em structure, etc).

  • if it is a schematic, the process hierarchy function is called again with the new schematic object.