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.
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.