[Closed] Persistent Node Arrays
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 [b]holdMaxFile/band 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!
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: %
" (getnodesByAttr identifier).count
)
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.
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.
I was wondering about CA : If the CA is put on the scene node, will it be conserved on merges or xrefs ?
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.
Great, it can conveniently replace custom file properties if we merge often.