Hi!
I tried to make a Save Presets script, but there is a problem with reading values from ini file.
Here the script:
(
me = getSourceFileName()
dir = getFilenamePath me
iniFile = dir + "mECSPV.ini"
global allSavedPresets = (readValue ((getINISetting iniFile "Presets" "names") as stringStream))
global edgeToCut=#(5, 16) as array
global eTc=#(0.05, 0.15) as array
rollout sp "Save Presets test"
(
button SaveP "Save Presets" pos:[42,7] width:79 height:21
button DelPrst "Del" pos:[120,7] width:79 height:21
dropdownList LoadPresets "" items:allSavedPresets pos:[13,33] items:#() width:185 height:(allSavedPresets.count+1) toolTip:"Load Presets"
on sp open do
(
global iniFile
me = getSourceFileName()
dir = getFilenamePath me
iniFile = dir + "mECSPV.ini"
/*
-- If this variable - allSavedPresets are defining here MaxListener return this error: Compile error: Undeclared variable: allSavedPresets
global allSavedPresets = (readValue ((getINISetting iniFile "Presets" "names") as stringStream)) */
)
on SaveP pressed do
(
rollout editTextSaveP "save Presets"
(
global presetName = undefined
editText prst_name "" bold:true
button SavePrst "Save"
on prst_name entered txt do
(
if txt != "" then
(
presetName = txt as string
print presetName
)
)
on SavePrst pressed do
(
if allSavedPresets.count !=0 then
store = allSavedPresets
else
store = #() as array
me = getSourceFileName()
dir = getFilenamePath me
iniFile = dir + "mECSPV.ini"
append store presetName
setIniSetting iniFile "Presets" "names" (store as string)
setIniSetting iniFile presetName "edgeToCut" (EdgeToCut as string)
setIniSetting iniFile presetName "eTc" (eTc as string)
allSavedPresets = (readValue ((getINISetting iniFile "Presets" "names") as stringStream))
LoadPresets.items = allSavedPresets
)
)
createdialog editTextSaveP modal:true
)
on LoadPresets selected itm do
(
me = getSourceFileName()
dir = getFilenamePath me
iniFile = dir + "mECSPV.ini"
edgeToCut = readValue ((getINISetting iniFile (itm as string) "edgeToCut") as stringStream)
eTc = readValue ((getINISetting iniFile (itm as string) "eTc") as stringStream)
-- print edgeToCut
)
on DelPrst pressed do
(
prstToDel = LoadPresets.selected
print prstToDel
)
)
createdialog SP width: 200
)
Here the INI file:
[Presets]
names=#("1", "2", "3", "preset", "preset01")
[1]
edgeToCut=#(68, 11, 33)
eTc=#(0.68, 0.11, 0.33)
[2]
edgeToCut=#(13, 84)
eTc=#(0.13, 0.84)
[3]
edgeToCut=#(1, 99)
eTc=#(0.01, 0.99)
[preset]
edgeToCut=#(1, 99, 50)
eTc=#(0.01, 0.99, 0.5)
[preset01]
edgeToCut=#(1, 99, 50)
eTc=#(0.01, 0.99, 0.5)
When i run the script and select from dropdownlist "1", "2" or "3" there is no problem. But if I select "preset01" or "preset" from dropdownlist MaxScript Listener show this error: MAXScript Rollout Handler Exception: -- Runtime error: Read past end of stream
If I use "Save Preset" button and save a new presets, and then select this new presets from dropdownlist, MaxScript Listener shows the same error: MAXScript Rollout Handler Exception: -- Runtime error: Read past end of stream
The second problem is with "on sp open do". IF allSavedPresets is declared here, MasXcript Listener show error: Compile error: Undeclared variable: allSavedPresets
Why this error occure?
P.S. Sory for may bad english.
Attachment contains .ms and .ini file.