Session Events in designer startUp not running

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?

system.util.getLogger | Ignition User Manual

Still not indented correctly. The indent on the if is 2 tabs instead of just the proper 1. The if and else indents should line up...

1 Like

Stop asking LLMs for help with Ignition.

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"
1 Like

Also note this forum's rule on letting us know when you are showing us LLM output.

As an IA employee, Paul can't fully express how annoying this is.

As a forum regular, let me tell you: this is super annoying.

Just don't use LLM's with Ignition. At least until you already know how to use Ignition.

1 Like