« Back to University of Duisburg-Essen

Setting enumerations in ADO script

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Setting enumerations in ADO script
Answer
2/7/15 2:17 PM
Hello,
unfortunately i didn't find any information on how i can set specific values for enumerations with ado script. Maybe you can help me in that regard. Besides that, is it possible to add buttons in the modeling environment, which are executing ADO script code when pressing it ?

Thank you very much,
Jonas Kaiser

RE: Setting enumerations in ADO script
Answer
2/9/15 12:06 PM as a reply to Jonas Kaiser.
Dear Jonas Kaiser,

Thank you for your questions. In order to solve your first question, how to define enumeration values dynamically, please have a look at the following thread.
http://www.adoxx.org/live/faq/-/message_boards/message/209425
There you can find a detailed documentation of the solution including a library with an implementation example.

To solve your second issue there are two ways to represent buttons in the modeling toolkit.
     1. Push-button In the Notebook
     2. Define a HOTSPOT in the GraphRep

Ad 1)
  ·Create an attribute of type PROGRAMCALL.
  ·Configure the attribute AttrRep
1   NOTEBOOK
2   CHAPTER "Description"
3   ATTR "Name"
4   ATTR "%ATTRNAME%" push-button no-param
The additional input ‘push-button no-param’ has the effect that you will have a push button in the notebook which triggers the ADOSCRIPT implementation of the PROGRAMCALL attribute.


Ad 2)
  ·Create an attribute of type PROGRAMCALL.
  ·Configure the attribute AttrRep
1    NOTEBOOK
2    CHAPTER "Description"
3    ATTR "Name"
4    ATTR "%ATTRNAME%"
  ·Configure the attribute GraphRep by defining a HOTSPOT

A HOTSPOT element links the rectangular region specified by x, y, w and h to the object attribute specified by the main parameter attrName. The element itself is invisible in the graphical representation.
Moving the mouse over a HOTSPOT region of an INTERREF or a PROGRAMCALL attribute lets the mouse cursor become a pointing hand. Additionally the corresponding attribute value or any specified text is shown in a balloon window.
Clicking on a HOTSPOT region has the same effect as clicking on the text of an ATTR element for the same attribute.

HOTSPOT
attrName [ text:strExpr ]
[ x:xposExpr ] [ y:yposExpr ]
[ w:widthExpr ] [ h:heightExpr ]
 
Example: Hotspot for a PROGRAMCALL attribute
 1GRAPHREP
 2PEN w:0.05cm
 3FILL color:dodgerblue
 4RECTANGLE x:-1.4cm y:-.7cm w:2.8cm h:1.4cm
 5AVAL ed:" External Documentation " # External documentation
 6IF (LEN ed)
 7  FILL color:$cafe69  # hidden message? ;-)
 8  POLYGON 7 x1:1.2cm y1:-0.4cm x2:1.6cm y2:-0.4cm x3:1.6cm y3:-0.5cm
 9            x4:2.0cm y4:-0.3cm x5:1.6cm y5:-0.1cm x6:1.6cm y6:-0.2cm
10            x7:1.2cm y7:-0.2cm
11  HOTSPOT "External Documentation" x:1.2cm y:-0.5cm w:0.8cm h:0.4cm
12          text: ("Execute: " + copy (ed, 0, search (ed, "@", 0)))
13ENDIF
      

Result:

RE: Setting enumerations in ADO script
Answer
2/18/15 12:17 PM as a reply to Mehmet Albayrak.
First of all, thank you for taking the time. I have to apologize if I formulated my question vague. Instead of changing enumerations dynamically, we need to set an enumeration on a pre defined value using ado script. Basically the same as reading enumerations just vice versa.

Besides that, how is it possible to bind an .ASC file with the EXECUTE FILE command in an attribute of type PROGRAMCALL? I've done that but it does not seem to work. Is there something to consider?
Thank you very much and best regards,

Jonas Kaiser

RE: Setting enumerations in ADO script
Answer
2/23/15 7:24 AM as a reply to Jonas Kaiser.
Dear Jonas,

Please find responses to both of your queries

Setting an Enumeration Value

Firstly, 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.abl
Change enumeration value.adl
ChangeEnumerationValue.asc

illustrate 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 Programcall

To 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.

RE: Setting enumerations in ADO script
Answer
2/24/15 5:03 PM as a reply to David Burke.
Thank you David, that was exactly what we were looking for.
Since our project comes to an end, I want to express my gratitude for the great support we received during it.

Best regards,
Jonas Kaiser