Iterate through all components programatically in Perspective?

We went with this one so our util library looks like

def getComponents(element):
	def walkComponents(component):
		for child in component.children:
			yield child
			walkComponents(child)
	return walkComponents(element)

def parseContainer(container):
	return {
		c.name: c.custom["outValue"]
		for c in getComponents(container) if "outValue" in c.custom
	}

and call parseContainer on a container works as we expect it too.

Decided on this one because it's the most readable to me and without needing a library.

Thank you all very much!

7 Likes

Hello I'm having a similar problem:

I have a view with a bunch of components. Each one of them has the following custom properties : name (bined to the meta name to make the iterating code simpler), tagPath, and status.

How can I iterate through that view's components and spit out a dictionary of dictionaries which should look like this below?

myList = 
{
"EmbeddedView_1": {"name": EmbeddedView_1,"tagPath": "some path", "status": "open"},
"EmbeddedView_2": {"name": EmbeddedView_2,"tagPath": "some_other_path", "status": "close"},
"EmbeddedView_2": {"name": EmbeddedView_3,"tagPath": "a_different_path", "status": "close"},
 etc ...
}

Thank you.
Basel