Notifications
Clear all

[Closed] Converting string to object pathName

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!

5 Replies

select (getNodeByName objectNameString)

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.


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)

Show off

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