blank instances
kaotkbliss
Posts: 2,915
in The Commons
I have some scenes where I instance a lot of different things and parent the instances to other things (like signs on buildings or something)
Going back through the scenes I'm changing some stuff and removing items I've decided not to have in the scene. Is there an easy way to find instances in the tree that no longer have the original object they were created from so I can remove them?

Comments
When you delete the original object, the instances *should* be deleted as well. Is this not happening?
Not that I've ever noticed. It always leaves an instance kinda like when you create a null object Only it's named "instance"...
Ummm... actually you're quite correct. I was talking nonsense. I remebered instances being deleted with the original, but I just double-checked, and they aren't. The reason I thought they were is that in my products, I always parent the instances to the original, so that if the user deletes it, they all go.
So to go back to your original problem.... I can't think of any way to do it, other than going through them all manually in the scene pane, using the visibilty icon to check what they are. Also, it might be worth putting in a feature request for this.
I thought this would be easy to script, but (at least within a session) the target for an instance iss till defined even if the actual node has been deleted. I don't know if that's the correct result or not.
Edit: it does work if the scene is saved and reloaded after the nodes are deleted so I will post it here - though it's a rough draft and will probably need more work to handle instance groups. Run the script with nothing selected and it should select all and only the orphaned instances.
Thank you Richard! :)
Originally I too parented instances to their original object, but then I moved them to attach them to the building they were "part of" in the scene. Then I decided to remove some of the greebles off the buildings which led to this situation.
jag11 pointed out the isInScene() function, which can be used to tell if an item still exists but has been removed from the scene. Rewriting to use that, this script seems to work whether or not the scene has been reloaded since the source item was deleted.