View Full Version : Converting String values to object names

07 July 2011, 05:19 PM
I am putting together a simple script that lists all current scene cameras into a drop down list which I have setup below.

However as I select the items from the drop down list I also want it to select the corresponding camera in the scene. Obviously the items are stored in the list as string values, how can I convert these into object names eg. Converting the format of "Camera01" into $Camera01.



CurrentCam = "NONE"

try(destroyDialog CamUtil)catch()

rollout CamUtil "Camera Match Utility" width:112 height:56
dropDownList ddl1 "Current Camera" pos:[10,8] width:100 height:10

fn getCams =
ddl1.items = sort (for c in cameras where (isKindOf c camera) collect

on ddl1 selected itm do
Currentcam = ddl1.selected
--select currentcam

on CamUtil open do
registerRedrawViewsCallback getCams

Createdialog CamUtil

07 July 2011, 05:48 PM
There are two options here:

You can use getNodeByName() to convert the string to the object you want to select, or store a separate array of cameras objects and index into it instead of converting names to objects.
But since you want to sort the names alphabetically, just use getNodeByName().

You can also add a test using isValidNode() to make sure the result of getNodeByName() is valid (for example if the camera was collected, but then deleted).

07 July 2011, 05:58 PM
Well 3 options as you could call:execute ("select $'"+currentcam+"'")However, read the help on where execute works best as there are cases where it can slow down execution.


EDIT: May help to wrap the cam name in ' ' for names containing spaces, etc.

07 July 2011, 09:18 AM
Thanks guys for your suggestions, very much appreciated!

CGTalk Moderation
07 July 2011, 09:18 AM
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.