Get all components

I'm trying to iterate through some components on a window. Is there a way to grab components in an array? I'm familiar with getComponent - is there another function to grab all components?

You can call the getComponents() method on a container to get an array of all components in a container.

For example:

for comp in event.source.parent.getComponents():
	print comp.name

You could get the root container, get all the components in the root container and then check to see if any of those components are containers and if so get all the components in those containers etc. recursively. That would get you all the components (and nested components) within the root container of a window.

Will try that…thank you. Is getcomponents documented somewhere?

Yes, in the Java documentation: docs.oracle.com/javase/7/docs/ap … ents%28%29

Much of the Ignition GUI is built using Swing/AWT components.

Nick

I did some digging with Python. The getComponents method may be being overridden by another class that we don’t have documentation about.

I’d like to get a component and test if it’s a check box but I can’t seem to get it to work

win = system.gui.getWindow(“Trending/ToolScreens/Trend”)

template = win.getRootContainer().getComponent(“TrendView”).templates

comps = win.getRootContainer().getComponents()

tags = system.tag.browseTags(parentPath = “Trends/Tag History Pens”)

param = “TagPath”

x = type(comps[0])

for comp in comps:

print comp == x

Is there a way to get type of component? I am looking to find all the power tables I have within a window.

Python's native type() function will give you the class of a java object, from which you can see what kind of component it is.

didn't think of that actually, thanks so much

# Written for the action performed event handler of a button in the root container of the window.
# Iterate through all of the components
for component in event.source.parent.components:

	# Check to see if the component is a power table
	if 'VisionAdvancedTable' in component.__class__.__name__:
		
		# If so, print the name of the component to the diagnostic console
		print component.name

If the power tables are nested in containers, then move this to a recursive function that gets called again any time a BasicContainer class is encountered during an iteration.