Check if body exist with a specific id and get error code

Hi,

Is there a way to check if a body with a specific id exist in my project using python? If I try, for example, to use a command with a body id that does not exist, how do I get the error code using python?

Thanks,

Hi,

I can think of two ways to do this. You will not necessarily get an error code but you can catch and detect the error.

  1. Use a try/except to get the body by id. Cubit will throw a RuntimeError if the given body id does not exist.
cubit.cmd("reset")
cubit.cmd("brick x 10")

try:
  b = cubit.body(2)
except RuntimeError:
    print("Error")
  1. Use cubit.parse_cubit_list() to get the body by id. If the body does not exist, it will return an empty tuple.
body_exists = cubit.parse_cubit_list("body", "2")
if body_exists:
   print("Found it")
else:
   print("Error")

Karl

1 Like