isolate number from format string with quote ""

Hi all :)

They are the last details of my script (Environment Lighting HDR Studio (MR) ) but now I've a problem that I can not solve...

I want to enter parameters in rollut taking them from a txt file, but the info in file txt are written as Reflections (Subactive Color): (color 255 255 255) or Glossines: 8.0 ecc.. Now I know this form to isolate number from string array:

test = "Max Distance FallOff: 2.0"
strArr = filterString test " "
valuespinner = strArr[4] as float
print valuespinner

but I can not transfer ONLY values in rollout, because I always error of various kinds (!)
If I try with "openFile" and "readValue", (for read the file txt) I've always the result, for example, "scale()", but never specific value. I had no trouble writing values to and from .txt, but now I can not do this..

The question is very simple: How isolate a number from a string with quote "" and restore the values of spinner etc. the rollout reading a file .txt?

Any help is very important to me :D

Thanks
Michele71

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pixamoon's picture

`

why not go with loop and case (of course after filtering)

so if you have strArr array:

for i in strArr.count do (
	case strArr[i] of (
		"Glossines:":(glossines = strArr[i+1] as float)
		"GlossySample:":(glossyS = strArr[i+1] as float)
		--- etc
	)
)

just an idea.
value is always next after name
and "Glossines:" u have probably as a rollout elements .text

It doesn't work for color but than you can do
(color (strArr[i+2] as float) (strArr[i+3] as float) (strArr[i+4] as float))

ah but u need to have written in file "Glossy_Sample" instead of "Glossy Sample"
or remove spaces before writing so you get "GlossySample"

Michele71's picture

Thanks pixamoon :) Before

Thanks pixamoon :)

Before posting my question, I have tried a simil loop, but without success. Now I perform also your advice and see what appears!

Thanks for your patience and response :)

pixamoon's picture

sure

thats the 1st way (loop every line to get values):

(
	local csvFile = "C:\\renderpreview_0004.txt"
	local adata = (dotnetClass "System.IO.File").ReadAllLines csvFile
 
	for i = 1 to adata.count do 
	try(
		pInfo = (filterString adata[i] " ")
		case pInfo[1] of (
			"Glossines:":glossines = pInfo[2] as float
 
		)
	)
	catch(print ("Error in line: " + i as string))
)
 
print glossines

and this is 2nd (append all single words to one array and than loop it and search for values)

(
	local csvFile = "C:\\renderpreview_0004.txt"
	local adata = (dotnetClass "System.IO.File").ReadAllLines csvFile
	local strArr = #()
 
	for i = 1 to adata.count do (
		pInfo = (filterString adata[i] " ")
		for o in pInfo do append strArr o
	)
 
	for i = 1 to strArr.count do (
		case strArr[i] of (
			"Glossines:":glossines = strArr[i+1] as float
 
		)
	)
)
 
print glossines

Of course you need single words, like "Glossines:", "GlossySample" etc

What you think ?

Michele71's picture

Yea, I'm doing the tests, but

Yea, I'm doing the tests, but I think the concept is right ;) I try to do the tests then I'll know!

thanks again!!!!

pixamoon's picture

reading form txt

I think dotnet methods will help

Maybe this will help. Take a look on http://www.scriptspot.com/3ds-max/scripts/read-data-from-csv-txt

the quote there is "|" but you can easily change to other quote I think.
Best,

Michele71's picture

Yes pixamoon, I have already

Yes pixamoon, I have already read that discussion, but I was not help ... I thank you anyway for your attention and response :)

pixamoon's picture

`

I'm bit not sure how and which values you want to get from txt file.
I dont understand where you get "scale()" etc. instead of value...
Can you post or send me part of this txt file ? [email protected]

Michele71's picture

Sure! I attach here the file

Sure! I attach here the file exemple file .txt

What is on in rollout is printed in the .txt file, so not everything is written (plese see Environment Lighting HDR Studio (MR) to understand the working). The value to get from .txt is  number and true or false (to send in spinner rollout ecc).

AttachmentSize
renderpreview_0004.txt 760 bytes

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.