I load an SDF file which contains multiple robots/objects and I want to get back the "names" of these robots/objects as defined in the SDF. PyBullet when using loadSDF
will return a list of unique IDs for these bodies, I want to convert these IDs to names. Is that possible?
Asked
Active
Viewed 163 times
0

Phrixus
- 1,209
- 2
- 19
- 36
1 Answers
1
The getBodyInfo()
method, see example here, returns a tuple containing the name of the body as the first element, so you can access it using body_info[0]
, though you have to keep in mind this information might be encoded, you might need .decode()
for human readable representation.
This only works with unique names if the SDF file contains unique names for each body. If multiple bodies have the same name, then only the first body with that name will be returned. In that case you have to use something like setBodyUniqueId()
method to set a unique ID for each body if necessary.

daniel451
- 10,626
- 19
- 67
- 125
-
Thank you! Do you know if the "index" of the body is the body id? That is, if there are 5 bodies, and you get 0, 1, 2, 3, 4 as indices of the bodies, would they correspond to the IDs PyBullet understands internally? In other words, could I construct a dictionary mapping the object_names with the object IDs (that PyBullet expects) so that I can query using both information? – Phrixus Dec 15 '22 at 15:37
-
Probably worth of another question. The short answer is no, you would need to assign unique IDs since they are not the same as the IDs PyBullet uses internally. – daniel451 Dec 15 '22 at 16:55
-
I found the `getBodyUniqueId(body_index)` to work. – Phrixus Dec 15 '22 at 17:04
-
Yes, this one would work but as mentioned in answer there might be occasions where PyBullets internal representation is different, then you have to set unique IDs first. – daniel451 Dec 15 '22 at 17:35