2 Instantiate a new node and its child nodes from a node type. 12 def instantiate(parent, node_type, nodeid=None, bname=None, idx=0):
14 instantiate a node type under a parent node. 15 nodeid and browse name of new node can be specified, or just namespace index 16 If they exists children of the node type, such as components, variables and 17 properties are also instantiated 20 rdesc.TypeDefinition = node_type.nodeid
25 bname = rdesc.BrowseName
26 elif isinstance(bname, str):
27 bname = ua.QualifiedName.from_string(bname)
30 return [Node(parent.server, nid)
for nid
in nodeids]
35 instantiate a node type under parent 37 node_type = Node(server, rdesc.NodeId)
38 refs = node_type.get_referenced_nodes(refs=ua.ObjectIds.HasModellingRule)
41 if len(refs) == 1
and refs[0].nodeid ==
ua.NodeId(ua.ObjectIds.ModellingRule_Optional):
45 addnode.RequestedNewNodeId = nodeid
46 addnode.BrowseName = bname
47 addnode.ParentNodeId = parentid
48 addnode.ReferenceTypeId = rdesc.ReferenceTypeId
49 addnode.TypeDefinition = rdesc.TypeDefinition
51 if rdesc.NodeClass
in (ua.NodeClass.Object, ua.NodeClass.ObjectType):
52 addnode.NodeClass = ua.NodeClass.Object
55 elif rdesc.NodeClass
in (ua.NodeClass.Variable, ua.NodeClass.VariableType):
56 addnode.NodeClass = ua.NodeClass.Variable
58 elif rdesc.NodeClass
in (ua.NodeClass.Method,):
59 addnode.NodeClass = ua.NodeClass.Method
62 print(
"Instantiate: Node class not supported: ", rdesc.NodeClass)
65 res = server.add_nodes([addnode])[0]
66 added_nodes = [res.AddedNodeId]
69 parents = ua_utils.get_node_supertypes(node_type, includeitself=
True)
70 node = Node(server, res.AddedNodeId)
71 for parent
in parents:
72 descs = parent.get_children_descriptions(includesubtypes=
False)
75 if not ua_utils.is_child_present(node, c_rdesc.BrowseName):
77 if res.AddedNodeId.NodeIdType
is ua.NodeIdType.String:
78 inst_nodeid = res.AddedNodeId.Identifier +
"." + c_rdesc.BrowseName.Name
79 nodeids =
_instantiate_node(server, res.AddedNodeId, c_rdesc, nodeid=
ua.NodeId(identifier=inst_nodeid, namespaceidx=res.AddedNodeId.NamespaceIndex), bname=c_rdesc.BrowseName)
81 nodeids =
_instantiate_node(server, res.AddedNodeId, c_rdesc, nodeid=
ua.NodeId(namespaceidx=res.AddedNodeId.NamespaceIndex), bname=c_rdesc.BrowseName)
82 added_nodes.extend(nodeids)
def _rdesc_from_node(parent, node)
def instantiate(parent, node_type, nodeid=None, bname=None, idx=0)
def _instantiate_node(server, parentid, rdesc, nodeid, bname, recursive=True)
def _read_and_copy_attrs(node_type, struct, addnode)