[Closed] Converting String values to object names
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
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).
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.