TypeError:getComponent():1st arg cant't be coerced to int

So I think I have the hang of this scripting stuff, but I have ran into a problem I’ve been trying to figure out for the past two days.
Im using Kymera Map Module
Ignition 8.0.1
I want when mouse enters the point to popup a label with values. I can get them to print to the console but when I try to
send the text to a label using

def onPointEntered(self, event, point):
event.source.parent.getComponent(‘Label 8’).text = “Hello Hello”

I get the following:

File “”, line 12, in onPointEntered
TypeError: getComponent(): 1st arg can’t be coerced to int

Any thoughts?

That’s not a Numeric Label is it? This is for the MouseEntered property change?

No, it’s just your typical Display Label.
onPointEntered() is from the kymera module.
I figured it was a random enough error that anyone with scripting knowledge could elaborate.

I got in touch with Kymera here is what they advised:

We would suggest you to use self(first argument of onPointEntered()) instead of event.source for what you are doing, So your code will look like
self.parent.getComponent(‘Label 8’).text = “Hello Hello”

Here is little explanation of why you are getting that error. In onPointEntered() method, event.source.parent gives you the pointLayer and not the Root Container of the window. The getComponent() for pointLayer takes integer argument which is the index of the point on Map Panel.
For example: If you still want to use “event” argument for what you are doing, you can achieve that with below code: event.source.parent.getComponent(0).parent.parent.parent.getComponent(‘Label’).text = “Hello Hello”
where getComponent(0) gives you the first point on the Map.

I can tell you where it’s coming from, but not really what the fix is - it looks like Kymera might need to do something differently. getComponent() is actually a base method on Java’s Container class - but it only accepts integers, as component index paths. In Ignition, we wrap all of our classes when we expose them to scripting, and we added an “overload” to getComponent that allows you to specify a single component’s name - but that breaks down if you ever get outside the boundaries of what we “expect” you to reach in scripting. For example, if you wanted to deeply customize, say, an alarm status table…you would need component index paths to reach a button to change its font size.

If you want a detailed explanation, this thread might help, particularly the pitfalls and their work-arounds:

Note that I wouldn’t expect Kymera’s PointLayer to take string lookups, so the wrapper is moot.

1 Like