Properties
Setting the Most Common Properties of an System Object
Properties for an object can be set upon creation of an object or after creation by using the
getobject function and accessing property names through "." syntax and committing
the changes using the commit method. Below is a code example that uses the getobject
function to get an object (if the object does not exist, it is created using the createobject function),
then sets its most common properties and references using the
refs
field.
local obj = syslib.getobject("/System/localhost/testObj")
if obj == nil then -- if the object doesn't exist, create it
obj = syslib.createobject("/System/localhost", "MODEL_CLASS_HOLDERITEM")
obj.ObjectName = "testObj"
obj.ObjectDescription = "Object used for debugging"
obj.OpcEngUnit = "m/s"
obj.DecimalPlaces = 2
obj.Limits.OpcRangeLow = 0
obj.Limits.OpcRangeHigh = 200
obj.ArchiveOptions.StorageStrategy = "STORE_RAW_HISTORY"
obj.Location.Latitude = 50.8312
obj.Location.Longitude = 6.9063
obj.refs = {
{name="Ref1", path="/System/localhost/holder1"},
{name="Ref2", path="/System/localhost/holder2"}
}
obj:commit()
end
-- make sure to set a numeric value if historization is desired
local value = "10"
syslib.setvalue(obj:path(), tonumber(value), 0, syslib.currenttime())
Accessing Properties
The properties of AspenTech Inmation objects can be accessed using the notation: object.property as demonstrated in previous examples For example, an object is created and the object name and properties can be set in the following way:
obj = syslib.createobject("/System/localhost", "MODEL_CLASS_HOLDERITEM")
obj.ObjectName = "testObj"
obj.ObjectDescription = "Object used for debugging"
obj:commit()
Properties contained in property compounds can be accessed either through the full property path:
local lat = syslib.getvalue("/System/localhost/testObj.location.latitude")
local archiveprop = syslib.getvalue("/System/localhost/testObj.ArchiveOptions.StorageStrategy")
OR the property can be accessed without needing to know the property compound it is nested within. For example the following code will access the "Latitude" and "ArchiveOptions" properties the same as in the above example:
local lat = syslib.getvalue("/System/localhost/testObj.latitude")
local archiveprop = syslib.getvalue("/System/localhost/testObj.StorageStrategy")
| To access an object’s properties in the "flat" way as shown above, the full path of the AspenTech Inmation object itself must still be correct. |