SET_ATTR_VAL ​
SET_ATTR_VAL sets an attribute value of one instance.
Syntax ​
CC "Core" SET_ATTR_VAL objid:idValueAttrSpec val:anyValue [ as-string ] .
AttrSpec : attrid:idValue| attrname:strValue .
#-->RESULT ecode:intValue
Parameters ​
objid
(idValue) - AttrSpecval
(anyValue) -as-string
(modifier) -
Returns ​
ecode
(intValue) - Contains the error code or is 0 in case of success.
Details ​
The instance (library, class, connector class, model, modeling object, connector, record row or attribute profile) is specified by ID with objid. The attribute is specified by ID with attrid or by name with attrname. The new attribute value is passed with val.
When as-string is specified val must be a string which is conveted to the attribute type (e.g. INTEGER) internally. Otherwise the type of val must match the type of the attribute.
After changing a value of an attribute profile CC "Core" SAVE_LIBRARY has to be called to save that change into the database.
Note: When setting model attributes for a model that is not loaded, no error will be returned and the value of the model attribute will not be changed.
For certain types of attributes the value must follow a specific syntax:
The internal core-values for INTERREF type attributes follow the syntax:
InterRefValue : { ModelReference } | { ObjectReference } .
ModelReference : REF m:strValue mt:strValue .
ObjectReference : REF m:strValue mt:strValue c:strValue i:strValue .
The m
parameter specifies the name of a model, mt
the type of a model, c
the name of a (node) class and i
the name of an instance of the class.
The internal core-values for PROFREF type attributes follow the syntax:
REF i:strValue .
The i
parameter has the name of an instance of the allowed Attribute Profile class.
See Also ​
Examples ​
Example 1 ​
# get all selected objects
CC "Modeling" GET_SELECTED
IF (objids = "") {
CC "AdoScript" ERRORBOX "No object has been selected!"
EXIT
}
# from the list of selected objects, extract the first objectid
SET selected:(VAL token(objids,0," "))
# get the class of the selected object
CC "Core" GET_CLASS_ID objid:(selected)
# get the attribute "Name" of the class
CC "Core" GET_ATTR_ID classid:(classid) attrname:"Name"
IF (ecode) {
CC "AdoScript" ERRORBOX "The selected object does not contain an attribute called \"Name\"!"
EXIT
}
# set the name of the selected object
CC "Core" SET_ATTR_VAL objid:(selected) attrid:(attrid) val:"Seppl"
IF (ecode) {
CC "AdoScript" ERRORBOX "Could not set the attribute value!"
EXIT
}
Example 2 ​
# get the current model
CC "Core" GET_ACT_MODEL
IF (modelid = "") {
CC "AdoScript" ERRORBOX "Open a bp model first!"
EXIT
}
# get the modelattribute "Name" of the class
CC "Core" GET_ATTR_ID classid:bp-model attrname:"Beschreibung"
IF (ecode) {
CC "AdoScript" ERRORBOX "Model doe not contain an attribute called \"Beschreibung\"!"
EXIT
}
# set the model attribute
CC "Core" SET_ATTR_VAL
objid:(VAL modelid) attrid:(attrid) val:"Modeldescription here!"
IF (ecode) {
CC "AdoScript" ERRORBOX "Could not set the attribute value!"
EXIT
}
Example 3 ​
# get the class of the selected object
CC "Core" GET_CLASS_ID classname:"__LibraryMetaData__" bp-library
# get the attribute "Name" of the class
CC "Core" GET_ATTR_ID classid:(classid) attrname:"Grafiken erzeugen"
IF (ecode) {
CC "AdoScript" ERRORBOX "The selected object does not contain an attribute called \"Name\"!"
EXIT
}
# set the name of the selected object
CC "Core" SET_ATTR_VAL objid:(classid) attrid:(attrid) val:1
IF (ecode) {
CC "AdoScript" ERRORBOX "Could not set the attribute value!"
EXIT
}
Versions and Changes ​
Available since ADOxx 1.3