ScriptSpot

Forum topic · General Scripting

More value Spinner in a Loop

By Michele71 · 2013-09-18

Description

Hello man!

I have a curiosity:

I have 3 spinner named Spinner1, Spinner2 and Spinner3 and they control three parameters.

I have this loop (for example)


for i in scenematerial do (temp = spinner[i].value print temp)

it's possible "pass" the [i] for all three parameters of the spinner?

If possible How do? Contrariwise there is another solution?

Thanks for any help :)

Comments (8)

barigazy · 2013-09-18

'i' in your example is not a number but material.


for i = 1 to scenematerial.count do print (spinner[i].value)

This will throw error if scenematerial.count > number of spinners
Be more specific. What's represent spinners value, which parameter?

Michele71 · 2013-09-18

Thanks for you reply Barigazy :)

Yes you have right :) I'm confused!! but still wanted to be a simple example :)

The concept is this:

I have write a script that controls the parameters "Blur" in the any material in VRay.
Now, I have more of the 53 spinner (spnBlur1, spnBlur2, spnBlur3, ...) with related controls
I must write in a .text file, the value of each spinner control then, the values ​​of material "Blur".

There is a method to write a loop that allows me to do this?

thanks in advance :D

barigazy · 2013-09-18

This is very easy using .net
Just be sure that your rollout is open and name of rollout is stored in global variable.
You can do this simply adding this line at the top of your code


try(destroyDialog ::roll)cache()

Next we need to define some .net classes

dnSW = dotNetClass "System.IO.StreamWriter"
dnFile = dotnetClass "System.IO.File"
myTxt = dotNetObject dnSW (dnFile.Create @"c:\Users\Public\Documents\WriteText.txt") --change filename for your case
for c in roll.controls do -- i used "roll" for rollout
(
if isKindOf c SpinnerControl and MatchPattern c.name pattern:"spnBlur*" do myTxt.WriteLine (c.value as string)
)
myTxt.Close() ; myTxt.Dispose()
-- next line is only if you want to see saved file in mxs editor
edit @"c:\Users\Public\Documents\WriteText.txt"

barigazy · 2013-09-18

Or as function

fn storeRollSpnValuesToTxt roll ctrlClass: patt: txtFileName: =
(
local dnSW = dotNetClass "System.IO.StreamWriter"
local dnFile = dotnetClass "System.IO.File"
local myTxt = dotNetObject dnSW (dnFile.Create txtFileName)
for c in roll.controls where (isKindOf c ctrlClass and MatchPattern c.name pattern:patt) do myTxt.WriteLine (c.value as string)
myTxt.Close() ; myTxt.Dispose() ; gc light:on ; txtFileName
)
storeRollSpnValuesToTxt someRollout ctrlClass:SpinnerControl patt:"spnBlur*" txtFileName:@"c:\Users\Public\Documents\blurValues.txt

Michele71 · 2013-09-18

Many thanks barigazy :) This Function is VERY helpful ;) double-inch!!! :D

barigazy · 2013-09-18

Probably next question will be how to read back theses values or how .net "StrimReader" works.:) While back I created simple TextEditor where I used same methods.

Michele71 · 2013-09-18

Hahahaahah Probably so, but for now this is already a lot! :D If I have a problem with .Net I make a whistle! hahahahah

Thanks Again :)

Michele71 · 2013-09-18

WoW!! Hahahahah thank you barigazy !! it works!!!! hahahahha :)

Unfortunately I have never used .Net :(
Your solution for me is a big help and certainly a starting point to begin to study the .net :)

Thank Again barigazy! 1000+ point! :D