View Full Version : getAppData - to identify nodes - problem

10 October 2007, 07:06 PM
Hi guys,

I am using the

setAppData rootNode location string

command to save data out for the scene. This is going really well, until I save out node references. I can save the full node reference and then get it back using getAppData. Apply the appropriate filters to isolate out the nodes into elements of an array. But from there the node reference is still a string. So for example I will get a return like this, for storing 2 spheres....

#("$Sphere:Sphere02 @ [6629.098633,-6203.749023,0.000000]", "$Sphere:Sphere03 @ [737.988281,-7214.803223,0.000000]")

so the first element of this is the array:

"$Sphere:Sphere02 @ [6629.098633,-6203.749023,0.000000]"

My question is how can I get the node from this string? I am sure that it is simple since I have the full reference.... I dont want to filter out the name, since there may well be multiple objects with the same name.....

I have tried string executions like:

execute ("select " + Array[1] as string)

but you cannot select $Sphere:Sphere02 @ [6629.098633,-6203.749023,0.000000]
it will only work if you "select $Sphere02". Which leads to the duplicated objects problem again....

Am I being stupid. If there is a simple way to grab the scene node from a string reference like "$Sphere:Sphere02 @ [6629.098633,-6203.749023,0.000000]" , then it would be awesome to know....

Cheers for your time guys :)


10 October 2007, 07:34 PM
A way to do this (albeit, someone will chime in with a better way) would be to brute force the string to get Sphere02 from it.

-- Function getNodeFromString returns the nodes name if correct and undefined it it's not found
fn getNodeFromString thestring = (
local newNodeString = ""
local start = undefined
local end = undefined

for i = 1 to thestring.count do (
if thestring[i] == ":" then
start = i+1
if thestring[i] == "@" then
end = i - 1
try (
newNodeString = (substring thestring start (end-start))
return newNodeString
return undefined

if (nodeName = getNodeFromString "$Sphere:Sphere02 @ [6629.098633,-6203.749023,0.000000]") != undefined then
execute ("select $" + nodeName)

10 October 2007, 07:43 PM
another way to do this would be to filter through a matchPattern() function, or a findString() function which might be faster, but I didn't think of it till afterwards ;)

10 October 2007, 07:48 PM
Don't save the node, save (assuming all nodes are uniquely named).
When getting the appData, simply use getNodeByName to convert back to node reference.

10 October 2007, 10:29 PM
^ or you could do that. :D

11 November 2007, 08:55 AM
Thanks :)

Awesome feedback. I will store the node name, and enforce a strict no duplicate name policy. It is definitely a good practice to enforce anyway!

Thanks for the feedback guys! :)


11 November 2007, 11:29 AM
I just want to make it clear that you are not storing a node, you are storing a string there for there is no reference to the node kept. If a name of an object is changed the string that is stored for that node will no longer be valid.

Another possible way is to store the nodes as weak references in a custom attribute definition on the root. I don't know why you are doing this so I can't tell you if this is the way that you should go or not.

11 November 2007, 02:20 PM
Cheers PEN,

I have read your page on weak referencing, but I am yet to get my head around it. I think it is something that I need to learn, since I bumped into the same problem with a scripted plugin referencing itself, and your page offered a solution for that.

The tool I am writing is very simple. I am just saving out node name lists which can be used to form fast isolation sets. So artists can save out lists of nodes with the scene, and then jump between isolated modes very quickly for different object sets. I am using the rootnode data partly as an exercise, but the first draft of the tool has had very positive feedback.

Could I set up similar node lists in weak references stored in custom attributes on the rootnode? If so, this way of directly referencing the node would be great, since as you have pointed out using the setAppData and getAppData methods restricts you to a string, and thus the dangers of name changes and duplicated naming conventions.

Is your weak reference technic applicable here? And as a custom Attribute to the root node I assume it would save with the scene? The artists here love that feature, since they can reload old files, and restart crashed files, and still access some nicely predetermined object lists for different isolation modes....

Thanks for the input :)

P.S Also cheers for the code example MoonDoggie, your string filtering code is a lot smoother than mine, so I have updated my clumsy version! Thanks! :)

11 November 2007, 02:35 PM
I would think that using CA defs would work well in this instance. I don't think that it would cause any slow downs of the scene. You have to remember that if you store a reference to a node then it becomes part of the scene hierarchy and can trigger updates to dependent nodes. Do lots of tests with lots of weak reference nodes added just to be sure. I would like to hear what you find out as well.

11 November 2007, 02:57 PM
Im on it. Ill get it set up, run some tests and let you know my findings. Thanks again for the support :)


11 November 2007, 03:26 PM
P.S Also cheers for the code example MoonDoggie, your string filtering code is a lot smoother than mine, so I have updated my clumsy version! Thanks! :)

Absolutely! And you're welcome.


CGTalk Moderation
11 November 2007, 03:26 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.