Syntax error on Ignition 7.9.6 when writing simple code


I am trying to write a code that enables the visibility of a button if the machine being used matches a certain IP address using an if/else statement. I’m getting a syntax error on the first line, it doesn’t like the “=” for some reason, and didn’t work when I changed it to “==” either. I’m not the best at this aspect of Ignition, and would really appreciate a nudge in the right direction.

Thanks so much!


ip =
if ( ip == “192.168.245.XXX”, event.source.parent.getComponent(‘Button 4’).visible = True,
event.source.parent.getComponent(‘Button 4’).visible = False)

You are trying to use the syntax from expression bindings in python. Use pure python.

Thanks for the speedy response! However I’m sorry to say that I’m not sure what you mean when you say to use pure python. Could you elaborate on that please? I’m writing this script on the “Visible” property for the button component, so I should write it somewhere else and not within the binding? If so, where? I appreciate your time, thanks.

Ah, in the binding, you can only use the expression language, not python. Your first line is a python script call. You would use the [System] tag that holds the client IP address. No need for an if function, just the comparison to the desired string.

{Strictly speaking, bindings can call python via the runScript function, but I don’t recommend that for most cases.}

1 Like

That worked! I entered
{[System]Client/Network/IPAddress} = “192.168.245.XXX”
When I changed my IP address the button went invisible. Appreciate it!