Reading from INI file

How do I read the information from an ini file.
Example - The ini file is filled with notes and I want those notes to display in an edittext field as written in the ini file with spacing, numbers, letters, and separate lines if paragraphed as in the ini file.

edittext edtxtInfo "" fieldWidth:242 height:200  text:MyInfo pos:[0,4]
MyInfo = GetINISetting "C:Desktop\trash\testingINI\Info.ini
<code>

Comments

Comment viewing options

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

Shortly to say - all argument

Shortly to say - all argument to both get and set ini settings functions are strings --
GetINISetting "c:/fun.ini" "SectionName" "KeyName"
If you call the function to not existing file, or the section (or it key) is not found, the GetINISetting just return an empty string. Here is a test...

-- create and set new ini file
setINISetting "c:/fun.ini" "Character1" "Name" "Homer Simpson"
setINISetting "c:/fun.ini" "Character1" "Weight" "150"
setINISetting "c:/fun.ini" "Character2" "Name" "Bart Simpson"
setINISetting "c:/fun.ini" "Character2" "Weight" "60"
 
-- the ini file content:
[Character1]
Name=Homer Simpson
Weight=150
[Character2]
Name=Bart Simpson
Weight=60

Although there are duplicate key names is stll a valid ini file, because this keys are in separate sections. Also no need Create/Open/Close for ini's, nor yet Find/Replace. Cool, ya :)

-- read the ini file:
getINISetting "c:/fun.ini" "Character1" "Name"
getINISetting "c:/fun.ini" "Character1" "Weight"

Also you can explore the ini file content (if needed) :) (very useful feature)

-- get the section names...
getINISetting "c:/fun.ini" -->> #("Character1", "Character2")
-- get the key names in "Character1"
getINISetting "c:/fun.ini" "Character1" -->> #("Name", "Weight")

Well, if the ini was allows nested tree (as xml) would be the best format ever :))

hope this help

my recent MAXScripts RSS (archive here)

Budi G's picture

MyInfo = GetINISetting

MyInfo = GetINISetting "C:Desktop\trash\testingINI\Info.ini"

you should pay attention a slash, to ensure such:

MyInfo = GetINISetting "C:\Desktop\trash\testingINI\Info.ini" "dir" "subdir"

or by "\\"

or by "/"

or by "//"

about the ""(a double quote in string) of "dir"(is section_string) "subdir"(is key_string ) that is example contents data in file.ini.
you can check in mxscript reference about that.

reading in file.INI contents like:

[dir]
subdir=#($box01,$box02)

and that's like memory of 2 box objects in file.INI...

so do you understand it ? :)

toddfx's picture

Syntax

I am trying to save animationRange.end to an ini file, but cannot get the syntax correct for saving content data.

I have searched in the MAXScript reference but have been unable to put together the functional code.

Can you elaborate on the "double quote in string" bit you mentioned? Thank you so much!

Anubis's picture

what so unclear?

all parameters in both functions (getINISetting and setINISetting) are strings:

setINISetting "c:/test.ini" "AnimationRange" "start" (animationRange.start as string)
setINISetting "c:/test.ini" "AnimationRange" "end" (animationRange.end as string)

this example code will create a ini file (c:\test.ini) with this contents:

[AnimationRange]
start=0f
end=100f

my recent MAXScripts RSS (archive here)

Comment viewing options

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