PDA

View Full Version : Converting String values to object names


Riffmaster
07-05-2011, 06: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.

Thanks,

D.


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 c.name)
)

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

on CamUtil open do
(
getcams()
registerRedrawViewsCallback getCams
)
)

Createdialog CamUtil

Bobo
07-05-2011, 06: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).

PiXeL_MoNKeY
07-05-2011, 06: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.

-Eric

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

Riffmaster
07-07-2011, 10:18 AM
Thanks guys for your suggestions, very much appreciated!

CGTalk Moderation
07-07-2011, 10: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.