How to Run Startup Script in Vision Designer

Script in internalFrameActivated and visionWindowOpened works perfect on vision client.

But not running on designer.
Is there a way to run startup script on vision designer?

You have to be in preview mode when you open the window.

1 Like

I think for startup of designer there's some trick if I recall of making a vision client tag with an on change script that will fire when designer is opened.

Thank you for your quick responses, otherwise I will keep thinking how to make this work.

In this vision window, I have an action to write component value to document tag.

If this component value doesn't update on window startup on designer, a developer will unintentionally write old designer value to document tag.

Instead, I will modify my strategy to bind component values to tag.

Wise. I never use those window events, for similar reasons.

In a pinch you can use runScript() in a run-once binding to execute a script no matter what mode the designer is in.

Can you tell me more where is this run-once binding?

I've never encountered a run-once binding anywhere within ignition.

This will run the target function once:

runScript("path.to.some.function", 0)

Same as the behavior of now(0) to capture a startup timestamp. These are "polling" functions that will only run once if the poll interval is set to zero. As documented.

Bindings that have no references to any other tag or property, and do not poll, will only execute once.

2 Likes

I found how I am doing it currently now that I'm at my office.

  1. Create a vision client tag with a type of DateTime
  2. Set tag to use expression now(0)
  3. Set the Value Changed event script to this and add your script inside the if block:
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	# If this is the first event after initial subscription and if the event is in the designer environment,
	if initialChange and system.tag.readBlocking(['[System]Client/System/SystemFlags'])[0].value < 4:
		# Put your script/code here that you want to run one time on startup of the designer

The OP is looking to run a script on window startup, not client startup.

Ahh, from reading the OP this morning, I thought they meant on designer startup. In all honesty, I just kinda glanced at the other messages to make sure I wasn't repeating something someone else already posted. Looking back now, I see they're talking about a window.

Add a custom property called isRunning and bind it to system flags:
image

//expression binding on the isRunning custom property
{[System]Client/System/SystemFlags} > 2

Then, run your initialization script on the propertyChange event handler:

# Custom Property that allows the change to be visible in the designer
# ...without having to close and reopen the window
if event.propertyName == 'isRunning' and event.newValue:
	# Do initialization stuff here

Any time preview mode is started or a client session is initialized, the tag value will change to a value greater than two and trigger the script.

That's a lot more trouble than just calling a custom method from a runScript() binding on a custom property in a window's root container. self in the custom method will be the root container.

Simply triggering a property change event from a tag binding doesn't seem like more trouble that creating a custom method and calling it from a runscript expression binding. It's just clear and clean coding approach that doesn't use run script.

Bindings with runScript() work in both design and preview mode. All other scripts only work in preview mode. The OP wants a script that will run on window open in the designer whether in design or preview mode.

:man_shrugging:

{ Your code also will run every time they change from design to preview. That isn't "run once". }

Exactly; I like that when I'm developing.