UDT template button write to tag script

I'm quite new to Ignition. I apologize in advance for not finding the forum or manual blurb that is the answer to my problem.

Situation:
I have many motors so making a template. I'm mimicking "UDTs and Template Views" from IA University.

Problem:
My onActionPerformed Script for my Primary Button is not turning on my UDT instance tag.

I've read quite a bit in the Perspective 8.1 manual and read and tried a lot from the forum but haven't found the solution. (BTW-a huge thank you to all contributors to the forum!)

I'm on my 400th variation of the script and so far, no joy. I don't get errors anymore and thought, "that's good". But in this case, no news isn't good news.

Primary Button onActionPerformed script:

def runAction(self, event):
	startPath = {self.view.params.SimpleMtr.Start_SCADA}
	system.tag.writeBlocking("startPath","true")

If I change the script to a discrete path, it works but of course, only for that one tag.

startPath = "[default]testSimpleMtr_2/Start_SCADA"
system.tag.writeBlocking(startPath,"true")

UDT instance:
image

Params:

Eventually, I'll go the "dropConfig" route but I have to get this working first.

Gentlemen, I greatly appreciate the feedback!

Bryon

A couple of pointers to get you going:

{self.view.params.SimpleMtr.Start_SCADA}

You are creating a dictionary. system.tag.writeBlocking requires a list.

system.tag.writeBlocking("startPath", "true")

Two problems here. You are passing literal strings into the function instead of variables. "startPath" is not the same as startPath. Similarly "true" is not the same as True.

Try this:

def runAction(self, event):
	startPath = [self.view.params.SimpleMtr.Start_SCADA]
	values = [True]
	system.tag.writeBlocking(startPath, values)

Gentlemen, I greatly appreciate the feedback!

<Cough!>

1 Like

It also appears that self.view.params.SimpleMtr.Start_SCADA is the value of the Start SCADA tag, not the path.

I would restructure this view so that the only param is a tag path to a simple motor UDT. Then add a custom prop called SimpleMtr which has an indirect tag binding to that tag path param.

1 Like

Gentlemen, I greatly appreciate the feedback!

Also not to be that person but we're not all gentlemen here, it's good practice to use gender neutral language.

1 Like

Maybe an apostrophe will accomodate all genders :laughing:
"gentle'men"

We are, at least you and I, Austra'ans after all: land of abbreviations

1 Like

I think you misspelt Strayans :smiley:

2 Likes

Crikey's, that was fast!

Sorry for late response. Was busy trying suggestion and the myriad of variations, none of which worked. I got the below "string error" as a result of the above script.

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:runAction>", line 4, in runAction
TypeError: expected a str

	caused by org.python.core.PyException
Traceback (most recent call last):
  File "<function:runAction>", line 4, in runAction
TypeError: expected a str

I'm actually working toward a dropConfig with my SimpleMtr template. I had problems getting it to work so I backed up to where I am now. I'm finding that I am unable to get the correct onClick script syntax for the button of my template instance to work.

I think you're right about the value being passed instead of the path. This works but I can't figure out how to get it to interact via the view.params... path.

	startPath = ["[default]testSimpleMtr_2/Start_SCADA"]
	values = [True]
	system.tag.writeBlocking(startPath, values)

You just need to pass in a tag path to your View's param, not a value/binding to a tag

That would be great! I've tried but I don't know how.

Find your UDT instance, right click, copy path
Paste the path into the param value in the embedded View. In the view you'll then need to append onto this udt instance path the relative path to the tag within the UDT instance.

Eg
Expression

{self.view.custom.udtInstancePath} + '/tagName' 

Script

'{}/tagName'.format(self.view.custom.udtInstancePath) 
1 Like

Hey All,

Thank you so much for your input! It's so nice to have a place to learn!
Here's the version I finally got to work:

def runAction(self, event):
	providerPath = "[default]"
	tagPath = (self.view.params.SimpleMtr.pathToParentFolder)
	buttonPath = providerPath + tagPath + "/Start_SCADA"
	system.tag.writeBlocking(buttonPath, "true")

Still new to JSON and Python. Simple braces didn't occur to me until I stared at the previous post.
That said, I'd like to pass in the provider. Not all of my tags are in [default]. (Still sorting out the ramifications of where I put tags.)

Cheers, and thank you again!

This should be True, not a string

Not sure why you surround this in braces, but these aren't needed. Braces usually define a tuple (a type of immutable array), but only when there are 2 or more values, or you add a comma to the end of a single value. You don't have a comma at the end so I think it's just effectively returning the string value into the variable. In any case, it could be super confusing to someone looking at it, so I'd remove them.

Also, I'd recommend getting used to using the str.format function as it handles converting values passed to it into strings for you rather than having to explicitly do this yourself

Purely ignorance.

Had no idea. Thanks for the lesson!

Will do.