PDA

View Full Version : Persistent Node Arrays


BoubQC
05-05-2011, 06:19 PM
Hey guys! In one of my script I'm working with arrays containing nodes. I'm not sure if i use the best method to do it and maybe you could give me some ideas. I store my arrays in a Persistent Global variable. It works fine... I have a callback so if an object is deleted I collect of the valid nodes to rebuild my array. One of the problems I faced is if I holdMaxFile()and I fetch it after. All the arrays gets invalid... I was able to get around that but finding another way to store my nodes would be great... And for the persistent global I was thinking storing it in the sceneroot defined properties it's just not done yet! So if you guys have any ideas!? Thanks!

denisT
05-05-2011, 07:25 PM
I use Persistent Globals but always try to minimize the usage. Persistent Globals have some problems on merge (fetch) and xref scene. So I recommend you to mark all your nodes by some Custom Attribute. After that it will be easy and fast enough to find all nodes by the attribute. Using this method you will not mess with callbacks (delete, clone, copy, undo/redo, merge node, etc.)
here is a sample:

global identifier = attributes "Identifier" attribID:#(0x1cabed9b, 0x5555de47)
(
parameters main
(
id type:#integer default:0
)
)
fn getnodesByAttr attr =
(
for a in (custAttributes.getDefInstances attr)
where isvalidnode (node = refs.dependentnodes (custAttributes.getOwner a) firstonly:on)
collect node
)
(
delete objects
for k=1 to 1000 do
(
custAttributes.add (obj = box()) identifier BaseObject:on
)
format "nodes: %\n" (getnodesByAttr identifier).count
)

Panayot
05-05-2011, 10:16 PM
setAppData() is also good and easy way to 'stamp' your objects.

denisT
05-05-2011, 10:30 PM
setAppData() is also good and easy way to 'stamp' your objects.

It's slow to search by app data. You have to loop through all nodes. Another problem is that app data doesn't copy with copied (cloned) node.

groutcho
05-06-2011, 10:56 AM
I was wondering about CA : If the CA is put on the scene node, will it be conserved on merges or xrefs ?

PEN
05-06-2011, 01:14 PM
Yes, Ca Defs come with the objects where every they go, they can hold all sorts of data types as well as store and display UI's.

groutcho
05-06-2011, 01:23 PM
Great, it can conveniently replace custom file properties if we merge often.

Panayot
05-06-2011, 10:08 PM
It's slow to search by app data. You have to loop through all nodes. Another problem is that app data doesn't copy with copied (cloned) node.Thanks for the note.

Yes, AD needs to loop through all nodes. Also not preserved when copied but I see some benefit here. I use app data to make my own hadle enumeration. Never mind, at the point of performance, CAs is better one.

denisT
05-06-2011, 10:33 PM
Thanks for the note.

Yes, AD needs to loop through all nodes. Also not preserved when copied but I see some benefit here. I use app data to make my own hadle enumeration. Never mind, at the point of performance, CAs is better one.

I'm using app data in a lot of places. Usually I prefer to store some node's extra data in app data channels than in node's custom defined properties or CA.

CGTalk Moderation
05-06-2011, 10:33 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.