With respect to unique object names, this is an intended behaviour, that 2 instances derived from the same class need to have a unique name, therefore by default (creating a new object the following logic is applied: "Classname" + ObjectID. To overcome this limitation, it is possible to define a new attribute that holds a none-unique name of the object and also allows same naming of same-class instances. The object's name can be generated using event and script logic:
To enable this feature please follow the steps below:
a) Define a new attribute of type STRING, named "Denomination"
b) Add the new attribute in the ATTRREP of the class so that it appears in the notebook of the instance. For the "Name" attribute define it as write-protected, meaning that the value can not be changed by the user, but by the event-based script
1NOTEBOOK
2CHAPTER "Description"
3ATTR "Denomination"
4ATTR "Name" write-protected
c) Update/modify the GRAPHREP so that the new attribute is visualized instead of the "Name" attribute
1GRAPHREP
2SHADOW off
3# Tyres
4ELLIPSE x:-0.5cm rx:0.3cm ry:0.3cm
5ELLIPSE x:0.5cm rx:0.3cm ry:0.3cm
6# Body
7LINE x1:-0.2cm x2:0.2cm
8LINE x1:-0.8cm x2:-1cm
9LINE x1:0.8cm x2:1cm
10LINE x1:1cm x2:1cm y2:-0.5cm
11LINE x1:-1cm x2:-1cm y2:-0.5cm
12LINE x1:-1cm x2:1cm y1:-0.5cm y2:-0.5cm
13# Roof
14LINE x1:-0.5cm x2:-0.3cm y1:-0.5cm y2:-0.9cm
15LINE x1:0.5cm x2:0.3cm y1:-0.5cm y2:-0.9cm
16LINE x1:-0.3cm x2:0.3cm y1:-0.9cm y2:-0.9cm
17# Windows
18LINE y1:-0.5cm y2:-.9cm
19
20ATTR "Denomination" y:0.7cm w:c h:c
c) Define an event listener to update the "Name" attribute. It is important to decide on which event this should be triggered, our proposal would be to run it before a model is saved. The actual logic how an objectname is only available as a FIXME in this snipplet. Please make sure to update the code accordingly. The code snipplet should be added in the "External coupling" library attribute of the dynamic library.
1ON_EVENT "BeforeSaveModel" {
2 # modelid : integer
3 # origin : string Origin of the save action call. "new", "save", "saveas-new" or "saveas-save".
4 # persist for the event the modelid
5 SETL saveModelID:(modelid)
6 CC "Core" GET_ALL_OBJS modelid: (saveModelID)
7 SETL lObjIDs:(objids)
8 # iterate through all objects in the model
9 FOR sObjID in:(lObjIDs) {
10 # FIXME: logic to generate the name should be added here
11 SETL sObjName:("NewObjectName")
12 # save the objectname in the object
13 CC "Core" SET_ATTR_VAL objid: (VAL sObjID) attrname: ("Name") val:(sObjName)
14 }
15}