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?
The
getBodyInfo()
method, see example here, returns a tuple containing the name of the body as the first element, so you can access it usingbody_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.