API to create objects

Introduction

The APIs described below create objects in the Q Studio project and return the corresponding C# objects. They are supplied by the InformationModel class, displayed by the QPlatform.HMIProject module.

In the following table, the APIs to be used for the most common purposes are given:

Purpose

API

Create a BaseObject basic project object.

InformationModel.MakeObject(browseName)

Create the desired type of project object.

InformationModel.MakeObject<T>(browseName)

Create a BaseObject basic project object type.

InformationModel.MakeObjectType(browseName)

Create the desired type of project object type.

InformationModel.MakeObjectType<T>(browseName)

InformationModel.MakeObject(browseName)

Creates a project object of the BaseObject type and returns a corresponding IUAObject C# object.

static IUAObject MakeObject(QualifiedName browseName);

Arguments

browseName QualifiedName

BrowseName of the new object.

Returns

IUAObject

C# object corresponding to the project object created.

Example

Below is an example in which the API creates a Motor object and returns the corresponding C# object, which is assigned to the motor variable. The Motor object is then added to the parent node of the NetLogic.

var motor = InformationModel.MakeObject("Motor");
Owner.Add(motor);

InformationModel.MakeObjectType(browseName)

Creates an object type derived from BaseObject and returns a corresponding IUAObjectType C# object.

static IUAObjectType MakeObjectType(QualifiedName browseName);

Arguments

browseName QualifiedName

BrowseName of the new object type.

Returns

IUAObjectType

C# object corresponding to the project object created.

Example

Below is an example in which the API creates a Motor (type) object and returns the corresponding C# object, which is assigned to the motor variable. The Motor (type) object is then added to the parent node of the NetLogic.

var motor = InformationModel.MakeObjectType("Motor");
Owner.Add(motor);

InformationModel.MakeObject(browseName, objectTypeId)

Creates a project object of the type indicated in the second argument and returns a corresponding IUAObject C# object type.

static IUAObject MakeObject(QualifiedName browseName, NodeId objectTypeId);

Arguments

browseName QualifiedName

BrowseName of the new object.

objectTypeId NodeId

NodeID of the type from which the new object is derived.

Returns

IUAObject

C# object corresponding to the project object created.

Example

Below is an example in which the API creates a NewMotor object derived from Motor (type), searched with the Find method and then specified using NodeID:

var motorType = Project.Current.Find("Motor");
var mymotor = InformationModel.MakeObject("NewMotor", motorType.NodeId);

InformationModel.MakeObjectType(browseName, superTypeId)

Creates a project object type derived from the type indicated in the second argument (supertype) and returns a corresponding IUAObjectType C# object.

static IUAObjectType MakeObjectType(QualifiedName browseName, NodeId superTypeId);

Arguments

browseName QualifiedName

BrowseName of the new object.

superTypeId NodeId

NodeID of the type from which the new object is derived.

Returns

IUAObject

C# object corresponding to the project object created.

Example

Below is an example in which the API creates a SpecialMotor (type) object derived from Motor (type), searched with the Find method and then specified using NodeID:

var supertype = Project.Current.Find("Motor");
Owner.Add(InformationModel.MakeObjectType("SpecialMotor", supertype.NodeId));

InformationModel.MakeObject<T>(browseName)

Creates a project object of the specified <T> type and returns a corresponding C# object of the same type.

Note

at design time, the API functions only if the specified type is a native type, i.e., contained in the Q Platform modules.

static T MakeObject<T>(QualifiedName browseName);

Arguments

T

IUAObject C# class, corresponding to the C# object class to return and to the object type from which the new object is derived.

browseName QualifiedName

BrowseName of the new object.

Returns

T

C# object corresponding to the project object created.

Example

Below is an example in which the API creates a NewMotor object of the Motor type:

var myObj = InformationModel.MakeObject<Motor>("NewMotor");
Owner.Add(myObj);

InformationModel.MakeObjectType<T>(browseName)

Creates a project object of the specified <T> type and returns a corresponding C# object of the same type.

Note

at design time, the API functions only if the specified type is a native type, i.e., contained in the Q Platform modules.

static T MakeObjectType<T>(QualifiedName browseName)

Arguments

T

IUAObjectType C# class, corresponding to the C# object class to return and to the object type from which the new object is derived.

browseName QualifiedName

BrowseName of the new object.

Returns

T

C# object corresponding to the project object created.

Example

Below is an example in which the API creates a NewLabelType object of the Label type and returns a LabelType C# object:

var myObj= InformationModel.MakeObjectType.<LabelType>("NewLabelType");
Owner.Add(myObj);

InformationModel.MakeObject<T>(browseName, objectTypeId)

Creates a project object of the type indicated in the second argument and returns a C# object of the corresponding specified <T> type.

Note

at design time, the API functions only if the specified type is a native type, i.e., contained in the Q Platform modules.

static T MakeObject<T>(QualifiedName browseName, NodeId objectTypeId);

Arguments

T

IUAObject C# class, corresponding to the class of the C# object to return,

browseName QualifiedName

BrowseName of the new object.

objectTypeId NodeId

NodeID of the type from which the new object is derived.

Returns

T

C# object corresponding to the project object created.

Example

Below is an example in which the API creates a NewMotor object of the Motor type, searched with the Find method and then specified using NodeID, and returns a Motor C# object:

var motortype = Project.Current.Find("Motor");
var myObj = InformationModel.MakeObject<Motor>("NewMotor", motortype.NodeId);
Owner.Add(myObj);

InformationModel.MakeObjectType<T>(browseName, superTypeId)

Creates a project object type derived from the type indicated in the second argument (supertype) and returns a C# object of the corresponding specified <T> type.

Note

at design time, the API functions only if the specified type is a native type, i.e., contained in the Q Platform modules.

static T MakeObjectType<T>(QualifiedName browseName, NodeId superTypeId);

Arguments

T

IUAObjectType C# class, corresponding to the class of the C# object to return.

browseName QualifiedName

BrowseName of the new object.

superTypeId NodeId

NodeID of the type from which the new object is derived.

Returns

T

C# object corresponding to the project object created.

Example

Below is an example in which the API creates a NewMotorType object of the Motor type, searched with the Find method and then specified using NodeID, and returns a MotorType C# object:

var supertype = Project.Current.Find("Motor");
var myObj = InformationModel.MakeObjectType<MotorType>("NewMotorType", supertype.NodeId);
Owner.Add(myObj);

See also

Related concepts

Objects

Related procedures

Objects and Object Types

Use object and variable templates