[Closed] Setting environment values with strings
Hi,
I'm developing a script which stores and applies [rendersettings]( http://forums.cgsociety.org/showthread.php?f=98&t=839437). I'm storing my settingnames and values in an xml. These are always stored as strings. I get and set the values in the scene with getproperty and setproperty. An example:
re = renderers.current
strSetting = "filterMaps" --comes from an xml
strValue = "true" --comes from an xml
setproperty re strSetting (execute strValue)
Now i'd like to set environment values, such as the environmentmap or backgroundcolor. Again I've got the settingnames and values stored as strings in an xml. However I cannot find methods to apply my values to the environment-settings. How do I convert the string "[i]backgroundcolor[/i]" to the global system variable [i]backgroundcolor[/i]? Can this be done?
Can this be done?
Klaas
execute should do that.
execute <string>
[left]Compiles and evaluates the contents of the string as a MAXScript expression and returns the result of the evaluation.
backgroundcolor
(color 0 0 0)
execute "backgroundcolor"
(color 0 0 0)
-Eric
[/left]
Exactly, getting the values works fine with execute. But setting the values is something else. I’d like to do the following
backgroundcolor = (color 0 0 0)--this is the normal way to set that value
(execute "backgroundcolor") = (color 0 0 0)--this generates an error
Klaas
execute "backgroundcolor = color 0 0 0"
-- or
backgroundcolor = execute "color 0 0 0"
That is because you are using it wrong. (execute “backgroundcolor”) == (color 0 0 0). So in other words you are saying (color 0 0 0) = (color 0 0 0) as (execute “backgroundcolor”) returns the current value of background color. You need to create the full code as a string and execute that as denisT wrote. Another example if strValue is a string for instance “(color 0 0 0)”, then use:
execute ("Backgroundcolor = "+strValue)
-Eric
Thanks Denis and Eric,
that’s just what I was looking for. My next problem is about setting the environmentMap by using strings. This is what I have so far
i = 1 --the index of a material
execute ("environmentMap = currentmateriallibrary[" + (i as string) + "]")
This works fine, but I’m wondering if it’s possible to avoid the currentmateriallibrary and use a matlib loaded from loadTempMaterialLibrary. So
i = 1 --the index of a material
myLib = loadTempMaterialLibrary "somePath" --load a matlib
execute ("environmentMap = myLib[" (i as string) + "]")
This doesn’t work because the myLib-variable cannot be used as a string.
Though I’ve got a working solution, I’d like to beautify it.
Klaas
both your codes are not right. [b]Execute[/b] function executes string expression, so:
#1 has to be:
i = 1 --the index of a material
execute "environmentMap = currentmateriallibrary[i][i]"
[/i]#2 has to be:[i]
i = 1 --the index of a material
myLib = loadTempMaterialLibrary "somePath" --load a matlib
execute "environmentMap = myLib[i]"
[/i]but [i]execute “environmentMap = myLib” is exactly same as [i]environmentMap = myLib and you don’t have to use execute at all.
Note that Execute() operates in Global scope. So as long as myLib is global, it should work if expressed correctly. If myLib is declared as local or is implicitly local due to living in a local scope, it would not be visible to the Execute call.
Bobo is absolutely right. All variables in execute expression has to be Global.
Damn, I should have read the doc too, struggled with it for some time…