Skip to content

Arguments not working when adding method to object type #1564

Open

Description

@cdh4u

I am adding a method to an object type (myType.add_method()). In the clients (I am using the Prosys Browser and UaExpert clients) I can see the object type with the method and the input/output arguments.

When I create an object instance, in the clients I can see the object instance with the method. However, the input/output arguments are missing, and I am not able to call the method with input arguments. The issue applies to both clients.

`@uamethod
def method_handler(parent, input):
print("In handler")
return True

inargs = []
outargs = []

inarg = ua.Argument()
inarg.Name = "TestMethod"
inarg.DataType = ua.NodeId(ua.ObjectIds.String)
inarg.ValueRank = -1
inarg.ArrayDimensions = []
inarg.Description = ua.LocalizedText("Test method input")
inargs.append(inarg)
outarg = ua.Argument()
outarg.Name = "Result"
outarg.DataType = ua.NodeId(ua.ObjectIds.Boolean)
outarg.ValueRank = -1
outarg.ArrayDimensions = []
outarg.Description = ua.LocalizedText("Test method result")
outargs.append(outarg)
myType.add_method(
2,
"TestMethod",
method_handler,
inargs,
outargs,
).set_modelling_rule(True)

myInstance = objects.add_object(2, "myObjectInstance", myType.nodeid)`

However, when I add a method to an object instance (myInstance.add_method()), everything works. I can see the input/output arguments.

`@uamethod
def method_handler(parent, input):
print("In handler")
return True

myInstance = objects.add_object(2, "myObjectInstance", myType.nodeid)

inargs = []
outargs = []

inarg = ua.Argument()
inarg.Name = "TestMethod"
inarg.DataType = ua.NodeId(ua.ObjectIds.String)
inarg.ValueRank = -1
inarg.ArrayDimensions = []
inarg.Description = ua.LocalizedText("Test method input")
inargs.append(inarg)
outarg = ua.Argument()
outarg.Name = "Result"
outarg.DataType = ua.NodeId(ua.ObjectIds.Boolean)
outarg.ValueRank = -1
outarg.ArrayDimensions = []
outarg.Description = ua.LocalizedText("Test method result")
outargs.append(outarg)
myInstance.add_method(
2,
"TestMethod",
method_handler,
inargs,
outargs,
).set_modelling_rule(True)`

Any ideas on what I am doing wrong? In the examples the methods are added to object instances.

Activity

  1. cdh4u commented on Aug 2, 2025

    @cdh4u
    Author

    I think I found the issue and solution.

    When you add a method to an object type, you need to explicitly set the modelling rule of the Input/OutputArguments properties to Mandatory (or True). Otherwise they will be added to object instances (eventhough the method node will).

    Not sure if that is on purpose, or whether it is a bug in the library, because one would think that the modelling rule would be set automatically. I do realize this repo is no longer maintained, but if it is a bug it may be worth checking whether it has been fixed in the async repo.

    method_node = myType.get_child(["2:TestMethod"]) met_props = method_node.get_properties() for prop in met_props: prop.set_modelling_rule(True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions