Dear Jonas,
Please find responses to both of your queries
Setting an Enumeration ValueFirstly, predefined (or standard) value for an enumeration attribute is initally set in the library using the Development Toolkit.
Once this has been set, all object instances with this attribute which are created in the Modelling Toolkit will have this value initally set. If one wishes to subsequently change the value of this enumeration attribute using an ADOscript, the appropriate command is SET_ATTR_VAL. This is the opposite of GET_ATTR_VAL which you referred to.
Syntax
CC "Core" SET_ATTR_VAL objid:id AttrSpec val:anyValue [ as-string ] .
AttrSpec : attrid:id | attrname:strValue .
#-->RESULT ecode:intValue
The following library, ADOscript and sample model:
Change Enumeration Value.ablChange enumeration value.adlChangeEnumerationValue.ascillustrate the use of this command.
In this model we have three classes: A (triangle), B (circle) and C (square). There is also an attribute of type Enumeration called "Colour" - which classes A and B have, but C does not. There is also an ADOscript called "ChangeEnumerationValue.asc". The purpose of this script is to find all objects in the model that possess the attribute "Colour" (in this case, instances of A and B ) and change its value to another value which the user selects from a list. One can see the method of actually setting the enumeration attribute value in line 46 of the code below.
1###################################################################################################
2# Script to change the value of an enumeration attribute for all objects which have this attribute
3###################################################################################################
4CC "Modeling" GET_ACT_MODEL
5SET n_modelId: (modelid)
6IF (n_modelId = -1) {
7 CC "AdoScript" ERRORBOX "Error: No model currently open"
8 EXIT
9}
10# First we retrieve all objects in the active model, and put the object ids in a list "l_objIds"
11CC "Core" GET_ALL_OBJS modelid: (n_modelId)
12SET l_objIds: (objids)
13
14# The attribute name whose value we wish to change is called "Colour" here, and is of type enumeration
15# For all objects with the attribute Colour, we wish to change the current value to some new value
16# We allow user interaction, to select what the new value should be
17SET n_valFound:1
18
19# Loop over all objects in the current model
20FOR s_objId in: (l_objIds) {
21 CC "Core" GET_CLASS_ID objid: (VAL s_objId)
22 SET n_classId: (classid)
23 CC "Core" GET_ATTR_ID classid: (n_classId) attrname: ("Colour")
24 SET n_attributeId: (attrid)
25 # Check whether the current object has an attribute called "Colour"
26 # If the current object does not have this attribute, GET_ATTR_ID returns "-1" and nothing is done,
27 # otherwise the following IF{..} block is executed
28 IF (attrid != -1) {
29 # This IF {..} block presents a selection tool to select the value desired, we only do this once (using the value of n_valFound)
30 IF (n_valFound=1) {
31 # Read the enumeration domain (i.e. the list of options for the enumeration attribute)
32 CC "Core" GET_FACET_ENUMERATIONDOMAIN attrid: (n_attributeId)
33 SET s_enumerationDomain: (val)
34 CC "Core" GET_ATTR_VAL objid: (VAL s_objId) attrname:"Colour"
35 SET s_currentSelection: (val)
36 # Present selection box, to set the desired value (which is then stored in s_enumVal)
37 CC "AdoScript" LISTBOX entries: (s_enumerationDomain) toksep:"@" title:"Select attribute value" oktext:"Apply" boxtext:"Attribute value:" selection: (s_currentSelection)
38 IF (endbutton = "ok") {
39 SET s_enumVal: (selection)
40 }
41
42 }
43 SET n_valFound: (n_valFound + 1)
44
45 # Now we set the selected value for the current object in our loop over all objects
46 CC "Core" SET_ATTR_VAL objid: (VAL s_objId) attrname:"Colour" val: (s_enumVal)
47
48 }
49
50}
One can test the functionality of this script by going to the Modelling Toolkit and loading the provided library. In the "Tools" menu (see image below) please go to the option "Change enumeration value". One is then presented with options to set for the enumeration value. On selection, all class objects possessing this attribute have their enumeration value changed to the chosen one.
In principle, the main point of this illustration is the use of the command to set the enumeration value, which is shown in the code above. We would suggest that if this does not answer your question, perhaps describe the specific scenario that you are having problems with and the requirements you need a solution for in more detail. We can then describe it for you more exactly.
Calling an ADOscript from Attribute of Type ProgramcallTo your second question regarding the use of a Programcall attribute to execute an ADOscript file; this is illustrated in the same library using class C mentioned above. This class has an attribute "ExecuteAdoScript" of type Programcall.
Firstly, this is defined in the library as shown in the image.
Note that in this case we have defined an ITEM "Change Enum Val" which is linked to the ADOscript. We have imported this script to the library and hence we have the path "db:\\ChangeEnumerationValue.asc". This can also be a path to a local file "C:\\....\\...\\ChangeEnumerationValue.asc", for example. Note the use of double backslash to separate directories.
In this case we have also selected a Predefined value while defining the attribute. This not selected automatically for you, which you may be used to from setting Enumeration attributes.
Now, in the Modelling Toolkit we can test this attribute by going to the notebook of an object of class C
We can test the execution of the script by clicking on the green arrow. Firstly note that before clicking on the arrow, in the dropdown box underneath "Executable" in the image, we need to have selected the item that we had defined earlier - "Change Enum Val" - or the script will not execute. This should be selected by default though if we have set the Predefined value in the library as above. Secondly, if we have made a mistake when defining the location of the script, we would now get an error indicating that the script cannot be loaded. If you are getting a specific error during your attempts, please let us know what error is displayed.