How to delete a bunch of objects at once?

Typically: "How do I... ", "How can I... " questions
Post Reply
zhy149
Posts: 71
Joined: 14 Apr 2021, 20:18

How to delete a bunch of objects at once?

Post by zhy149 »

Hello,

I have a bunch of objects in the hierarchy, how can I delete them at once by click or scripts?
Thank you!

coppelia
Site Admin
Posts: 8724
Joined: 14 Dec 2012, 00:25

Re: How to delete a bunch of objects at once?

Post by coppelia »

Hello,

you can shift-select objects in the scene hierarchy then click <delete>.
Programmatically, you can use sim.removeObject or sim.removeModel in various ways, e.g.

Code: Select all

sim.removeObject(objectHandle) -- remove a single object

sim.removeModel(modelHandle) -- remove a single model

sim.removeObject(sim.handle_all) -- remove all objects

-- Remove a list of objects, e.g. the objects that originate at the hierarchy tree of "myRobot":
local baseHandle=sim.getObjectHandle("myRobot")
local objectList=sim.getObjectsInTree(baseHandle)
for i=1,#objectList,1 do
    sim.removeObject(objectList[i])
end
Cheers

Post Reply