How to reference component properties in a module?

I have a number of properties (colours) in the root container. I want to change these properties based the properties of various components on the screen. (eg: is a switch open/close)

I know I could write an expression for each colour but a lot of the code would be duplicated. So I want to write a common module for each component type.

So the expression would look a bit like this:
if (app.SC5802.is_1_live(“component”) , color(1,2,3),
if (app.SC5802.is_1_live(“other component”) , color(2,3,4),
color(3,4,5))

My problem is how do I reference the component properties in the module is_1_live() ?

Robert,

If you know the window and component name, you can get a reference to a component with the following script code:

from fpmi.gui import getWindow window = getWindow("Window Name") component = window.rootContainer.getComponent("Component Name")
Once you have a reference to the component, you can reference the component’s properties with statements like this:

property = component.property

If you need to access different windows and/or components, you might possibly be able to use global variables that you update in various ways.

To reference the module scripts as an expression, you’ll need to use the runScript() expression language function.

Hopefully this is what you’re looking for.

Thanks, MickeyBob

That should do it.

Almost, I’m passing in the property name to the module.

component.property treats property as a literal not a variable.

getPropery() doesn’t work on a component

How can I find the value of a property when I only have the name of the property?

Robert,

If the possible property names are limited, you can have an if, elif, else sequence of statements that checks the property string/variable. For example:

if propertyString = "property1": component.property1 = something elif propertyString = "property2": component.property2 = somethingelse elif propertyString = "property3": component.property3 = somethingelseagain ...

I guess I could do that. It is not very elegant though.

Off to the feature request forum…

There may be a more generic/fancier way to do this using “component.class.dict” but I want to experiment a little before I give more specifics.

Robert,

I’ve got a solution for you. You’re not going to believe how easy it is.

Try something like this:

window = getWindow("WindowName") component = window.rootContainer.getComponent("ComponentName") setattr(component, 'propertyName', someArbitraryValue)

Thanks for that. I got the answer I needed over here