View Full Version : Unique variables
gzovkic 06-03-2009, 01:59 PM This is either incredibly simple, or incredibly stupid.
I'm working on a script in which I'll need to define a bunch of unique variables and store data to reference later.
That having been said, I'd like to use user-input strings to help define the name of the variable.
eg.
Prompt user to enter name: 'theName'
Declare a string variable called 'theName'
Simple? Silly?
Help's much appreciated.
|
|
ZeBoxx2
06-05-2009, 03:58 PM
you'll have to use execute()
rollout roll_test "roll_test" (
edittext edt_test "variable name:" text:"myVar"
spinner spn_test "variable value:"
button btn_show "output variable name and value"
on btn_show pressed do (
-- you'll want to test the text against other disallowed characters in variable names
-- this only makes sure it's not blank
if (edt_test.text != "") do (
execute (edt_test.text + " = " + (spn_test.value as string))
format "% = %\n" edt_test.text (execute edt_test.text)
)
)
)
createDialog roll_test
What is the purpose of letting the user define the variable names? There might be a more elegant solution to your problem.
scorpion007
06-06-2009, 10:01 AM
You probably want to use arrays to store variable amounts of user data. Variables are maxscript internals, and probably shouldn't be exposed to the user.
magicm
06-06-2009, 01:24 PM
An alternative to using the execute function is the globalVars structure (2008 or later):
globalVars.set <global var name> <value>
Martijn
ZeBoxx2
06-07-2009, 06:55 AM
An alternative to using the execute function is the globalVars structure (2008 or later):
globalVars.set <global var name> <value>
Martijn
Except that it's not...
The global variable name must exist, otherwise a runtime error will be generated
( The first line of the documentation is a bit misleading in that respect, as it claims that the globalVars structure also lets you create variables. )
You can use globalVars.get / globalVars.set after the first execute() to create the global variable, of course.
magicm
06-07-2009, 11:13 AM
( The first line of the documentation is a bit misleading in that respect, as it claims that the globalVars structure also lets you create variables. )
I should have tested that myself, but indeed it doesn't seem to let you create new vars.
Martijn
ZeBoxx2
06-07-2009, 12:35 PM
yeah, it's a bit odd.. almost seems like they simple forgot to add a .create() method; similar to how gamma used to be exposed... you could set display gamma, input gamma, output gamma, etc. etc. - everything except enable/disable gamma ;)
Either way, globalVars is a much more appropriate method once the variable has been created.
gzovkic
06-10-2009, 07:41 PM
Thanks for the responses everyone.
Yeah - I was -way- off on what I was trying to do. Any method which would have had user string defined variables is natively messed up :).
As suggested above (thanks!), I'm using an array to store some data now. I'm using persistent globals in order to keep the data associated with each maxfile.
If I create a new file, however, the data in the array remains, and doesn't clear. Is there any way to keep it empty / unique with each new max file?
ZeBoxx2
06-11-2009, 01:16 AM
only on file > new? Odds are you'd want it cleared when loading an existing file as well, no?
Anyway.. for file > new, it'll be similar to this:
callbacks.addScript #systemPreNew "yourVariableName = undefined" id:YourID
Place that in a .ms file and stick it in your startup scripts folder.
the reason I use 'pre' is so that the variable is cleared first. That way, if you choose to do the same for loading files later, if the scene does have the variable set it should still be okay once the file is actually loaded (#filePostOpen ; see the notes in the help file on distinguishing between a scene load and a preset load.. wouldn't want the latter to clear your variable)
gzovkic
06-11-2009, 01:24 PM
Ze - Thanks -so- much, exactly what I needed!
Moreover, thanks for your patience with my complete ignorance and less than ravenous exploration of the help file :).
ZeBoxx2
06-11-2009, 02:10 PM
no worries, we're all here to help
by the way, you might want to look into Custom Attributes. You can store these with a scene file as well, without having to worry about persistent globals.
The only 'problem' with them is that you can only store a limited set of types, and within each parameter only a single type. So an array of integers, an array of strings, etc. - but not an array with mixed integers and strings.
That would also prevent the need for that callback :)
gzovkic
06-11-2009, 02:35 PM
I'll definitely look into that. It's -super- simple data I'm storing for a simple animation management script. The last bit of it should export each chunk of timeline using the stored variables.. but I'm having a hell of a time figuring out yet another basic function.
Using the fbx exporter settings, then exporting the file. Can't seem to figure out how to get the fileExport line to use the settings from the fbx exporter lines. I -have- learned that it's not as simple as :
pluginManager.loadClass FBXEXP
fbxExporterSetParam "Cameras" true
fbxExporterSetParam "Lights" false
fbxExporterSetParam "GeomAsBone" true
fbxExporterSetParam "BakeAnimation" true
fbxExporterSetParam "UpAxis" "Y"
exportFile myFile.fbx #noprompt
Can't find much to clarify :S. I promise that's the last stupid question on this project
ZeBoxx2
06-11-2009, 03:36 PM
FbxExporterSetParam "Cameras" false
exportFile "c:\\nocameras.fbx" #noprompt
FbxExporterSetParam "Cameras" true
exportFile "c:\\cameras.fbx" #noprompt
seems to work for me - you shouldn't have to use the pluginManager; the plugin should be loaded already in a default max installation.
CGTalk Moderation
06-11-2009, 03:36 PM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.