Page 1 of 1

[Server] How to create an object with default values in some variables

Posted: 10 Jan 2022, 11:05
by jramirez-jh
I'm working on a server that creates instances of objects dynamically like this:

Code: Select all

var objectTypeNodeId = new ExpandedNodeId(nId, DefaultNamespaceIndex).ToNodeId(Server.NamespaceUris);

var jhObjectId = new NodeId(jhBuilderModel.ObjectName, DefaultNamespaceIndex);

var settings = new CreateObjectSettings
{
	ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
	ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
	RequestedNodeId = jhObjectId,
	BrowseName = new QualifiedName("a name", DefaultNamespaceIndex),
	DisplayName = "a name",
	TypeDefinitionId = objectTypeNodeId
};

CreateObject(Server.DefaultRequestContext, settings);
Each object have N variables, I know the string identifier names of those objects (I'm receiving them also dynamically), my issue is that I need those objects to have default values in some of those variables but I can not find an easy way of doing it.

I've tried using the Write method of the new created object like this:

Code: Select all

var objectNode = CreateObject(Server.DefaultRequestContext, settings);
objectNode.Write(6525, "test value"); //NO LUCK, can't see any default values set
I'm also trying with the NodeData property of the CreateObjectSettings object but as its an object type I've no idea what are the accepted data structures? (there is no documentation about it). I've tried like this without any luck:

Code: Select all

var settings = new CreateObjectSettings
{
	ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
	ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
	RequestedNodeId = jhObjectId,
	BrowseName = new QualifiedName("a name", DefaultNamespaceIndex),
	DisplayName = "a name",
	TypeDefinitionId = objectTypeNodeId,
	NodeData = new Dictionary<string, string>
	{
		{"myobject.status_description", "god help me"}, //using the full identifier objectname.variablename
		{"status_description", "god help me"}, //using only the variable name
	}
};

var objectNode = CreateObject(Server.DefaultRequestContext, settings);
What is the right way of doing this?

Re: [Server] How to create an object with default values in some variables

Posted: 04 Feb 2022, 18:39
by Support Team
Hello,

You can use the Methode BaseNodeManager.SetVariableDefaultValue for your use case.

Please note: The BrowseName of the child must be correct, especially the NamespaceIndex of the BrowseName.

https://documentation.unified-automation.com/uasdknet/3.1.1/html/classUnifiedAutomation_1_1UaServer_1_1BaseNodeManager.html#af73589a0d9f0f896559aa5ab6b6a2bf1