Converting String values to object names

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  07 July 2011
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.



  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
"i'd rather have a full bottle in front of me than a full frontal lobotomy"
  07 July 2011
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
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.
"The Evil Monkey hiding in your closet."
  07 July 2011
Thanks guys for your suggestions, very much appreciated!
"i'd rather have a full bottle in front of me than a full frontal lobotomy"
  07 July 2011
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 10:15 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.