Gazebo | Ignition | Community
Ask Your Question

How to add/delete a object mutliple times from a single model file using a plug-in

asked 2014-01-10 07:56:11 -0600

Markus Bader gravatar image


I like to add multiple cylinders with an id and i like also to remove them after a ceartain time using a plug-in. I worked through the model factory example. I am able to add, let's say ten cylinders but all cylinders a named the same. So my first question is how to I add a model, from file with a different name? How to I remove a added model by name using a plug-in?


edit retag flag offensive close merge delete


If you add them as in the tutorial, you could usa a variable for the model name in order to use different values. And you should be able to remove them with

AndreiHaidu gravatar imageAndreiHaidu ( 2014-01-10 09:58:09 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2014-02-10 03:05:32 -0600

scpeters gravatar image

updated 2014-02-10 03:24:42 -0600

Assuming you're using a WorldPlugin, you can use the World::InsertModelSDF or World::InsertModelString API's (see example code from updated tutorial). You can specify the model name as an attribute in the passed SDF object or SDF string. I'm updating the example to show how to do this (pull request #957).

I don't think it's currently possible to specify a custom model name when spawning via a filename with a factory message, though it can be done when passing custom sdf strings (see numerous spawning functions in the ServerFixture class).

edit flag offensive delete link more


Thanks for the update, spawning works now

Markus Bader gravatar imageMarkus Bader ( 2014-04-10 04:42:47 -0600 )edit

answered 2014-01-13 23:00:38 -0600

dkotfis gravatar image

I've been doing this by keeping track of whether a model type exists within the world, and using the clonemodelname field of the factory message to spawn sequential models. With this method, each new model takes the previous with "_clone" appended to its name. Unfortunately, the functions within physics::World needed modify the model name before spawning are private, so I don't think there's a better way right now.

edit flag offensive delete link more

answered 2014-01-13 23:03:04 -0600

dkotfis gravatar image

You can delete models using the "entity_delete" field on the "~/request" topic. Just fill in the model name.

edit flag offensive delete link more

Question Tools



Asked: 2014-01-10 07:56:11 -0600

Seen: 1,964 times

Last updated: Feb 10 '14