Josiah opened this issue on Nov 19, 2002 ยท 3 posts
Josiah posted Tue, 19 November 2002 at 7:27 PM
I know you cannot delete elements of a mesh figure, such as an arm or finger, But what about magnets? If you delete the base, the magnets heirarchy is also deleted. How can I delete the base?
I think the code below should work by looking at all the actors and deleting any magnet base it finds, however the closest function for deleting it I could find is "DeleteCurrentProp()". Needless to say, it dosen't work!
############################
scene = poser.Scene()
actor = scene.Actors()
~for actor in actors:
~~try:
~~except:
~~~pass
~~else:
~~~actor = scene.CurrentActor()
~~~scene.DeleteCurrentProp()
############################
ockham posted Tue, 19 November 2002 at 10:06 PM
One problem is sort of subtle: in line 3 you use a try/except for a condition that won't really generate an error. If the actor is not a magnet-base, IsBase will simply give 0, which is not an error. So this just needs a plain old If, not a try/except. (I committed this error OFTEN when I first started Pythoning, so I know it well!) The second problem is that you use "actor" for the list-of-actors obtained from scene.Actors(), and also use "actor" for a member of that list. Third problem is that you didn't actually select the actor before deleting it. Below is a version that works: #------------------------------ scene = poser.Scene() for actor in scene.Actors(): # Go through all actors ~if actor.IsBase(): # is it a magnet base? ~~scene.SelectActor(actor) # if so, select it, ~~scene.DeleteCurrentProp() # and then delete it.
Josiah posted Wed, 20 November 2002 at 3:37 AM
Thanks Ockham! I have started to use the try/except way too much, and looking back over some other stuff I can see where I've made the same error! Your version works perfectly (of course)! Thanks again!