Having default elements after creating a new modelHaving default elements after creating a new modelRE: Having default elements after creating a new modelDavid Burkehttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3545322015-08-04T08:33:31Z2015-08-04T08:28:01ZDear Fadi, <br /><br />To implement the suggestion by Wilfrid, there are two modifications that one would make to the library. This would probably be the better option, since it would take into account that the GraphRep will probably be much more complicated than a simple circle or square. <br /><br />1) Firstly, to make the objects resizable the command "sizing:" is used in the GraphRep. There are three options here "symmetrical", "asymmetrical" and "keep-aspect-ratio". Hence, instead of the GraphRep code written in a previous post for A, one could simply put<br /><br /><div class="code"><span class="code-lines">1</span>GRAPHREP<br /><span class="code-lines">2</span>sizing:asymmetrical<br /><span class="code-lines">3</span><br /><span class="code-lines">4</span>SET cmRadius: (2cm)<br /><span class="code-lines">5</span>FILL color:red<br /><span class="code-lines">6</span>ELLIPSE x: (0cm) y: (0cm) rx: (cmRadius) ry: (cmRadius)<br /></div><br /><br />and similarly for B, C and D. The part "<strong>sizing:asymmetrical</strong>" written in line 2 makes the GraphRep for the object resizable. <br /><br />2) When we created the objects in the AdoScript written in the previous post, we wrote a string to the "Position" attibute in lines 11, 18, 31 and 38. In this case, all we would need to do is modify these lines so that they also sets the size of the object. So, for example, for line 11 it would read<br /><br /><div class="code"><span class="code-lines">1</span>CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:5cm w:4cm h:4cm index:1"</div><br /><br />The extra part "<strong>w:4cm h:4cm</strong>" <strong></strong><strong></strong>defines the width and height of the object respectively. <br /><br />As a final point, one does not need the attribute "Default object" anymore either, so this attribute can safely be removed. With these modifications, the same effect is achieved, but the method is more generic.David Burke2015-08-04T08:28:01ZRE: Having default elements after creating a new modelWilfrid Utzhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3544952015-08-04T07:18:39Z2015-08-04T07:18:39ZFollowing David's comment, please keep in mind that the size of the object created relates on the characteristics defined in the GRAPHREP, more specifically on the sizing options.<br />In case the object is not resizeable (or does not implement the behaviour of David above), the size will always be the same. In case resizeable, using the respective sizing option (e.g sizing:asymmetrical), you can set the size of the object when created using the "Position" attribute. The "Position" attribute is a LEO string (can be parsed with the LEO commannd) and contains the x, y, w, h and index value. You can construct the Postion value and define your own sizing (in h and w) and the object would then appear accordingly.Wilfrid Utz2015-08-04T07:18:39ZRE: Having default elements after creating a new modelDavid Burkehttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3544782015-08-04T06:42:34Z2015-08-04T06:22:58ZDear Fadi, <br /><br />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 <br />default object larger. In this library, there are two model types named "Modeltype AB" and "Modeltype CD". Modeltype AB contains two objects <br />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 <br />respectively. When a new model is created for either of these model types, a default instance of the classes is created. Furthermore, the default <br />objects that are created are larger (2cm). Any instance of the classes created after that have a size of only 1cm. <br /><br /><img src="https://www.adoxx.org/svn/all-repo/5_ADOxx_SupportLibraries_ADOxx13UL1/Create%20default%20instance%20after%20model%20create/Images/Model.PNG" /><br /><br />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 <br />"No". The full AdoScript for the creation of the default objects is <br /><br /><div class="code"><span class="code-lines"> 1</span>PROCEDURE global CREATE_PREDEFINED_OBJECTS nModelID: integer<br /><span class="code-lines"> 2</span>{<br /><span class="code-lines"> 3</span><br /><span class="code-lines"> 4</span> CC "Core" GET_MODEL_INFO modelid: (nModelID)<br /><span class="code-lines"> 5</span><br /><span class="code-lines"> 6</span> IF ( modeltype = "Modeltype AB") {<br /><span class="code-lines"> 7</span> #add standard objects<br /><span class="code-lines"> 8</span> CC "Core" GET_CLASS_ID classname: "A"<br /><span class="code-lines"> 9</span> SETL nClassA: (classid) <br /><span class="code-lines">10</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: (nClassA) objname: ("A")<br /><span class="code-lines">11</span> CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:5cm index:1"<br /><span class="code-lines">12</span> CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"<br /><span class="code-lines">13</span><br /><span class="code-lines">14</span> CC "Core" GET_CLASS_ID classname: "B"<br /><span class="code-lines">15</span> SETL nClassB: (classid) <br /><span class="code-lines">16</span> <br /><span class="code-lines">17</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: (nClassB ) objname: ("B")<br /><span class="code-lines">18</span> CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:10cm index:1"<br /><span class="code-lines">19</span> CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"<br /><span class="code-lines">20</span> <br /><span class="code-lines">21</span> # repeat for more objects of this class and/or for more classes<br /><span class="code-lines">22</span><br /><span class="code-lines">23</span> CC "Core" SAVE_MODEL modelid: (nModelID)<br /><span class="code-lines">24</span> }<br /><span class="code-lines">25</span><br /><span class="code-lines">26</span> ELSIF (modeltype = "Modeltype CD") {<br /><span class="code-lines">27</span> #add standard objects<br /><span class="code-lines">28</span> CC "Core" GET_CLASS_ID classname: "C"<br /><span class="code-lines">29</span> SETL nClassC: (classid) <br /><span class="code-lines">30</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: (nClassC) objname: ("C")<br /><span class="code-lines">31</span> CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val:"NODE x:3cm y:5cm index:1"<br /><span class="code-lines">32</span> CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"<br /><span class="code-lines">33</span><br /><span class="code-lines">34</span> CC "Core" GET_CLASS_ID classname: "D"<br /><span class="code-lines">35</span> SETL nClassD: (classid) <br /><span class="code-lines">36</span><br /><span class="code-lines">37</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClassD ) objname: ("D")<br /><span class="code-lines">38</span> CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Position" val: "NODE x:3cm y:10cm index:1"<br /><span class="code-lines">39</span> CC "Core" SET_ATTR_VAL objid: (objid) attrname:"Default object" val:"Yes"<br /><span class="code-lines">40</span> <br /><span class="code-lines">41</span> # repeat for more objects of this class and/or for more classes<br /><span class="code-lines">42</span><br /><span class="code-lines">43</span> CC "Core" SAVE_MODEL modelid: (nModelID)<br /><span class="code-lines">44</span> }<br /><span class="code-lines">45</span> # repeat for all needed model types<br /><span class="code-lines">46</span><br /><span class="code-lines">47</span>}<br /></div><br /><br />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 <br />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.<br /><br /><div class="code"><span class="code-lines"> 1</span>GRAPHREP<br /><span class="code-lines"> 2</span><br /><span class="code-lines"> 3</span>AVAL sDef:"Default object"<br /><span class="code-lines"> 4</span><br /><span class="code-lines"> 5</span>IF (sDef = "Yes")<br /><span class="code-lines"> 6</span>SET cmRadius: (2cm)<br /><span class="code-lines"> 7</span>ELSE<br /><span class="code-lines"> 8</span>SET cmRadius: (1cm)<br /><span class="code-lines"> 9</span>ENDIF<br /><span class="code-lines">10</span><br /><span class="code-lines">11</span>FILL color:red<br /><span class="code-lines">12</span>ELLIPSE x: (0cm) y: (0cm) rx: (cmRadius) ry: (cmRadius)<br /></div><br /><br />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<br /><br /><div class="code"><span class="code-lines">1</span>ON_EVENT "CreateModel"<br /><span class="code-lines">2</span>{<br /><span class="code-lines">3</span>EXECUTE file: "db:\\scripts_predefined_objects.asc"<br /><span class="code-lines">4</span>CREATE_PREDEFINED_OBJECTS nModelID: (modelid)<br /><span class="code-lines">5</span>}<br /></div><br /> <br />The library itself can be downloaded here:<br /><br /><a href="https://www.adoxx.org/svn/all-repo/5_ADOxx_SupportLibraries_ADOxx13UL1/Create%20default%20instance%20after%20model%20create/BIN/Create%20Default%20Elements%20after%20Model%20Create%20Library.abl">Create Default Elements after Model Create Library.abl</a>David Burke2015-08-04T06:22:58ZRE: Having default elements after creating a new modelFadi Al Machothttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3543632015-08-03T14:46:25Z2015-08-03T14:46:25ZI mean when a new model is created of type "Model A", an instance of class A is created as a default object. This default created one, for example, is a circle with radius 4cm, although in graphrep, the radius could be only 2cm !Fadi Al Machot2015-08-03T14:46:25ZRE: Having default elements after creating a new modelDavid Burkehttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3538412015-08-03T11:18:46Z2015-08-03T11:14:17ZDear Fadi,<br /><br />Could you specify what you mean by being able to change the size of the default object ? <br /><br />Do you mean by that, the following scenario for example:<br />When a new model is created of type "Model A", an instance of class A is created as a default object. This default created one, for example, is a circle with radius 2cm. If one creates another instance of A in the model after that though the circle is smaller with only a radius 1cm. <br /><br />Or is your question more generic, about how to make an object resizable or how to write Graphical Representation code defining an object's size ? <br /><br />If you can clear up what you wish by maybe describing a scenario we can try and post an example. <br /><br />Kind regards, <br /><br />DavidDavid Burke2015-08-03T11:14:17ZRE: Having default elements after creating a new modelFadi Al Machothttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3538342015-08-03T09:50:22Z2015-08-03T09:50:22ZDear Wilfrid & Sabin,<br />thank you very much,<br />is it possible to change the size of the default object? <br />If yes would you please post an exampleFadi Al Machot2015-08-03T09:50:22ZRE: Having default elements after creating a new modelWilfrid Utzhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3533462015-07-31T10:56:07Z2015-07-31T10:56:07ZHi Fadi, Sabin,<br /><br />potentially this threads could help you as well. It relates to default models and event handling specifically using variants and views.<br /><br /><a href="http://www.adoxx.org/live/faq/-/message_boards/message/110883">http://www.adoxx.org/live/faq/-/message_boards/message/110883<br /></a><br /><a href="http://www.adoxx.org/live/faq/-/message_boards/message/110765">http://www.adoxx.org/live/faq/-/message_boards/message/110765 (incl. Variant Management Examples)</a>Wilfrid Utz2015-07-31T10:56:07ZRE: Having default elements after creating a new modelSabin Popescuhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3533392015-07-31T10:33:38Z2015-07-31T10:29:59ZHi, Fadi.<br /><br />You can achieve the desired behavior using the event "CreateModel", described <a href="http://www.adoxx.org/AdoScriptDoc/files/Events/Core/CreateModel-js.html">here</a>.<br />All you have to do is define an event handler for the event "CreateModel" in the library attribute "External coupling" of your library.<br />The event handler should look like this:<div class="code"><span class="code-lines"> 1</span>ON_EVENT "CreateModel"<br /><span class="code-lines"> 2</span>{<br /><span class="code-lines"> 3</span> SETL nModelID: ( modelid ) <br /><span class="code-lines"> 4</span> CC "Core" GET_MODEL_INFO modelid: ( nModelID)<br /><span class="code-lines"> 5</span><br /><span class="code-lines"> 6</span> IF ( modeltype = "MyModelType_01") {<br /><span class="code-lines"> 7</span> #add standard objects<br /><span class="code-lines"> 8</span> CC "Core" GET_CLASS_ID classname: "MyClass_011"<br /><span class="code-lines"> 9</span> SETL nClass01ID: ( classid ) <br /><span class="code-lines">10</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID ) objname: ("MyObject_011_1")<br /><span class="code-lines">11</span> CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:5cm index:1"<br /><span class="code-lines">12</span> <br /><span class="code-lines">13</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID ) objname: ("MyObject_011_2")<br /><span class="code-lines">14</span> CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:8cm index:1"<br /><span class="code-lines">15</span> <br /><span class="code-lines">16</span> # repeat for more objects of this class and/or for more classes<br /><span class="code-lines">17</span><br /><span class="code-lines">18</span> CC "Core" SAVE_MODEL modelid: (nModelID)<br /><span class="code-lines">19</span> }<br /><span class="code-lines">20</span><br /><span class="code-lines">21</span> ELSIF ( modeltype = "MyModelType_02") {<br /><span class="code-lines">22</span> #add standard objects<br /><span class="code-lines">23</span> CC "Core" GET_CLASS_ID classname: "MyClass_21"<br /><span class="code-lines">24</span> SETL nClass01ID: ( classid ) <br /><span class="code-lines">25</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID ) objname: ("MyObject_021_1")<br /><span class="code-lines">26</span> CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:5cm index:1"<br /><span class="code-lines">27</span> <br /><span class="code-lines">28</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID ) objname: ("MyObject_021_2")<br /><span class="code-lines">29</span> CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:8cm index:1"<br /><span class="code-lines">30</span> <br /><span class="code-lines">31</span> # repeat for more objects of this class and/or for more classes<br /><span class="code-lines">32</span><br /><span class="code-lines">33</span> CC "Core" SAVE_MODEL modelid: (nModelID)<br /><span class="code-lines">34</span> }<br /><span class="code-lines">35</span> # repeat for all needed model types<br /><span class="code-lines">36</span>}<br /></div><br />Of course, this piece of code may be very complex if you have many model types and many standard objects, so you could create a global procedure (called for exampe CREATE_PREDEFINED_OBJECTS), store it in a file in the application library and call it from the event handler<br /><br />In this case, the event handler would look like this:<br /><div class="code"><span class="code-lines">1</span>ON_EVENT "CreateModel"<br /><span class="code-lines">2</span>{<br /><span class="code-lines">3</span> EXECUTE file: "db:\\scripts_predefined_objects.asc"<br /><span class="code-lines">4</span> CREATE_PREDEFINED_OBJECTS nModelID: ( modelid )<br /><span class="code-lines">5</span>}<br /></div><br />and the definition of the procedure would be:<div class="code"><span class="code-lines"> 1</span>PROCEDURE global CREATE_PREDEFINED_OBJECTS nModelID: integer<br /><span class="code-lines"> 2</span>{<br /><span class="code-lines"> 3</span><br /><span class="code-lines"> 4</span> CC "Core" GET_MODEL_INFO modelid: ( nModelID)<br /><span class="code-lines"> 5</span><br /><span class="code-lines"> 6</span> IF ( modeltype = "MyModelType_01") {<br /><span class="code-lines"> 7</span> #add standard objects<br /><span class="code-lines"> 8</span> CC "Core" GET_CLASS_ID classname: "MyClass_011"<br /><span class="code-lines"> 9</span> SETL nClass01ID: ( classid ) <br /><span class="code-lines">10</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID ) objname: ("MyObject_011_1")<br /><span class="code-lines">11</span> CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:5cm index:1"<br /><span class="code-lines">12</span> <br /><span class="code-lines">13</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID ) objname: ("MyObject_011_2")<br /><span class="code-lines">14</span> CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:8cm index:1"<br /><span class="code-lines">15</span> <br /><span class="code-lines">16</span> # repeat for more objects of this class and/or for more classes<br /><span class="code-lines">17</span><br /><span class="code-lines">18</span> CC "Core" SAVE_MODEL modelid: (nModelID)<br /><span class="code-lines">19</span> }<br /><span class="code-lines">20</span><br /><span class="code-lines">21</span> ELSIF ( modeltype = "MyModelType_02") {<br /><span class="code-lines">22</span> #add standard objects<br /><span class="code-lines">23</span> CC "Core" GET_CLASS_ID classname: "MyClass_21"<br /><span class="code-lines">24</span> SETL nClass01ID: ( classid ) <br /><span class="code-lines">25</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID ) objname: ("MyObject_021_1")<br /><span class="code-lines">26</span> CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:5cm index:1"<br /><span class="code-lines">27</span> <br /><span class="code-lines">28</span> CC "Core" CREATE_OBJ modelid: (nModelID) classid: ( nClass01ID ) objname: ("MyObject_021_2")<br /><span class="code-lines">29</span> CC "Core" SET_ATTR_VAL objid: ( objid ) attrname: "Position" val: "NODE x:3cm y:8cm index:1"<br /><span class="code-lines">30</span> <br /><span class="code-lines">31</span> # repeat for more objects of this class and/or for more classes<br /><span class="code-lines">32</span><br /><span class="code-lines">33</span> CC "Core" SAVE_MODEL modelid: (nModelID)<br /><span class="code-lines">34</span> }<br /><span class="code-lines">35</span> # repeat for all needed model types<br /><span class="code-lines">36</span><br /><span class="code-lines">37</span>}<br /></div><br />This second option would also enable you to read a predefined configuration for each model type from an XML-file stored in the application library or externally, at a preconfigured location, and based on each particular configuration, call a procedure that creates each object.<br /><br />The parameters of the command calls CREATE_OBJECT and SET_ATTR_VAL are described in the <a href="http://www.adoxx.org/AdoScriptDoc/index.html">AdoScript Documentation</a> as well.<br />Hope this helps.Sabin Popescu2015-07-31T10:29:59ZHaving default elements after creating a new modelFadi Al Machothttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=3533222015-07-31T08:42:29Z2015-07-31T08:39:56ZHi, is it possible to create a new model (adding a new model from our model groups) which contains default elements? because we get usually empty models.Fadi Al Machot2015-07-31T08:39:56Z