UDTs - Bind Parameters to Properties Using Scripting

I’m trying to use an Ignition script to change the binding of a property using scripting.

I’m using this script:

a = system.tag.getConfiguration('[default]FV_102/FullStall/Ack')
x = (a[0]['opcItemPath'])
print('opcItemPath: ', x)
print('Type: ', type(x))

The result is this:

('opcItemPath: ', {bindType=parameter, binding={OPC_Item_Path}.{TagName}})
('Type: ', <type 'com.inductiveautomation.ignition.common.config.BoundValue'>)

My issue is that I do not know how to create / modify the BoundValue datatype. Setting the opcItemPath equal a string of the desired path does not work. I have to manually go back into the UDT and apply the change.

The information that I found on the BoundValue is this: http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.0-beta/com/inductiveautomation/ignition/common/config/BoundValue.html

The system.tag.configure document doesn’t have an example on using parameters (it does for setting parameters). https://docs.inductiveautomation.com/display/DOC80/system.tag.configure

Is it possible to bind a parameter to a property via scripting?

There’s not any way to construct bindings in scripts, for any part of Ignition. You would have to instantiate an expression parser with a carefully constructed execution context, and none of the necessary pieces are exposed, not even in the SDK. It is theoretically possible, though. But totally unsupported.

The closest you can get would be to programmatically construct a file in tag export format and use system.tag.importTags() to pull it in.

Is this still the case ? I want to overwride an opcItemPath of a child in a UDT instance that uses parameters bindings.

I know its an old thread, but if you were still wondering, I found that (in 8.3) if you import the BoundValue type you can create a new BoundValue and assign it to a tag's opcItemPath property.

eg. if you want to bind a parameter named opcRootPath:

import com.inductiveautomation.ignition.common.config.BoundValue as BoundValue

rootpath = "[default]tagpath"
tag = system.tag.getConfiguration(path+"/member", False)[0]
bv = BoundValue('parameter', '{opcRootPath}/RestOfThePath')
tag['opcItemPath'] = bv
system.tag.configure(path, conv, 'o')

I just looked at this (and Ignition) for the first time in years. It turns out all that was needed was a .getValue() on the parameter. No need for messing with BoundValue.

Here's a script that dynamically goes through a specified path and automatically adds the nested name to the OPC_Item_Path custom parameter.
Going off the initial example, the OPC_Item_Path variable was FV_102.
Now the OPC_Item_Path for FV_102/FullStall will be FV_102.FullStall

# goes through all tags in project and replaces child UDT parameters with the parent values
# if they have the same parameter names
def propogateParamsChildren(pth, layer=0, dParams={}):
    browsedPath = system.tag.browseTags(pth)
    for itm in browsedPath:
        if itm.isFolder():
            propogateParamsChildren(itm)
            continue

        tagConfig = system.tag.getConfiguration(itm)
        if tagConfig[0]['tagType'].toString() == 'UdtInstance':
            if layer == 0:
                dParams = tagConfig[0]['parameters']
                propogateParamsChildren(itm, layer+1, dParams)
            else:

                for k in dParams.keys():
                    if tagConfig[0]['parameters'].get(k, None) is not None:
                        if k == 'OPC_Item_Path':
                            tagConfig[0]['parameters'][k] = dParams[k].getValue() + '.' + tagConfig[0]['name']
                        else:
                            tagConfig[0]['parameters'][k] = dParams[k]
                system.tag.configure(pth, tagConfig, 'o')
                
                propogateParamsChildren(itm, layer+1, dParams)