Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Coordinates and deletion
Answer
11/04/14 12:03
I've created a popup window, when a user creates a specific new object in a model, which gives him the option to choose between 4 options. Each option should then create a certain number of new objects and relations (automatically) to connect those new objects to the initial object. The issue I'm having is finding the function that gives me the coordinates of the that initial object and a way to position the automatically created objects (after the user has given his choice) correctly, meaning, not too far away from the initial object.

Also is there a way to make the delete of those automatically created objects conditional on the deletion of the initial object. Meaning that they can only be deleted if the initial object is deleted and that there would be no other way to delete them. Something less restrictive than the "erasable" you mentioned in our last conversation.

RE: Coordinates and deletion
Answer
11/04/14 12:04 as a reply to Anonymous.
a) Coordinates: the position information is stored in the "Position" attribute, a default attribute by the platform. You can add this attribute to the ATTRREP to see how the values change when you move an object. In order to retrieve and set the coordinates, you can use the following script as an example. This sample would move a set of elements 1 cm to the right.

Please consider in the script that the following logic:
i) Position value is read using the default GET_ATTR_VAL function
ii) The position String is a LEO String and parsed accordingly.
iii) The values to be used in SET_OBJ_POS are measurement values (actually CM) if you calculate thos differently, please convert to a measurement accordingly, using "CM" to transform a real to a centimeter value.

Alternatively to iii) you can also construct the position string in the script and set it using SET_ATTR_VAL. This should be used if you do not have a model window yet but modify in the CORE only.
 1CC "Modeling" GET_SELECTED
 2FOR objid in: (objids) {
 3    CC "Core" GET_CLASS_ID objid: (VAL objid)
 4    IF (NOT isrel) {
 5        # get position
 6        CC "Core" GET_ATTR_ID classid: (classid) attrname:"Position"
 7        CC "Core" GET_ATTR_VAL objid: (VAL objid) attrid: (attrid)
 8        LEO parse: (val) get-tmm-value:x:"x" get-tmm-value:y:"y"
 9        # increment x coordinate and set new position
10        SET x: (x + 1cm)
11        CC "Modeling" SET_OBJ_POS objid: (VAL objid) x: (x) y: (y)
12    }
13}


b) Deleting prevention: My proposal here would be to implement a logic that defines the "Erasable" according to the logic you have in mind. You can simple set the value of the attribute in your script, constructing the model based on the user input. This would leave the events intact and generic and you cover your interaction logic in the script you currently produce.
Another approach could be to cover the logic when an object can be deleted in an EXPRESSION attribute to calculate the value dynamically based on the model setup.
Alternatively, please have a look at the events that prevent the deletion as provided yesterday, and modify the non-delete logic there.

RE: Coordinates and deletion
Answer
11/04/14 12:05 as a reply to Wilfrid Utz.
The coordinates issue works and I haven't had time to check the delete prevention yet.

I have a new problem. When I create a new object in a model, I made it that for that object, a ListBox pops up. The user then chooses if 1-4 objects should be automatically created and linked to the first object. Those objects will also be placed near the first created object, which was why I needed the coordinates. The issue I'm having is that the automatically created objects aren't different instances. Basically the first automatically created object disappears, is considered once the second objects needs to be created and is recreated as the second object and so on. So basically I want  to know how to create different instances of an object in a "while" condition.

RE: Coordinates and deletion
Answer
11/04/14 12:06 as a reply to Anonymous.
If I understand your question/issue correctly, I assume that you have the loop already implemented, the issue why within the loop the iteration does not work relates to the uniqueness condition of instances of the same class. Can you try to change the name and append e.g. a counter value to the name?