Notifications
Clear all

[Closed] update object list

I tough I finish my tool but I have following problem. I conducting operations on scene objects like select and delete, hide, isolate etc objects from my array list. Problem is if some of these object will be changed by user (like change name, group destry, object delete etc) there is script error because list appeal to not existing objects so my question is:
How to check which of objects from my list still exist and use it as new objects selection for my operation. If there is no object from list prevent action.

Problem look like this

—- use scene with some objects

myobjects=#()
select objects
for o in selection do
(
append myobjects o
select o
)

delete $

select myobjects –<— HERE IS PROBLEM, HOW TO CHECK ON HOW MANY OBJECT STILL —-EXISTING I CAN CONDUCT OPERATION

3 Replies

there are three functions that can help you


isvalidnode
isvalidobj
isdeleted

for objects you can use isvalidnode… it returns FALSE for deleted objects. so you don’t need to combine it with isdeleted
so the code might look:


(
	myobjects = ....
	
	myobjects = for obj in myobjects where isvalidnode obj collect obj
)

Thank you, I used all 3 different commands like you gave me and test it on selected objects and it seems it prevent code from errors but don’t execute anything. It seems like selection is empty inspite I delete only one object from it. In last case when I use isnodedelete action was ok but there was error in listner.

This is my test code, it should select rest of object after removing one of them from scene:

(
myobjects = #()

for i in selection do
(
	append myobjects i
	select i
)

delete $
myobjects = for obj in myobjects where isvalidnode obj collect obj
select myobjects  --&lt;---- selection is still empty

)

Sorry, I did somthing wrong with it, your script work fine, this is exactlywhat I was looking for. Thank you. Thanks for saving my day.