getAppData - to identify nodes - problem

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 10 October 2007   #1
Question getAppData - to identify nodes - problem

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

Old 10 October 2007   #2
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)
-Colin Senner
3dsMax Scripts:

Last edited by MoonDoggie : 10 October 2007 at 07:38 PM.
Old 10 October 2007   #3
Red face

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
-Colin Senner
3dsMax Scripts:
Old 10 October 2007   #4
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.
Old 10 October 2007   #5
^ or you could do that.
-Colin Senner
3dsMax Scripts:
Old 11 November 2007   #6
Thumbs up Cheers Guys!


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!

Old 11 November 2007   #7
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.
Paul Neale
Old 11 November 2007   #8
Simple Isolation Tool

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!
Old 11 November 2007   #9
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.
Paul Neale
Old 11 November 2007   #10

Im on it. Ill get it set up, run some tests and let you know my findings. Thanks again for the support

Old 11 November 2007   #11
Quote: 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.

-Colin Senner
3dsMax Scripts:
Old 11 November 2007   #12
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 01:49 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.