PDA

View Full Version : Converting string to object pathName


Jon Huhn
10-25-2005, 08:28 AM
Well, looks like I did it again. Right after I posted this question, I thought of a different set of search strings to use while searching here on the forum, and found the answer to my question here http://forums.cgsociety.org/showthread.php?t=153527 .

I do think this topic should be more explicitly addressed in the Maxscript reference under the pathName topic, but instead it's addressed in the Frequenty Aked Questions section. Oh well.

He's my original post:


Seems like this should be easy, but I can't figure it out or find the answer in the Maxscript reference or here in the CGTalk forums.

How can I convert the string "$box01" to a valid pathName that points to the object $box01 ?

Thanks!

salmonmoose
10-25-2005, 08:41 AM
select (getNodeByName objectNameString)

Jon Huhn
10-25-2005, 09:21 AM
Thanks, Anton, but I went with the execute() function instead (of which I knew nothing about until I researched this problem!) since I needed to grab a collection, and not just a single item.

salmonmoose
10-25-2005, 09:25 AM
objectArray = #()
for objName in objNameArray do
(
append objectArray (getNodeByName objName)
)
select objectArray



Just by theory, think this works :)

just in case you want to expand your script, it'll probably be easier with 'real' code :)

Bobo
10-25-2005, 01:25 PM
objectArray = #()
for objName in objNameArray do
(
append objectArray (getNodeByName objName)
)
select objectArray



Just by theory, think this works :)

just in case you want to expand your script, it'll probably be easier with 'real' code :)

MAXScript is expression-based. Use it as such - saves time and typing! :)

select(objectArray = for o in objNameArray collect getNodeByName o)

This gives you both the new array of paths AND selects the nodes in the scene. You might want to check for invalid (deleted) nodes though:

select(objectArray = for o in objNameArray where isValidNode (theObj = getNodeByName o) collect theObj)

salmonmoose
10-25-2005, 11:46 PM
Show off ;)

Yeah, my code is possibly poorly written, it's what comes of having learnt a half dozen programming languages.

CGTalk Moderation
10-25-2005, 11:46 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.