+def get_instance_like(cell, name_contains, lev=0):
+ """get_instance_like: returns first instance with the word being searched
+ """
+ for inst in cell.getInstances():
+ name = inst.getName()
+ if name_contains in name:
+ print ("\t"*lev + "found instance like", name_contains, inst, name)
+ return inst
+
+ return None
+
+def rgetInstanceLike ( cell, path, lev=0):
+ """
+ Get the instance designated by path (recursively). The path argument can be
+ either a string of instance names separated by dots or directly a list of
+ instances names.
+
+ it also "reconstructs" the actual full path name of the instances
+ found recursively.
+ """
+ if isinstance(path,str):
+ path = path.split( '.' )
+ elif not isinstance(path, list):
+ raise ErrorMessage( 1, 'rgetInstanceLike(): "path" argument is ' \
+ 'neither a string or a list ({})"' \
+ .format(path) )
+ # find instance at this level
+ instance = get_instance_like(cell, path[0], lev)
+ if instance is None:
+ raise ErrorMessage( 1, 'rgetInstanceLike(): no instance "{}" ' \
+ 'in cell "{}"' \
+ .format(path[0], cell.getName()) )
+ iname = instance.getName()
+ # last instance (leaf search), return it
+ if len(path) == 1:
+ return instance, iname
+ # chew down another level, another brick in the wall
+ rinstance, rname = rgetInstanceLike(instance.getMasterCell(),
+ path[1:], lev+1)
+ # accumulate the names recursively found "level0.level1.level2..."
+ return rinstance, "%s.%s" % (iname, rname)
+
+