Setting enumerations in ADO scriptSetting enumerations in ADO scriptRE: Setting enumerations in ADO scriptJonas Kaiserhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=2338612015-02-24T17:03:01Z2015-02-24T17:02:16ZThank you David, that was exactly what we were looking for.<br />Since our project comes to an end, I want to express my gratitude for the great support we received during it.<br /><br />Best regards,<br />Jonas KaiserJonas Kaiser2015-02-24T17:02:16ZRE: Setting enumerations in ADO scriptDavid Burkehttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=2307162015-02-23T07:24:41Z2015-02-19T13:09:29ZDear Jonas, <br /><br />Please find responses to both of your queries<br /><br /><strong>Setting an Enumeration Value</strong><br /><br />Firstly, predefined (or standard) value for an enumeration attribute is initally set in the library using the Development Toolkit. <br /><br /><img src="https://www.adoxx.org/svn/all-repo/9_ADOxx_FAQ_Documentation_Libraries/Set%20enumeration%20value/BIN/Predefined%20value%20in%20%20library.JPG" /><br /><br />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.<br /><br />Syntax<br /><br /> CC "Core" SET_ATTR_VAL objid:id AttrSpec val:anyValue [ as-string ] .<br /><br /> AttrSpec : attrid:id | attrname:strValue .<br /><br /> #-->RESULT ecode:intValue<br /><br /><br />The following library, ADOscript and sample model:<br /><br /><a href="https://www.adoxx.org/svn/all-repo/9_ADOxx_FAQ_Documentation_Libraries/Set%20enumeration%20value/BIN/Change%20Enumeration%20Value.abl">Change Enumeration Value.abl</a><br /><a href="https://www.adoxx.org/svn/all-repo/9_ADOxx_FAQ_Documentation_Libraries/Set%20enumeration%20value/DOC/Change%20enumeration%20value.adl">Change enumeration value.adl</a><br /><a href="https://www.adoxx.org/svn/all-repo/9_ADOxx_FAQ_Documentation_Libraries/Set%20enumeration%20value/SRC/ChangeEnumerationValue.asc">ChangeEnumerationValue.asc</a><br /><br />illustrate the use of this command. <br /><br />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. <br /><br /><div class="code"><span class="code-lines"> 1</span>###################################################################################################<br /><span class="code-lines"> 2</span># Script to change the value of an enumeration attribute for all objects which have this attribute<br /><span class="code-lines"> 3</span>###################################################################################################<br /><span class="code-lines"> 4</span>CC "Modeling" GET_ACT_MODEL<br /><span class="code-lines"> 5</span>SET n_modelId: (modelid)<br /><span class="code-lines"> 6</span>IF (n_modelId = -1) {<br /><span class="code-lines"> 7</span> CC "AdoScript" ERRORBOX "Error: No model currently open"<br /><span class="code-lines"> 8</span> EXIT<br /><span class="code-lines"> 9</span>}<br /><span class="code-lines">10</span># First we retrieve all objects in the active model, and put the object ids in a list "l_objIds"<br /><span class="code-lines">11</span>CC "Core" GET_ALL_OBJS modelid: (n_modelId)<br /><span class="code-lines">12</span>SET l_objIds: (objids)<br /><span class="code-lines">13</span><br /><span class="code-lines">14</span># The attribute name whose value we wish to change is called "Colour" here, and is of type enumeration<br /><span class="code-lines">15</span># For all objects with the attribute Colour, we wish to change the current value to some new value<br /><span class="code-lines">16</span># We allow user interaction, to select what the new value should be<br /><span class="code-lines">17</span>SET n_valFound:1<br /><span class="code-lines">18</span><br /><span class="code-lines">19</span># Loop over all objects in the current model<br /><span class="code-lines">20</span>FOR s_objId in: (l_objIds) {<br /><span class="code-lines">21</span> CC "Core" GET_CLASS_ID objid: (VAL s_objId)<br /><span class="code-lines">22</span> SET n_classId: (classid)<br /><span class="code-lines">23</span> CC "Core" GET_ATTR_ID classid: (n_classId) attrname: ("Colour")<br /><span class="code-lines">24</span> SET n_attributeId: (attrid)<br /><span class="code-lines">25</span> # Check whether the current object has an attribute called "Colour"<br /><span class="code-lines">26</span> # If the current object does not have this attribute, GET_ATTR_ID returns "-1" and nothing is done,<br /><span class="code-lines">27</span> # otherwise the following IF{..} block is executed<br /><span class="code-lines">28</span> IF (attrid != -1) {<br /><span class="code-lines">29</span> # This IF {..} block presents a selection tool to select the value desired, we only do this once (using the value of n_valFound)<br /><span class="code-lines">30</span> IF (n_valFound=1) {<br /><span class="code-lines">31</span> # Read the enumeration domain (i.e. the list of options for the enumeration attribute)<br /><span class="code-lines">32</span> CC "Core" GET_FACET_ENUMERATIONDOMAIN attrid: (n_attributeId)<br /><span class="code-lines">33</span> SET s_enumerationDomain: (val)<br /><span class="code-lines">34</span> CC "Core" GET_ATTR_VAL objid: (VAL s_objId) attrname:"Colour"<br /><span class="code-lines">35</span> SET s_currentSelection: (val)<br /><span class="code-lines">36</span> # Present selection box, to set the desired value (which is then stored in s_enumVal)<br /><span class="code-lines">37</span> CC "AdoScript" LISTBOX entries: (s_enumerationDomain) toksep:"@" title:"Select attribute value" oktext:"Apply" boxtext:"Attribute value:" selection: (s_currentSelection)<br /><span class="code-lines">38</span> IF (endbutton = "ok") {<br /><span class="code-lines">39</span> SET s_enumVal: (selection)<br /><span class="code-lines">40</span> }<br /><span class="code-lines">41</span><br /><span class="code-lines">42</span> } <br /><span class="code-lines">43</span> SET n_valFound: (n_valFound + 1)<br /><span class="code-lines">44</span> <br /><span class="code-lines">45</span> # Now we set the selected value for the current object in our loop over all objects<br /><span class="code-lines">46</span> CC "Core" SET_ATTR_VAL objid: (VAL s_objId) attrname:"Colour" val: (s_enumVal)<br /><span class="code-lines">47</span> <br /><span class="code-lines">48</span> }<br /><span class="code-lines">49</span><br /><span class="code-lines">50</span>}<br /></div><br /><br />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.<br /><br /><img src="https://www.adoxx.org/svn/all-repo/9_ADOxx_FAQ_Documentation_Libraries/Set%20enumeration%20value/BIN/Change%20enumeration%20value%20menu%20option.JPG" /><br /><br />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. <br /><strong>Calling an ADOscript from Attribute of Type Programcall</strong><br /><br />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. <br /><br />Firstly, this is defined in the library as shown in the image. <br /><br /><img src="https://www.adoxx.org/svn/all-repo/9_ADOxx_FAQ_Documentation_Libraries/Set%20enumeration%20value/BIN/Programcall%20Facet.JPG" /><br /><br />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. <br /><br />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.<br /><br /><img src="https://www.adoxx.org/svn/all-repo/9_ADOxx_FAQ_Documentation_Libraries/Set%20enumeration%20value/BIN/Programcall%20Predefined%20value.JPG" /><br /><br />Now, in the Modelling Toolkit we can test this attribute by going to the notebook of an object of class C<br /><br /><img src="https://www.adoxx.org/svn/all-repo/9_ADOxx_FAQ_Documentation_Libraries/Set%20enumeration%20value/BIN/Notebook%20Execute.JPG" /><br />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.David Burke2015-02-19T13:09:29ZRE: Setting enumerations in ADO scriptJonas Kaiserhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=2270292015-02-18T12:17:25Z2015-02-09T16:13:31ZFirst 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.<br /><br />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?<br />Thank you very much and best regards,<br /><br />Jonas KaiserJonas Kaiser2015-02-09T16:13:31ZRE: Setting enumerations in ADO scriptMehmet Albayrakhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=2269272015-02-09T12:06:25Z2015-02-09T12:06:25ZDear Jonas Kaiser,<br /><br />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.<br /><a href="http://www.adoxx.org/live/faq/-/message_boards/message/209425">http://www.adoxx.org/live/faq/-/message_boards/message/209425</a><br />There you can find a detailed documentation of the solution including a library with an implementation example.<br /><br />To solve your second issue there are two ways to represent buttons in the modeling toolkit.<br /> 1. Push-button In the Notebook<br /> 2. Define a HOTSPOT in the GraphRep<br /><br />Ad 1)<br /> ·Create an attribute of type PROGRAMCALL.<br /> ·Configure the attribute AttrRep<div class="code"><span class="code-lines">1</span> NOTEBOOK<br /><span class="code-lines">2</span> CHAPTER "Description"<br /><span class="code-lines">3</span> ATTR "Name"<br /><span class="code-lines">4</span> ATTR "%ATTRNAME%" push-button no-param<br /></div>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.<br /><img src="" /><br /><br />Ad 2)<br /> ·Create an attribute of type PROGRAMCALL.<br /> ·Configure the attribute AttrRep<div class="code"><span class="code-lines">1</span> NOTEBOOK<br /><span class="code-lines">2</span> CHAPTER "Description"<br /><span class="code-lines">3</span> ATTR "Name"<br /><span class="code-lines">4</span> ATTR "%ATTRNAME%"<br /></div> ·Configure the attribute GraphRep by defining a HOTSPOT<br /><br />A <strong>HOTSPOT </strong>element links the rectangular region specified by <strong>x</strong>, <strong>y</strong>, <strong>w</strong> and <strong>h</strong> to the object attribute specified by the main parameter <em>attrName.</em> The element itself is invisible in the graphical representation.<br />Moving the mouse over a <strong>HOTSPOT </strong>region of an INTERREF or a PROGRAMCALL attribute lets the mouse cursor become a pointing hand. Additionally the corresponding attribute value or any specified <strong>text </strong>is shown in a balloon window.<br />Clicking on a <strong>HOTSPOT </strong>region has the same effect as clicking on the text of an <strong>ATTR </strong>element for the same attribute.<br /><strong><br />HOTSPOT </strong><em>attrName </em>[ <strong>text:</strong><em>strExpr</em> ]<br />[ <strong>x:</strong><em>xposExpr</em> ] [ <strong>y:</strong><em>yposExpr</em> ]<br />[ <strong>w:</strong><em>widthExpr</em> ] [ <strong>h:</strong><em>heightExpr</em> ]<br /> <br /><strong>Example: </strong><strong>Hotspot for a PROGRAMCALL attribute</strong><div class="code"><span class="code-lines"> 1</span>GRAPHREP<br /><span class="code-lines"> 2</span>PEN w:0.05cm<br /><span class="code-lines"> 3</span>FILL color:dodgerblue<br /><span class="code-lines"> 4</span>RECTANGLE x:-1.4cm y:-.7cm w:2.8cm h:1.4cm<br /><span class="code-lines"> 5</span>AVAL ed:" External Documentation " # External documentation<br /><span class="code-lines"> 6</span>IF (LEN ed)<br /><span class="code-lines"> 7</span> FILL color:$cafe69 # hidden message? ;-)<br /><span class="code-lines"> 8</span> POLYGON 7 x1:1.2cm y1:-0.4cm x2:1.6cm y2:-0.4cm x3:1.6cm y3:-0.5cm<br /><span class="code-lines"> 9</span> x4:2.0cm y4:-0.3cm x5:1.6cm y5:-0.1cm x6:1.6cm y6:-0.2cm<br /><span class="code-lines">10</span> x7:1.2cm y7:-0.2cm<br /><span class="code-lines">11</span> HOTSPOT "External Documentation" x:1.2cm y:-0.5cm w:0.8cm h:0.4cm<br /><span class="code-lines">12</span> text: ("Execute: " + copy (ed, 0, search (ed, "@", 0)))<br /><span class="code-lines">13</span>ENDIF<br /></div> <br /><br /><strong>Result:</strong><br /><img src="http://www.adoxx.org/live/documents/10157/110691/HOTSPOT.png/62e2844a-89de-4d79-acdc-a09d0c7db25b?t=1423487074652" />Mehmet Albayrak2015-02-09T12:06:25ZSetting enumerations in ADO scriptJonas Kaiserhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=2261742015-02-07T14:17:36Z2015-02-07T14:17:36ZHello,<br />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 ?<br /><br />Thank you very much,<br />Jonas KaiserJonas Kaiser2015-02-07T14:17:36Z