Dear Fadi,
Below is a link to a library which implements both the functionality of creating default objects when a new model is created and which makes the
default object larger. In this library, there are two model types named "Modeltype AB" and "Modeltype CD". Modeltype AB contains two objects
named "A" and "B" which are circles (red and blue respectively). Modeltype CD contains two objects "C" and "D" which are squares (red and blue
respectively. When a new model is created for either of these model types, a default instance of the classes is created. Furthermore, the default
objects that are created are larger (2cm). Any instance of the classes created after that have a size of only 1cm.
This is done by using the script from Sabin's reply above and by using an attribute "Default object" which is an enumeration of either "Yes" or
"No". The full AdoScript for the creation of the default objects is
1PROCEDURE global CREATE_PREDEFINED_OBJECTS nModelID: integer
2{
3
4 CC "Core" GET_MODEL_INFO modelid: (nModelID)
5
6 IF ( modeltype = "Modeltype AB") {
7 #add standard objects
8 CC "Core" GET_CLASS_ID classname: "A"
9 SETL nClassA: (classid)
10 CC "Core" CREATE_OBJ modelid: (nModelID) classid: (nClassA) objname: ("A")
11 CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:5cm index:1"
12 CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"
13
14 CC "Core" GET_CLASS_ID classname: "B"
15 SETL nClassB: (classid)
16
17 CC "Core" CREATE_OBJ modelid: (nModelID) classid: (nClassB ) objname: ("B")
18 CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:10cm index:1"
19 CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"
20
21 # repeat for more objects of this class and/or for more classes
22
23 CC "Core" SAVE_MODEL modelid: (nModelID)
24 }
25
26 ELSIF (modeltype = "Modeltype CD") {
27 #add standard objects
28 CC "Core" GET_CLASS_ID classname: "C"
29 SETL nClassC: (classid)
30 CC "Core" CREATE_OBJ modelid: (nModelID) classid: (nClassC) objname: ("C")
31 CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:5cm index:1"
32 CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"
33
34 CC "Core" GET_CLASS_ID classname: "D"
35 SETL nClassD: (classid)
36
37 CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClassD ) objname: ("D")
38 CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val: "NODE x:3cm y:10cm index:1"
39 CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"
40
41 # repeat for more objects of this class and/or for more classes
42
43 CC "Core" SAVE_MODEL modelid: (nModelID)
44 }
45 # repeat for all needed model types
46
47}
As you can see, in lines 12, 19, 32 and 39, the attribute for the created instance is set to "Yes" whereas by default it would have been set to "No". The GraphRep for the
objects then reads this attribute and if it is set to "Yes" makes it larger, and if set to "No" does not. The GraphRep, for example, for the class A is shown here and the GraphReps for B, C and D are analogous.
1GRAPHREP
2
3AVAL sDef:"Default object"
4
5IF (sDef = "Yes")
6SET cmRadius: (2cm)
7ELSE
8SET cmRadius: (1cm)
9ENDIF
10
11FILL color:red
12ELLIPSE x: (0cm) y: (0cm) rx: (cmRadius) ry: (cmRadius)
As mentioned in the previous post, but for completeness, the calling of the script to create the default instance happens using an event "CreateModel". The code that calls the script is placed in the "External coupling" part of the library (click on "Library attributes", then go to the tab "Add-ons") and is as follows
1ON_EVENT "CreateModel"
2{
3EXECUTE file: "db:\\scripts_predefined_objects.asc"
4CREATE_PREDEFINED_OBJECTS nModelID: (modelid)
5}
The library itself can be downloaded here:
Create Default Elements after Model Create Library.abl