Dear Hans-Georg Fill,
apologies for only coming back to you now. You can solve this scenario with the event listener 'SetAttributeValue'. This event is triggered if an attribute value is set, in this case the position attribute. But in this event we have to consider that we should not create an endless loop by setting the attribute value of the same attribute within the script. The add-on implementation below, which is also implemented in the 'Lock Position Library' (see attachment) , shows how you can avoid this endless loop.
Int this application library you can lock or un-lock the position of the object within the notebook through the 'Lock Position' attibute (type:integer).
Additionally we have added a debug logger to track the commands in the ‘Event Logging’ window dynamically - please feel free to remove this development functionality in case you have completed your implementation task. 1#===============================================
2#---- INIT GLOBAL VARS
3ON_EVENT "AppInitialized" {
4 # this global variable controls whether to react to the postion move event
5 SETG bListenToMoveChange:1
6
7 CC "Core" GET_CLASS_ID classname:"Lock"
8 SETG nLocklassID: (classid)
9
10 CC "Core" GET_ATTR_ID classid: (nLocklassID) attrname:"Position"
11 SETG nPositionAttrId: (attrid)
12
13 # create the dockable window for the output stream
14 CC "AdoScript" CREATE_OUTPUT_WIN winid:"EVENTLOG" title:"Event Logging"
15
16 # establish a global procedure as a helper implementation for timestamped logging
17 PROCEDURE global EVENT_LOG msgType:string message:string {
18 CC "Application" GET_DATE_TIME date-format:"dd/mm/yyyy" time-format:"hh:mm:ss"
19 SET currentDateTime: ((date) + " " + (time))
20 CC "AdoScript" OUT winid:"EVENTLOG" text: ("[" + (msgType) + "@" + currentDateTime + "]: " + (message) + "\n")
21 }
22 # Initial event log message for the "AppInitialized" event
23 EVENT_LOG msgType:"EVENT_LOG" message: ("AppInitialized")
24
25}
26ON_EVENT "SetAttributeValue" {
27 SET nInstID: (instid)
28 SET nAttrID: (attrid)
29 SET nModelID: (modelid)
30 SET sOldVal: (oldval)
31 # check if the listener for the event is active
32 IF (bListenToMoveChange) {
33 # check whether object is locked
34 CC "Core" GET_ATTR_VAL objid: (nInstID) attrname:"Lock Position"
35 SET nPositionLocked: (val)
36 # check whether an ecode was returned, and ecode > 0 means that the attribute is not available or existing
37 IF (ecode = 0) {
38 IF (nPositionLocked = 1) {
39 # check whether the change happen in the Positon attribute
40 IF (nAttrID = nPositionAttrId) {
41 # get new value for logging only
42 CC "Core" GET_ATTR_VAL objid: (nInstID) attrid: (nAttrID)
43 SET sNewPosition: (val)
44 SET sOldObjPosition: (sOldVal)
45 # log to window
46 EVENT_LOG msgType:"EVENT_LOG" message: ("Changed position from " + sOldObjPosition +" to " +sNewPosition)
47 # important: change the listener to 0 -> no event triggered in the update position. Otherwise endless loop -> crash
48 SETG bListenToMoveChange:0
49 LEO parse: (sOldObjPosition) get-tmm-value:x:"x" get-tmm-value:y:"y"
50 CC "Modeling" SET_OBJ_POS objid: (nInstID) x: (x) y: (y)
51 # reset the listener after position change
52 SETG bListenToMoveChange:1
53 }
54 }
55 }
56 }
57}