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.
barigazy's picture

...

*.Ini is good solution to store this kind of params. But XML is much fester,
especially when you use XPath method for reading XML doc.
Maybe you already know for this site.
XML examples
http://www.w3schools.com/xml/
XPath examples
http://www.w3schools.com/xpath/

barigazy

barigazy's picture
pixamoon's picture

`

wow, great examples and tutorials lol, thank you !

I would say .ini is good for just few values to save / load (because easy single lines to get and set values in code)
And for larger amount settings /data -> definitely faster XML !

What you think ?

barigazy's picture

...

that's right

;)

barigazy

pixamoon's picture

`

:)

Thank you again for XML examples... I still need to learn this, I have few ideas where to use it, but didn't have time to learn it. Now will be very easy.

Thank you !

pixamoon's picture

`

ah, and the last thing I saw somewhere to convert string to Poin3 but it works with color too!

a = execute "(color 10 10 10)"
a = execute "[10,10,10]"

then it can be much easier to get color form your text file:

(
	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 (
			"Reflection": ( if strArr[i+1] == "Color:" then RefColor = execute (strArr[i+2] + " " + strArr[i+3] + " " + strArr[i+4] + " " + strArr[i+5]) )
		)
	)
)
print RefColor

But if you have ini file it will be so easy to convert string "(color 10 10 10)" to color value.
Sorry I forgot about it yesterday.
Best,

pixamoon's picture

`

and even better:

this is what I found in maxscript help about execute
readExpr <filestream> and execute <filestream>

maxscript sample:

s=stringstream "random 0. 1.;random red blue"
readvalue s -- read and evaluate the first value
readvalue s -- read and evaluate the second value
seek s 0 -- position at beginning of stringstream
readexpr s -- read and evaluate the first expression
readexpr s -- read and evaluate the second expression
seek s 0 -- position at beginning of stringstream
execute s -- evaluate all expressions

and this should be very easy to read from txt file :)

barigazy's picture

...

Also to store some data of any tool (read/write) the best and fastest way will be XML.

barigazy

barigazy's picture

...

Yup. Can be done with .net but ...

test = "Max Distance FallOff: 2.0"
fn extractValue string asFloat:on nums:"1234567890." =
(
	name = trimright (trimleft string nums) nums
	string = substituteString string name ""
	if asFloat then string as float else string
)
extractValue test

barigazy

Michele71's picture

Thanks barigazy, I try your

Thanks barigazy, I try your function :)

At this point I agree with you as regards the format xml....

Thanks Again!!

Comment viewing options

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