Okay, I got some progress here, but am struggling to build the NodeBrowseInfo
and NodeDescription
that the findComponentsFor
method needs.
from com.inductiveautomation.ignition.common.tags.config.types import TagObjectType
from com.inductiveautomation.ignition.common.tags.browsing import NodeBrowseInfo, NodeDescription
from com.inductiveautomation.ignition.common.tags.paths import BasicTagPath
tag_path_str = "[default]_types_/MyFolder/MyUdtDefinition"
tag_path = BasicTagPath(tag_path_str)
node_desc = (NodeDescription.newBuilder()
.fullPath(tag_path)
.objectType(TagObjectType.UdtType)
.build())
node_browse_info = NodeBrowseInfo(tag_path, node_desc)
Both of these give empty tag descriptions when printed, and therefore dont return anything in the list. Any ideas?
>>> node_desc
TagDescription [name=null, dataType=null, currentValue=null, objectType=UdtType, subTypeId=null, attributes=null, hasChildren=false, displayFormat=null, tooltip=null]
>>> node_browse_info
TagDescription [name=null, dataType=null, currentValue=null, objectType=UdtType, subTypeId=null, attributes=null, hasChildren=false, displayFormat=null, tooltip=null]
I also tried with an instance's path and TagObjectType.UdtInstance
. Still no luck
For completeness, here is the whole script so far
from com.inductiveautomation.perspective.common.config.tagdrop import TagDropConfig
from com.inductiveautomation.ignition.common import TypeUtilities
from com.inductiveautomation.ignition.designer import IgnitionDesigner
from com.inductiveautomation.ignition.common.tags.browsing import NodeBrowseInfo, NodeDescription
from com.inductiveautomation.ignition.common.tags.paths import BasicTagPath
from com.inductiveautomation.ignition.common.tags.config.types import TagObjectType
from java.util import Optional
from org.python.core import PyString
from java.util.function import Function, Predicate
# Helper for Java Function
class PyFunction(Function):
def __init__(self, func):
self.func = func
def apply(self, arg):
return self.func(arg)
# Helper for Java Predicate
class PyPredicate(Predicate):
def __init__(self, func):
self.func = func
def test(self, arg):
return self.func(arg)
designerContext = IgnitionDesigner.getFrame().context
dropConfig = (Optional.ofNullable(designerContext.getProject())
.flatMap(PyFunction(lambda p: p.getSingletonResource(TagDropConfig.RESOURCE_TYPE)))
.flatMap(PyFunction(lambda r: r.getData()))
.filter(PyPredicate(lambda data: data.hasBytes()))
.map(PyFunction(lambda data: TypeUtilities.gsonToPy(TypeUtilities.pyToGson(PyString(data.getBytesAsReader().readString())))))
.map(PyFunction(lambda pyObj: TagDropConfig.fromJson(pyObj.toString())))
.orElse(TagDropConfig.createDefault()))
tag_path_str = "[default]_types_/MyFolder/MyUdtDefinition"
tag_path = BasicTagPath(tag_path_str)
node_desc = (NodeDescription.newBuilder()
.fullPath(tag_path)
.objectType(TagObjectType.UdtType)
.build())
node_browse_info = NodeBrowseInfo(tag_path, node_desc)
components = dropConfig.findComponentsFor(node_browse_info)
print components # returns []