Page 1 of 1

duplicated object script cannot find other objects by sim.getObjectHandle()

Posted: 05 Feb 2022, 08:28
by pwyq
Hi, in CoppeliaSim 4.2.0 (I haven't tested this with 4.3.0), I found that when I duplicate a robot, the new one is appended a string '#0' (as expected). The child script can get the handle of the robot itself (such as sim.getObjectHandle('robot#0')), but it fails to find any other objects other than the components of the duplicated robot. After I rename the duplicated robot from "robot#0" to "robot_2", the problem disappears. I doubt that the hashtag "#" is messing up with the sim.getObjectHandle.

Re: duplicated object script cannot find other objects by sim.getObjectHandle()

Posted: 07 Feb 2022, 09:23
by coppelia
Hello,

in CoppeliaSim versions prior to V4.3, you would use a unique object name to identify an object. Additionally, in order to enable scripts to automatically operate even after duplication, there was an automatic name adjustment mechanism, e.g.:

From script "robot#42" if you called:
  • handle=sim.getObjectHandle("sensor"), you would get the handle of object "sensor#42" (i.e. "#42" automatically appended)
  • handle=sim.getObjectHandle("sensor#36"), you would get the handle of object "sensor#36"
In the first above example, the sensor would be different for each copy of the robot model, since the robot model's name suffix would automatically change (e.g. "robot#43" --> "sensor#43", "robot#44 --> "sensor#44", etc.). In the second example, the sensor would be hard-wired, i.e. always the same, even in a robot model copy (e.g. "robot#43" --> "sensor#36", "robot#44 --> "sensor#36", etc.)

In CoppeliaSim V4.3 and later, objects have non-unique aliases, and you can easily access any object via an absolute or relative path to the object. See here about details on how to access objects programmatically.

Cheers