Hi,
So I try to make a startup session event, but every time I start my project it doesn’t run and it has a compiling error. In my perspective session property editor I have a custom value called operatorBlock and sometimes it just disappears. I try to make a session event on startup to generate this value, but I can’t really get it to work.
Anyone got some advice?
def onStartup(session):
session.props.locale = "en-US"
print("Locale (Language) is in English now (en-US)")
if 'operatorBlock' in session.custom:
operatorBlock = session.custom.operatorBlock
print(operatorBlock)
else:
session.custom.operatorBlock = "OperatorStartUp"
Is this an exact copy of the working version of the code? If so, be sure to indent your code correctly:
def onStartup(session):
session.props.locale = "en-US"
print("Locale (Language) is in English now (en-US)")
if 'operatorBlock' in session.custom:
operatorBlock = session.custom.operatorBlock
print(operatorBlock)
else:
session.custom.operatorBlock = "OperatorStartUp"
If this still doesn’t work, try:
self.session.props.locale
Could you try adding a logger and seeing if this script runs at all?
Here's your code rewritten to use tabs for indents consistently (while either spaces or tabs will work within Ignition's context, the built in editor uses tabs and you must be consistent to ensure no weird behaviors in Jython 2).
Separately, print is a statement, not a function, in Python 2.7 syntax, a detail LLMs perenially get wrong when you just ask them for "Python code to do X". But in any event print is not useful to you from a Perspective script; it will print to the wrapper log, not anywhere you can easily see. Use system.perspective.print instead.
def onStartup(session):
session.props.locale = "en-US"
system.perspective.print("Locale (Language) is in English now (en-US)")
if 'operatorBlock' in session.custom:
operatorBlock = session.custom.operatorBlock
system.perspective.print(operatorBlock)
else:
session.custom.operatorBlock = "OperatorStartUp"