Clone Node with Subnodes

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
DanG
Jr. Member
Jr. Member
Posts: 4
Joined: 24 Jul 2015, 06:57

Clone Node with Subnodes

Post by DanG »

Is there a way in the SDK to clone a Node including Subnodes (e.g. properties etc.)?

I need to create new ObjectTypes that inherit from an existing ObjectType at runtime. When calling "CreateObjectTypeNode" I can create a derived ObjectType but without the propoerties etc. defined for the SuperType.

Thanks,
Daniel

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: Clone Node with Subnodes

Post by Support Team »

Hello,

You do not need to get the properties, etc. from the super type since the subtype inherits the members of its super type. This is equivalent to subtyping in object orientated programming languages.

Best regards
Support Team

DanG
Jr. Member
Jr. Member
Posts: 4
Joined: 24 Jul 2015, 06:57

Re: Clone Node with Subnodes

Post by DanG »

Hello Support Team,

Thanks for your answer. When looking at different Object Types in UA Expert like BaseEventType and AuditEventType I seems that the inherited properties like EventId don't show up on the inherited type in the adddress space pane.
In my case the abstract super type defines a folder. The inherited type needs to provide type specific information in this inherited folder. I can see the folder on the SuperType but not on the inherited type. Is this folder browsable so that clients can retrieve the information and it is just not visible in UA Expert?

Thanks for your support
Daniel

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: Clone Node with Subnodes

Post by Support Team »

Hello Daniel,
so what you want to do is:
- Create an ObjectType with a folder.
- Create a subtype that adds a variable to that folder.

I have a small sample for you with MyObjectType:

Code: Select all

  MyObjectType
      |----Folder
      |----VariableA
And derrived from MyObjectType we have a MyObjectSubType:

Code: Select all

  MyObjectSubType
      |----Folder - Inherited from MyObjectType
          |----VariableB

Here's the code to create the ObjectTypes:

Code: Select all

    // create a subtype of BaseObjectType
    // MyObjectType
    //     |----Folder
    //     |----VariableA
    string name = "MyObjectType";
    NodeId myObjectTypeNodeId = new NodeId(baseId.Identifier.ToString() + "." + name, baseId.NamespaceIndex);
    CreateObjectTypeSettings objectTypeSettings = new CreateObjectTypeSettings()
    {
        ParentNodeId = ObjectTypeIds.BaseObjectType,
        ReferenceTypeId = ReferenceTypeIds.HasSubtype,
        RequestedNodeId = myObjectTypeNodeId,
        BrowseName = new QualifiedName(name, DefaultNamespaceIndex),
        DisplayName = name,
        Description = new LocalizedText("MyObjectType for testing")

    };
    ObjectTypeNode myObjectType = CreateObjectTypeNode(Server.DefaultRequestContext, objectTypeSettings);

    // Add Folder
    name = "Folder";
    NodeId myObjectTypeFolderNodeId = new NodeId(myObjectTypeNodeId.Identifier.ToString() + "." + name, myObjectTypeNodeId.NamespaceIndex);
    CreateObjectSettings objectSettings = new CreateObjectSettings()
    {
        ParentNodeId = myObjectTypeNodeId,
        ReferenceTypeId = ReferenceTypeIds.HasComponent,
        RequestedNodeId = myObjectTypeFolderNodeId,
        BrowseName = new QualifiedName(name, DefaultNamespaceIndex),
        DisplayName = name,
        Description = new LocalizedText("MyObjectType.Folder for testing"),
        ModellingRuleId = ObjectIds.ModellingRule_Mandatory,
        TypeDefinitionId = ObjectTypeIds.FolderType
    };
    CreateObject(Server.DefaultRequestContext, objectSettings);

    // Add VariableA
    name = "VariableA";
    NodeId myObjectTypeVariableANodeId = new NodeId(myObjectTypeNodeId.Identifier.ToString() + "." + name, myObjectTypeNodeId.NamespaceIndex);
    CreateVariableSettings variableSettings = new CreateVariableSettings()
    {
        ParentNodeId = myObjectTypeNodeId,
        ReferenceTypeId = ReferenceTypeIds.HasComponent,
        RequestedNodeId = myObjectTypeVariableANodeId,
        BrowseName = new QualifiedName(name, DefaultNamespaceIndex),
        DisplayName = name,
        Description = new LocalizedText("MyObjectType.VariableA for testing"),
        ModellingRuleId = ObjectIds.ModellingRule_Mandatory,
        TypeDefinitionId = VariableTypeIds.BaseDataVariableType
    };
    CreateVariable(Server.DefaultRequestContext, variableSettings);


    // create a subtype of MyObjectType
    // MyObjectSubType
    //     |----Folder - Inherited from MyObjectType
    //         |----VariableB
    name = "MyObjectSubType";
    NodeId myObjectSubTypeNodeId = new NodeId(baseId.Identifier.ToString() + "." + name, baseId.NamespaceIndex);
    objectTypeSettings = new CreateObjectTypeSettings()
    {
        ParentNodeId = myObjectTypeNodeId,
        ReferenceTypeId = ReferenceTypeIds.HasSubtype,
        RequestedNodeId = myObjectSubTypeNodeId,
        BrowseName = new QualifiedName(name, DefaultNamespaceIndex),
        DisplayName = name,
        Description = new LocalizedText("MyObjectSubType inherited from MyObjectType for testing")

    };
    ObjectTypeNode myObjectSubType = CreateObjectTypeNode(Server.DefaultRequestContext, objectTypeSettings);

    // Add Folder
    name = "Folder";
    NodeId myObjectSubTypeFolderNodeId = new NodeId(myObjectSubTypeNodeId.Identifier.ToString() + "." + name, myObjectTypeNodeId.NamespaceIndex);
    objectSettings = new CreateObjectSettings()
    {
        ParentNodeId = myObjectSubTypeNodeId,
        ReferenceTypeId = ReferenceTypeIds.HasComponent,
        RequestedNodeId = myObjectSubTypeFolderNodeId,
        BrowseName = new QualifiedName(name, DefaultNamespaceIndex),
        DisplayName = name,
        Description = new LocalizedText("MyObjectSubType.Folder for testing"),
        ModellingRuleId = ObjectIds.ModellingRule_Mandatory,
        TypeDefinitionId = ObjectTypeIds.FolderType
    };
    CreateObject(Server.DefaultRequestContext, objectSettings);

    // Add VariableB
    name = "VariableB";
    NodeId myObjectTypeVariableBNodeId = new NodeId(myObjectTypeNodeId.Identifier.ToString() + "." + name, myObjectTypeNodeId.NamespaceIndex);
    variableSettings = new CreateVariableSettings()
    {
        ParentNodeId = myObjectSubTypeFolderNodeId,
        ReferenceTypeId = ReferenceTypeIds.HasComponent,
        RequestedNodeId = myObjectTypeVariableBNodeId,
        BrowseName = new QualifiedName(name, DefaultNamespaceIndex),
        DisplayName = name,
        Description = new LocalizedText("MyObjectSubType.VariableB for testing"),
        ModellingRuleId = ObjectIds.ModellingRule_Mandatory,
        TypeDefinitionId = VariableTypeIds.BaseDataVariableType
    };
    CreateVariable(Server.DefaultRequestContext, variableSettings);

Best Regards,
Unified Automation Support Team

Post Reply