I am working on a project and it is getting larger and larger everyday, in this project I have a lot of components and we're managing the Color, state and other properties of these components from multiple buttons that resides in different containers. Explicitly writing the path of each component is very time consuming and it often leads to errors.
I am trying to create a global function, that can take the name or some kind of ID of a component and it should return the path of the component like this
btnExport = self.parent.parent.parent.getChild("GlobalContainer").getChild("Contianer1").getChild("ChildContainer1").getChild("SubChildContainer1").getChild("BtnExport")
and i can update the property from this btnExport variable.
I have found a function that gives the path of a component
def runAction(self, event):
def getPath(Component):
path = Component.name
if Component.parent is not None:
path = '%s/%s'%(getPath(Component.parent),path)
return path
But it does not take the name or some kind of ID I have to again provide the complete path of the component.
So is there a way to get the path like this in ignition perspective.
btnExport = self.parent.parent.parent.getChild("GlobalContainer").getChild("Contianer1").getChild("ChildContainer1").getChild("SubChildContainer1").getChild("BtnExport")
It sounds like you're trying to achieve something that you should be using bindings on the components for instead. What's the actual problem you're trying to solve?
I think problem statement is pretty much in the question. But let me rewrite it.
Example
There is a button ButtonA in Container A and this container is nested in multiple containers. And I am trying to change the color of this button when a specific row in a table is clicked, now in the future my boss has decided to change the location of this button to a different container, and that container is again nested in multiple containers.
Now I have to update the path of this button's color property from the row click and other places where that property is being use.
I want to ease this part of the problem where I don't have to update the path of the property each time I change the location of the button.
You should reverse the logic: make the button's color depend on a state, with bindings. Don't push the color to the button.
The click event on the row shouldn't event be aware that there are buttons reacting to it. Change a property, or send a message, and have the button react to that.
If it's behind a thousand layers of containers, then maybe passing parameters is not practical. In that case, send a message. Let the row event broadcast "I've been clicked !" and let whatever needs to react to this catch the message and do its job.
4 Likes
Depending on situation, you can also use session custom props as well. Bindings are preferable to message handlers for display of state, since they will evaluate when the page is changed away and back again
2 Likes
I should have been more accurate:
Don't use a message handler to change the colors, use it to change the state the colors are based on.
3 Likes
Avoiding deep and changable component location paths for bindings is best achieved with view custom properties.
2 Likes