PDA

View Full Version : removing multiple objects


durf
08-04-2009, 08:29 AM
Hello,

I cannot figure out how to remove or delete multiple objects that have been created this way:


def balls():
ball = ballOriginal.copy()
ball.scale(.5,.5,.5)
ball.collideSphere()
ball.setPosition([0,20,0])
vizact.ontimer2(0,200,balls)


How can I remove all 200 of those balls?

Thanks

farshizzo
08-04-2009, 03:55 PM
You should save each object you create into a global list. Then you can periodically go through the list and remove the objects.

durf
08-04-2009, 04:01 PM
Is there a good example of this to follow?

farshizzo
08-04-2009, 04:09 PM
I'm not sure there is an example that does exactly what you want, but the Duck Court example script that comes with Vizard shows how to save objects into a global list so they can be referenced later.

durf
08-05-2009, 07:31 AM
ballList = []

def balls():
ball = ballOriginal.copy()
ball.scale(.5,.5,.5)
ball.collideSphere()
ball.setPosition([0,20,0])
ballList.append(ball)
vizact.ontimer2(0,200,balls)


So I added a global list... how do you "periodically go through the list and remove the objects"? I tried ballList.remove() and that didn't work.

GiudiceLab
08-05-2009, 09:02 AM
I'm not sure if I understand exactly what you want to do, but if you first make the global list and then want to take all the balls out of it, you could:

for row in range(len(ballList)):
ballList[row].remove()

which will cycle through your list and remove each item.

Or, you could just erase your list by re-initializing it (I think):
ballList = []

durf
08-05-2009, 09:13 AM
Ok I will give that a try later... thanks for the feedback

durf
08-05-2009, 09:15 AM
Great I think it worked.