Dear Jonas,
Firstly to mention, there is a platform implementation for functionality related to your question. In the model editor under "Global Change", (menu item "Edit" -> "Global Change") there is an option to change the value of an attribute for all objects of a particular class. One goes to "Global Change" and adds a query to "Get all objects of class..". In the next step one selects the attribute that one wants to change. This change will then effect all objects of that class.
However, as you noted, you wish to change this attribute for *all* classes which have the attribute "ShowTextbox". In this case, one can write some AdoScript code to do this. The main points of the code are
1) Use the command "GET_ALL_OBJS" to get the IDs of all objects in the current model.
2) For each of these objects we make a call to "GET_ATTR_ID".
3) The trick is to look for what this call returns - if it returns "-1" we know that the object does not have this attribute. This allows us to only try and change the attribute "ShowTextbox" for objects that actually have this attribute.
The code itself is shown below, and is saved in the database under the filename "Change Attribute Value for all Objects Possessing Attribute.asc".
1SEND "GET_ACTIVE_MODEL" to:"Modeling" answer:modelid
2SET id_ModelId:(modelid)
3# First we retrieve all objects in the active model, and put the object ids in a list "l_objIds"
4CC "Core" GET_ALL_OBJS modelid:(VAL id_ModelId)
5SET l_objIds:(objids)
6
7# In this case, "Yes" is represented by 1, and "No" by 0 - which is equivalent to the box being checked or
8# unchecked respectively in the notebook
9SET n_yesVal:1
10SET n_noVal:0
11
12# The attribute name whose value we wish to change is called "ShowTextbox" here. We have three menu options in the model editor,
13# "Yes" which, for all objects having the attribute "ShowTextbox", changes the value to 1 (i.e. "Yes")
14# "No" which, for all objects having the attribute "ShowTextbox", changes the value to 0 (i.e. "No")
15# "Toggle" which, for all objects having the attribute "ShowTextbox", changes it to 0 if it was previously 1, and 1 if it was previously 0
16IF (s_menuOption = "Yes") {
17 # We loop over the objects in our active model. We perform an attempt to get the ID of the attribute "ShowTextbox" for the current object.
18 # If this attribute doesn't exist for the current object we get a value -1 returned. If we don't get -1 the object has the attribute
19 # and we change its value accordingly.
20 FOR s_objId in:(l_objIds) {
21 CC "Core" GET_CLASS_ID objid:(VAL s_objId)
22 SET id_ClassId:(classid)
23 CC "Core" GET_ATTR_ID classid:(id_ClassId) attrname:"ShowTextbox"
24 IF (attrid != -1) {
25 CC "Core" SET_ATTR_VAL objid:(VAL s_objId) attrname:"ShowTextbox" val:(n_yesVal)
26 }
27
28 }
29
30}
31
32IF (s_menuOption = "No") {
33
34 FOR s_objId in:(l_objIds) {
35 CC "Core" GET_CLASS_ID objid:(VAL s_objId)
36 SET id_ClassId:(classid)
37 CC "Core" GET_ATTR_ID classid:(id_ClassId) attrname:"ShowTextbox")
38
39 IF (attrid != -1) {
40 CC "Core" SET_ATTR_VAL objid:(VAL s_objId) attrname:"ShowTextbox" val:(n_noVal)
41
42 }
43
44 }
45
46}
47
48IF (s_menuOption = "Toggle") {
49
50 FOR s_objId in:(l_objIds) {
51 CC "Core" GET_CLASS_ID objid:(VAL s_objId)
52 SET id_ClassId:(classid)
53 CC "Core" GET_ATTR_ID classid:(id_ClassId) attrname:"ShowTextbox"
54
55 IF (attrid != -1) {
56 CC "Core" GET_ATTR_VAL objid:(VAL s_objId) attrname:"ShowTextbox"
57 # The case of "Toggle" is similar to the above, only that we flip the value of the attribute from "Yes" to "No" and vice versa.
58 IF (val = n_yesVal) {
59 CC "Core" SET_ATTR_VAL objid:(VAL s_objId) attrname:"ShowTextbox" val:(n_noVal)
60
61 }
62
63 IF (val = n_noVal) {
64 CC "Core" SET_ATTR_VAL objid:(VAL s_objId) attrname:"ShowTextbox" val:(n_yesVal)
65
66 }
67
68 }
69
70 }
71
72}
The triggering of the script itself, and the definition of some menu items to execute it, are defined in the library attributes under "Add-ons" and then "External coupling".
There are now three new menu options in the model editor under the "Tools" menu - "Change ShowTextbox to Yes", "Change ShowTextbox to No" and "Toggle ShowTextbox" which execute the AdoScript.
Please find attached a sample model file (ADL). In this case we have classes A and C, which have the attribute "ShowTextbox", and a class B which does not.
For clarity, classes A and C will appear as a blue/green circle if it doesn't have its attribute "ShowTextbox" ticked and is shown with a blue/green circle with a cross
through it if it does have "ShowTextbox" ticked. Class B, which doesn't have the attribute "ShowTextbox", is shown as a red triangle.
Download:
Change Attribute Value for all Objects Possessing Attribute.abl Change Attribute Value for all Objects Possessing Attribute.adl