PDA

View Full Version : Objects as variables and global strings


cgbeige
12-03-2011, 08:10 PM
I'm making a script that creates a temp setup of meshes and lights on a render layer and I want to have a button from the scriPt window delete everything on completion. How do you store these new objects as variables to be deleted later? If I try and set global string $meshTemp = `polySphere`;, I get an error since it's not a constant static string

NaughtyNathan
12-03-2011, 09:33 PM
just initialise the global first then set it:
global string $tempMesh;
$tempMesh = `polySphere`;although bear in mind that `polySphere` returns an ARRAY, so somthing like:
global string $tempMesh;
string $result[] = `polySphere`;
$tempMesh = $result[0];may be more appropriate anyway.
I can't tell exactly what you're doing from your description, but depending on the number of objects you need to store, maybe a Maya set would be better than loads of global vars?
:nathaN

cgbeige
12-03-2011, 10:27 PM
awesome - that works. thanks. It's just a few objects so the global vars are fine since there aren't many

Azrail
12-04-2011, 07:52 AM
Why don't you use optionVars or fileInfo? This way the values will be stored in the file itself, or the prefs, and you can get them later even after restarting maya. If it's just names you are storing you can always use the stringArrayToString-stringToStringArray to store/retrieve the data in a single option.

CGTalk Moderation
12-04-2011, 07:52 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.