PDA

View Full Version : Selecting or deleting groups in array


igr
10-14-2009, 02:09 AM
I need to select or delete all groups stored in an array, but first need to check if an array contains <deleted scene object> to avoid "attempt to access a deleted scene object" error message.

Problem is similar as in http://forums.cgsociety.org/showthread.php?t=443154 and I have tried Bobo's solution:

someArray = for o in someArray where isValidNode o collect o

but it doesn't work for groups.

Also, I've tried this:

for obj in someArray where not isDeleted obj do select obj
...
for obj in someArray where not isDeleted obj do delete obj

and got "No ""not"" function for OK".


In fact, I'm trying to select or delete array and it's content. Contents of array are grouped nodes with possibility that some groups have already been deleted in viewport.

Can anyone help me with this?
Thank you!
Igor

JHN
10-14-2009, 09:57 AM
try "isValidNode node" when checking if a node is a valid node.

-Johan

igr
10-14-2009, 02:49 PM
I've already tried "isValidNode Node" with

someArray = for o in someArray where isValidNode o collect o
select somearray

but, it removes everything in an array, not just deleted groups, because all groups are nested arrays within main array and therefore they are not a valid nodes.


When I try with isDeleted function:


for obj in someArray where not isDeleted obj do select obj


it produces "No ""not"" function for OK" error message and I can't figure out what it means and why "not" doesn't work with boolean value "isDeleted obj".

denisT
10-14-2009, 04:39 PM
I need to select or delete all groups stored in an array, but first need to check if an array contains <deleted scene object> to avoid "attempt to access a deleted scene object" error message.

...

In fact, I'm trying to select or delete array and it's content. Contents of array are grouped nodes with possibility that some groups have already been deleted in viewport.




what does your array contain? is it a list of groupHeaders, or groupMembers, or both?

but any way, you have to collect all valid and not deleted nodes from you list:

nodeList = for n in nodeList where isValidNode n and not isDeleted collect n

Technically isValidNode check is enough but I do check for not deleted just in case.

It has to work for group members, group headers, and any node

after that....

You have to know that if you select any group header or group member of a closed group it will automatically select whole group including members and header. So, if you want to select some particular node from the group, you have to open or ungroup this group first.

If want to delete any particular node from the group you can safely do it. It will not effect any other nodes from the group.

igr
10-15-2009, 12:03 PM
Example of my array is something like:

#(#($Dummy:Group1 @ [12.50...,...,...], $Sphere:Sphere1 @ [...], $Box:Box1 @ [...]), #($Dummy:Group2 @ [...], $Sphere:Sphere2 @ [...], $Box:Box2 @ [...]), #($Dummy:Group3 @ ...
and it contains lists of groupHeaders and groupMembers.


...
but any way, you have to collect all valid and not deleted nodes from you list:

nodeList = for n in nodeList where isValidNode n and not isDeleted collect n

Technically isValidNode check is enough but I do check for not deleted just in case.

It has to work for group members, group headers, and any node
...
I've tried:

for obj in someArray where isValidNode obj do delete obj

and nothing happens. I guess that arrays can not be valid nodes, unless I'm missing something here?

denisT
10-15-2009, 02:29 PM
Example of my array is something like:

#(#($Dummy:Group1 @ [12.50...,...,...], $Sphere:Sphere1 @ [...], $Box:Box1 @ [...]), #($Dummy:Group2 @ [...], $Sphere:Sphere2 @ [...], $Box:Box2 @ [...]), #($Dummy:Group3 @ ...
and it contains lists of groupHeaders and groupMembers.



I've tried:

for obj in someArray where isValidNode obj do delete obj

and nothing happens. I guess that arrays can not be valid nodes, unless I'm missing something here?

you have a list of arrays (not a list of nodes)... so, you have to go through all arrays in your list and collect only valid nodes:

someArray = for nodes in someArray collect (for node in nodes where isValidNode node collect node)

if you want do delete all valid nodes:

for nodes in someArray do (for node in nodes where isValidNode node do delete node)

igr
10-15-2009, 04:13 PM
It works! :)

Thank you very much DenisT!

CGTalk Moderation
10-15-2009, 04:13 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.