Access UDT parameter in script

How can I access UDT parameter in tag change event script?

I have used’[.]…\Parameters.ABC’), where ABC is the parameter name, successfully.

Obviously the relative path changes based on your folder structure in the UDT.

Interested to know if there is a better way, such as {ABC} in the references

1 Like

Hi Deon
I doesn’t in tag change event script in udt.

I don’t know if it’s possible. But we usually have a number of memory tags inside a folder of our UDT, that are just bound to those parameters.

Then those memory tags can be retrieved just like regular tags in the script.

Depends on the version. v8.0 makes parameters easier to access than v7.9.

v7.9 I’ve found it easier to do as Sanderd17 suggested.

v8.0 do as deon.korb suggests.

1 Like

@Paullys50 and @deon.korb

I have a similar question for the struct member reading of UDT in script with Ignition V8.0

The [default]VetctorTag/Vector is a OPC UDT tag, which can be read by function as shown in below snapshot that triggered by a button click operation.

This OPC tag has three members X, Y and Z. In fact, I want to just parse and print its member X.

It seems that’[default]VetctorTag/Vector.X’) doesn’t work. Could you help to give suggestion of it?

Thanks in advance’[default]VetctorTag/Vector/X’) should work.

I usually use the browsers, such as a Perspective binding, to figure out the syntax first.


Thanks for your info, the way works for the memory tags, but doesn’t work for OPC UDT tags.

The “[default]VetctorTag/Vector” is a OPC UDT tag that I dragged from a third part OPC UA server. Its whole data of X, Y, Z can be get by the with’[default]VetctorTag/Vector/X’) ,
but using’[default]VetctorTag/Vector/X’) doesn’t work for reading its struct member X.

What about this post?

Thanks for your info, I knew we could use JsonGet to retrieve Json format UDT of OPC tag.

Just want to know if it is possible to use to achieve this goal in script, because the jsonGet() function is only used in expression and it can’t be used in script.

If it provide the jsonGet() function in script, then it solve my issues.

What about this:

or this:

value ="New Tag3").value
value = system.util.jsonDecode(value)
print value
print value['X']
print value['Y']
print value['Z']

This post explain it…
EDIT: I just realized that @Kevin.Herron already explained this to you 11 days ago…?

Thanks for your comments.
I’ve try with your suggestion, it only works without the calling the eval() function as shown in the green box of below snapshot.
If we use eval() function or system.util.jsonDecode() function, both of them can’t parse the “Document” datatype, which is in fact printed as
<type ‘com.inductiveautomation.ignition.common.script.adapters.PyDocumentObjectAdaper’> as shown in below snapshot.

It seems that the Document type can’t be parsed by jsonDecode() function.
BTW, in fact, I’ve asked the question for document type UDT parsing as you mentioned, the jsonDecode() function also doesn’t work for that case, I use another workaround by using tags directly in script to solve my problem in that thread.

Well… then I’m ‘lost’…
In my case, when I drag from OPC browser the UDT (struct) tag from my S7-1500 OPC UA server, that tag is Unicode string type (JSON). You obviously get Document type.

I’m using v7.9.12. You’re using v8.
In v8 is deprecated (but it’ll still work, for backward compatibility). The new function is system.tag.readAsync.
Maybe was changed in v8…??? Maybe @Kevin.Herron can explain?

EDIT: I read the other post it again and it seems that, because tag system is completely changed in v8: is fine but its most direct replacement in 8.0 is system.tag.readBlocking.

@dawei.liu if you’re getting a document type just call str() on it first.

1 Like

Yes, my bad… :flushed:
Anyway, good call on str()… :+1:

@Kevin.Herron and @zxcslo

Really appreciate your help, the str() works well and solve my issues

I understood the question incorrectly, but it is very interesting to see how to read a struct up and then access it’s members.

How would you write back to one member of the struct then?

Just as Kevin’s suggestion in jsonSet workaround in script

I just tested that it’s possible to write back the struct value through script (Ignition version 8.0.4 Nightly)

With below script, the UDT member ‘param1’ of ‘OPC_tag’ can be updated and writen back to OPCUA server.

value1 =‘OPC_tag’).value
value1 = system.util.jsonDecode(str(value1))
value1[‘param1’] = ‘updated_param1_value’
value2 = system.util.jsonEncode(value1)
system.tag.write(‘OPC_tag’, value2)

Doesn’t that write the whole structure back? Less than optimal.

It does, and it’s required because his tag represents the whole structure. Reading the whole structure is the only way to get decent performance out of built-in OPC UA servers like the one on the S7-1500.

It would be ideal if the client could magically derive the NodeId for any given structure member and write to just that Node in the server, but it’s not even a given that a server exposes the members as individual Nodes.