[SOLVED] Playing with 2 dialogs [one main and one for editing variables]

-- Messing with \ and \\ -- [SOLVED] But another question at the bottom

Hi there, this is my first post here, and i'm a beginner in maxscript, and scripting in general.

I'm currently improving my script so it can store configuration file, and use them as variables.

I have several problem which i can't solve on my own, and, as a French young man, my english is not good enough to understand the all Maxscript Help File.

I'm Asking for help :)

So i learn there is scope things to access variables in different loop, and it's a bit hazy for me. I think It's on problem i have in my script, but first, i have a problem when edit my .ini file:

>> I must store a Network Path into my Ini File, but i just notice that the function "SetINISetting" simply ignore multiple backslash:

in my functions.ms file:

setINISetting theoutput "folders" "dossier_portes_ini" "\\\\Averty\\v\\Oskab\\scenes\\_portes\\"
setINISetting theoutput "folders" "dossier_render_ini" "\\\\Averty\\v\\Oskab\\scenes\\__RENDER\\"

in my .ini file i get:

[folders]
dossier_portes_ini=\\Averty\v\Oskab\scenes\_portes\
dossier_render_ini=\\Averty\v\Oskab\scenes\__RENDER\

But when I re-use my editvar rollout and manually type the good path,I get the good one... This is a mystery for me...

I need this function to work, because it's the defaults settings, overriding the one missing, or use as default if no modification are made.

Thanks in advance for reading me, and a thousand thanks for trying to help.

-- EDIT --

I'll try to be clear explaining this one !

First, i had only one roullout "main", opening when starting the script with everything in It, it worked well, but i like challenge and for further use, i wanted it to be editable.

So, now i have 3 files; main.ms, functions.ms and editvar.ms

main call editvar.ms by pressing a button, and when editvar close, it store all information into a temp.ini so i can access to my variables easily into main.ms

My problem is that when main start, it create a dropdownlist by parsing a folder, which can be modified by the second rollout.

since the dropdownlist is created when the first roullout is called, when i close my edit var, i don't find a way to update it (i tried "on close" but when i call it in the main script, it's gone since a long time and it does nothing)

So, for now, i close everything and launch the script again... not very handy !
Main:
http://my.jetscreenshot.com/8140/20130907-p6qh-26kb.jpg
EditVar:
http://my.jetscreenshot.com/8140/20130907-qazg-78kb.jpg

Thanks Again for helping me :)

[EDIT 2013/09/04]
-------------------------------------------
Some Handy Functions I use In this script:

1) LISTNG FILES: Create a list of files To put in a DropdownList / ListBox / MultiListBox: Arguments: Directory (path to folder) / Extension (ex: "max") / Extensionlength: number of character in Extension (ex: 3) / directorylengtplus = 1 for network path (UNC) or 2 for classic path (C:\\...) [ I use one Checkbox for It] / the dropdownlist: name of the object UI.

fn listingfiles directory extension extensionlength directorylenghtplus thedropdownlist =
	(	
	listeporte = getfiles (directory + "\*." + extension)
		/*Creating 2 empty arrays 
		listetemp holds thefilename + extension
		liste holds filename without the extension.*/	
		liste = #()
		listetemp = #()
		for a = 1 to listeporte.count do
			(
			directorylenght = directory.count
			listetemp [a] = Substring listeporte[a] (directorylenght +directorylenghtplus) 100
			counttemp = listetemp [a].count
			liste [a] = Substring listetemp [a] 1 (counttemp - (extensionlength+1))
			)	
		for a = 1 to liste.count do
			(	  
			thedropdownlist.items = append thedropdownlist.items (liste[a] as string)
			)
 
	)

2) Bdigit nb: Return a number value into a String with 4 digits:

fn bdigit nb = 
		(
			tostring = nb as string
			countstring = tostring.count
			if countstring == 4 then result =  tostring 
			if countstring == 3 then result =  ("0" + tostring) 
			if countstring == 2 then result = ("00" + tostring)
			if countstring == 1 then result = ("000" + tostring) 
			return (result)
		)

Comments

Comment viewing options

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

And.. one More Problem !

Thanks for your good advises, i didn't use struct for now, but it's look very nice, and i surely use them into my next script :)

I've got a little problem, which i don't understand, maybe because it's 5am here, and i don't manage to find a solution.

It's quite funny because it's working in a 2 lines script but not in the real one.

When i was working on the script, i made my path point to my desktop in an absolute path, and the script worked well. But when i made the mzp, and made the include point to function.ms by using userscript...

when i try this:

global inidir = getdir #userscripts + "\\OSKAB"
include (inidir + "\\functions.ms")

the listener is parsing the entire file, so i assume he found it, but in my main script it crashed.

try(DestroyDialog main)catch()
-- GLOBAL VARS
global inidir = getdir #userscripts + "\\OSKAB"
global functions = inidir + "\\functions.ms"
global tempini = inidir + "\\_temp.ini"
global oskabini = inidir + "\\oskab.ini"
-- END VARS
 
 
-- STARTING HERE
if (doesFileExist tempini) == true then
(
	if queryBox ("Souhaitez vous utiliser les derniers Settings ? \n (l'edition des paramètres ne sera pas disponible)") title:"Veuillez confirmer votre choix" beep:true then
	(
	global uselastsettings = 1
	)
	else
	(
	global uselastsettings = 0
	)
)
else
(
	if (doesFileExist oskabini) == false then
	(
	include functions.ms 
	createoskabini()
	)
	print "no temp.ini, creating one"
	copyfile oskabini tempini
)

ps: it's working when I enter the all path in absolute of course, but it's not the point of creating a mzp-file to deploy on several computers.

barigazy's picture

...

You can't use line include functions.ms. Max not recognize this. Now is the time to place all your fn's in struct. And your problem will disappear

bga

locke's picture

-Loosing It-

Tell me if i'm wrong, but when i use Struct to organize my functions.ms file, i will always have to include the function.ms file into my main.ms right?

I'm looking all over the web to find examples, but i found contradictory information. example: "don"t use include but file fileIn" Or "Omg you're using Filein, just use include !"

I'm confused

Here: http://neiltech.wordpress.com/2012/11/16/how-to-create-a-class-in-maxscr...
>> I understand the goal of using Struct, because we have 2 functions in the struct MyClass , executed by calling one Struct "MyClass"

But in my case, functions.ms is just a bunch of functions, and using Struct could organize them by type (Ini things / main script), but i don't understand the point.

Here's my functions:

--Functions:
 
--MENU INI--
----------
--Save Ini
fn saveini thedir theoutputfile =
(
)
 
--Load Ini
fn loadini thedir theimputfile =
(
)
 
-- create Oskab.ini
fn createoskabini =
(
)
 
 
-- Clear All
fn cleareditvar =
(
)
 
--OSKAB TOOL
--Load tempini
fn loadtempini theparam theparamcategory =
(
)
--/MENU INI --
 
 
-- Lister des fichiers dans un dossier et les ajouter à une dropdownlist
--directorylenghtplus = 1 si network path, 2 sinon
fn listingfiles directory extension extensionlength directorylenghtplus thedropdownlist =
(	
)
 
-- bdigit d'un nombre: convertir un nombre en paddin XXXX (exemple: 1 -> 0001) ------return: string
 
fn bdigit nb = 
(
)
 
--Nom de la porte correspondant au proxy (manipulation chaine de caracteres)
fn getportename prox =
(
)
 
--Assign le material d'"obj_shader_name" au layers correspondant a findthelayers
fn assignmattolayer obj_shader_name findthelayers =
(	
)
barigazy's picture

...

No no. Place all fn's from "function.ms" inside struct. But struct neet to be placed in main.ms. Forget about fileIn and include fn's.

bga

locke's picture

Can't find editText.text

Hi there, i'm stuck again.

I put all my function into my main script, into one sturct called "Myfunctions"

I initialize it before i declare my 2 rollouts.

The functions used by the main works just fine, but inside the settings rollout, the functions using the ".text" parameters of the edittext UI is not found by maxscript, and so i can't load or save new Ini...

I give you a piece of my code as exemple, into EDITVAR ROLLOUT (L103),I have several edittext exmple: "In1"

Into my save and load ini functions (L6 & L15) i use the .text parameters to get or assign a stringvalue, but max can"t find the .text parameters now. Is this a scope problem? I thought my functions are available anywhere in my code by using a global initialization of the struct...

I tried to get or assign a value directly from the rollout, not calling a pre-build function, it worked.

So my question is how can i do to make the.text parameters available into my function?

Thanks in advance,

Florent

AttachmentSize
example.ms 2.09 KB
barigazy's picture

...

This is the corrected code. I did not tested, but you can.
Read my "upercase" comments.
Also look how I initialized struct.

struct MyFunctionsStruct
(
	inidir = (getdir #userscripts + "\\Tool"),
	tempini = (inidir + "\\_temp.ini"),
	toolini = (inidir + "\\Tool.ini"),
	fn saveini thedir theoutputfile ctrl = -- ADD "CTRL" ARGUMENT POR YOUR ROLLOUT CONTROL EI.EDITTEXT
	(
		GetINISetting thedir "SectionName" "KeyName" -- WHY THIS LINE IS NOT STORED IN SOME VARIABLE
		-- create and set new ini file
		setINISetting theoutputfile "Usefull_Frames" "in1_ini" ctrl.text
	),
	--Load Ini
	fn loadini thedir theimputfile ctrl = (ctrl.text = getINISetting theimputfile "Usefull_Frames" "in1_ini"),
	-- create Tool.ini
	fn createToolini =
	(
		local inidir = getdir #userscripts + "\\Tool"
		local nameini = "Tool.ini"
		local theoutput = inidir + "\\" + nameini
		GetINISetting inidir "SectionName" "KeyName" -- WHY THIS LINE IS NOT STORED IN SOME VARIABLE
		-- create and set Tool ini file
		setINISetting theoutput "Usefull_Frames" "in1_ini" "1"
	),
	-- Clear All
	fn cleareditvar ctrl = (ctrl.text = ""),
	--Load tempini
	-- Load a parameter into the main funciton, get default if no one found
	fn loadtempini theparam theparamcategory =
	(
		local theparamini = theparam + "_ini"
		local testtemp = getINISetting tempini theparamcategory theparamini
		theparam = (if testtemp.count == 0 then (getINISetting Toolini theparamcategory theparamini) else testtemp)
	),
	-- Lister des fichiers dans un dossier et les ajouter à une dropdownlist
	--directorylenghtplus = 1 si network path, 2 sinon
	fn listingfiles directory extension extensionlength directorylenghtplus thedropdownlist = (),
	-- bdigit d'un nombre: convertir un nombre en paddin XXXX (exemple: 1 -> 0001) return: string
	fn bdigit nb = (),
	fn getportename prox = (),
	--Assign le material d'"obj_shader_name" au layers correspondant a findthelayers
	fn assignmattolayer obj_shader_name findthelayers =()
)
global MyFn = MyFunctionsStruct()
--END FUNCTIONS
try(DestroyDialog ::main)catch()
if (doesFileExist MyFn.tempini) == true then () else ()
-- EDITVAR ROLLOUT
rollout editvar "Tool Settings " width:250 height:550
(
)
-- MAIN ROLLOUT
rollout main "Tool - Create" width:250 height:200
(
)
createDialog main 250 125 

bga

locke's picture

I think i'm getting in but

Hi there, sorry for the late response, i didn't have time too look at the code yesterday. Youre code is working great but in my case (i didn't tell you all so you were unable to know, but i have about 70 Edittext or check box to load, save or clear.

At the first time, i wanted to save, load or clear all of them by calling one short function for each action into my rollouts

It work when adding the ctrl parameters, but i have to call the function 70 times. Although, i have different type, check-boxes ant EditText, so i cant use the same syntax when i want to get the.text value or the TriState. It's the same problem when i load or save, i have different group in the Ini, different types of values, etc.

I Give you an example with the clear function:

>>With the struct and calling 70 times:

--STRUCT
fn cleareditvar ctrl type = 
	(
	if type == "text" then
		(
		ctrl.text = ""
		)
	if type == "tristate" then
		(
		ctrl.triState = 0
		)
	)
--ROULLOUT
on clearall pressed do
	(
	MyFn.cleareditvar dossier_portes "text"
	MyFn.cleareditvar dossier_render "text"
	MyFn.cleareditvar unc_render "tristate"
	MyFn.cleareditvar unc_portes "tristate"
	MyFn.cleareditvar thelayerproxy "text"
	MyFn.cleareditvar findthelayers "text"
	MyFn.cleareditvar prefixrenderscenename "text"
	MyFn.cleareditvar prefixoutputfichier "text"
	MyFn.cleareditvar renderframes "text"
	MyFn.cleareditvar refletbrillant "text"
	MyFn.cleareditvar refletsatine "text"
	MyFn.cleareditvar in1 "text"
	MyFn.cleareditvar out1"text"
	MyFn.cleareditvar master1 "text"
	MyFn.cleareditvar in2 "text"
	MyFn.cleareditvar out2 "text"
	MyFn.cleareditvar master2 "text"
	MyFn.cleareditvar in3 "text"
	MyFn.cleareditvar out3 "text"
	MyFn.cleareditvar master3 "text"
	MyFn.cleareditvar in4 "text"
	MyFn.cleareditvar out4 "text"
	MyFn.cleareditvar master4 "text"
	MyFn.cleareditvar in5 "text"
	MyFn.cleareditvar out5 "text"
	MyFn.cleareditvar master5 "text"
	MyFn.cleareditvar in6 "text"
	MyFn.cleareditvar out6 "text"
	MyFn.cleareditvar master6 "text"
	MyFn.cleareditvar in7 "text"
	MyFn.cleareditvar out7 "text"
	MyFn.cleareditvar master7 "text"
	MyFn.cleareditvar in8 "text"
	MyFn.cleareditvar out8 "text"
	MyFn.cleareditvar master8 "text"
	MyFn.cleareditvar in9 "text"
	MyFn.cleareditvar out9 "text"
	MyFn.cleareditvar master9 "text"
	MyFn.cleareditvar in10 "text"
	MyFn.cleareditvar out10 "text"
	MyFn.cleareditvar master10 "text"
	MyFn.cleareditvar in11 "text"
	MyFn.cleareditvar out11 "text"
	MyFn.cleareditvar master11 "text"
	MyFn.cleareditvar in12 "text"
	MyFn.cleareditvar out12 "text"
	MyFn.cleareditvar master12 "text"
	MyFn.cleareditvar in13 "text"
	MyFn.cleareditvar out13 "text"
	MyFn.cleareditvar master13 "text"
	MyFn.cleareditvar in14 "text"
	MyFn.cleareditvar out14 "text"
	MyFn.cleareditvar master14 "text"
	MyFn.cleareditvar in15 "text"
	MyFn.cleareditvar out15 "text"
	MyFn.cleareditvar master15 "text"
	MyFn.cleareditvar in16 "text"
	MyFn.cleareditvar out16 "text"
	MyFn.cleareditvar master16 "text"
	MyFn.cleareditvar in17 "text"
	MyFn.cleareditvar out17 "text"
	MyFn.cleareditvar master17 "text"
	MyFn.cleareditvar typestart "text"
	MyFn.cleareditvar typeend "text"
	)

I don't which solution is the more efficient, because in 3 case (loading / saving and clear) each time i want to do one action i call one function In struct 70 times

In that case, i can't call the fucntion insode another rollout thant the one where the fucntion is declare... not handy, but i can cear all of my parameters in one line into mu editvar Roullout:

-- ROULLOUT
-- Clear All
fn cleareditvar =
(
dossier_portes.text = ""
dossier_render.text = ""
unc_render.triState = 0
unc_portes.triState = 0
thelayerproxy.text = ""
findthelayers.text = ""
prefixrenderscenename.text = ""
prefixoutputfichier.text = ""
renderframes.text = ""
refletbrillant.text = ""
refletsatine.text = ""
in1.text = ""
out1.text = ""
master1.text = ""
in2.text = ""
out2.text = ""
master2.text = ""
in3.text = ""
out3.text = ""
master3.text = ""
in4.text = ""
out4.text = ""
master4.text = ""
in5.text = ""
out5.text = ""
master5.text = ""
in6.text = ""
out6.text = ""
master6.text = ""
in7.text = ""
out7.text = ""
master7.text = ""
in8.text = ""
out8.text = ""
master8.text = ""
in9.text = ""
out9.text = ""
master9.text = ""
in10.text = ""
out10.text = ""
master10.text = ""
in11.text = ""
out11.text = ""
master11.text = ""
in12.text = ""
out12.text = ""
master12.text = ""
in13.text = ""
out13.text = ""
master13.text = ""
in14.text = ""
out14.text = ""
master14.text = ""
in15.text = ""
out15.text = ""
master15.text = ""
in16.text = ""
out16.text = ""
master16.text = ""
in17.text = ""
out17.text = ""
master17.text = ""
typestart.text = ""
typeend.text  = ""
)
 
 
on clearall pressed do
	(
		cleareditvar ()
	)

I tried several thing (don't forget i'm starting, i'm sure it will look strange for you)
>> print the edittext directly and save it to a .ini: : i get "EditTextControl:"

>> but i heard that i have to avoid the execute function for "converting" a string to get the variable with the same name:

exemple:

in1 = "TOTO"
...
in40 = "HELLO"
 
for i = 1 to 40 do
(
checkin = "in" + i as string
resultin = execute checkin
)

It can loop for X Variable, but it's very slow, and dirty... and i have still other Edittext who can"t enter in this loop...

I tried a few things, but except crashing the script it's not helpfull.

Can i declare Struct int Struct ? so i could store all my parameters and execute them 70 time by calling another struct parameter ?

exemple: Struct theparams (in1, in2 ... in40,checkbox1...)

So i can call cleareditvar for each params in the same time...

I'm Trying, I didn't count the Google researches about scripting or optimize in the way I want, there's no many article about struct...

Thanks For your time, at worst i can copy/paste the all dirty code into my script, i know it will work, but i'll not be satisfied about it.

barigazy's picture

...

I not have time right now to read your post but see this example
"main" is your rollout and you can simply loop and affect only edittex controls like this

for c in main.controls where classof c == EditTextControl do
(
		-- to collect all text
		textArr = #()
		append textArr c.text
		-- to remove text
		c.text = ""
		-- to collect all names of edittext controls
		namesArr = #()
		append namesArr c.controls[1].caption
--etc.
)

bga

barigazy's picture

...

You can test with this example

try(destroyDialog ::main)catch()
rollout main "• • •"
(
	local randomFiles = for i = 1 to 10 collect (dotNetClass "System.IO.Path").GetRandomFileName()
	edittext et1 "eText1"width:150 text:randomFiles[1]
	edittext et2 "eText2"width:150 text:randomFiles[2]
	edittext et3 "eText3"width:150 text:randomFiles[3]
	edittext et4 "eText4"width:150 text:randomFiles[4]
	edittext et5 "eText5"width:150 text:randomFiles[5]
	edittext et6 "eText6"width:150 text:randomFiles[6]
	edittext et7 "eText7"width:150 text:randomFiles[7]
	edittext et8 "eText8"width:150 text:randomFiles[8]
	edittext et9 "eText9"width:150 text:randomFiles[9]
	edittext et10 "eText10"width:150 text:randomFiles[10]
)
createDialog main 200 250 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

try this in the listener

for c in main.controls where classof c == EditTextControl do
(
		-- to collect all text
		textArr = #()
		append textArr c.text
                format "textArr >> %\n" textArr 
		-- to remove text
		c.text = ""
		-- to collect all names of edittext controls
		namesArr = #()
		append namesArr c.controls[1].caption
                format "namesArr >> %\n" namesArr 
--etc.
)

bga

barigazy's picture

...

Is this easy or not

;)

try(destroyDialog ::main)catch()
struct mainDataStruct
(
	cbDataArr = #(),
	txtDataArr = #(),
	fn clearAllData roll = 
	(
		for c in roll.controls do
		(
			case classof c of
			(
				(CheckBoxControl): c.tristate = 0
				(EditTextControl): c.text = ""
			)
		)
	),
	fn saveAllData roll =
	(
		free this.cbDataArr ; free this.txtDataArr
		for c in roll.controls do
		(
			case classof c of
			(
				(CheckBoxControl): (append this.cbDataArr c.tristate)
				(EditTextControl): (append this.txtDataArr c.text)
			)
		)	
	),
	fn restoreAllData roll =
	(
		local cnt1 = 1, cnt2 = 1
		for c in roll.controls do
		(
			case classof c of
			(
				(CheckBoxControl): (if this.cbDataArr != #() do (c.tristate = this.cbDataArr[cnt1] ; cnt1 += 1))
				(EditTextControl): (if this.txtDataArr != #() do (c.text = this.txtDataArr[cnt2] ; cnt2 += 1))
			)
		)			
	)
)
global RUN = mainDataStruct()
rollout main "• • •"
(
	local randomFiles = for i = 1 to 10 collect (dotNetClass "System.IO.Path").GetRandomFileName()
	checkbox cb1 "cb1" width:50 tristate:(random 0 1) across:2
	edittext et1 "eText1" width:120 text:randomFiles[1]
	checkbox cb2 "cb2" width:50 tristate:(random 0 1) across:2
	edittext et2 "eText2" width:120 text:randomFiles[2]
	checkbox cb3 "cb3" width:50 tristate:(random 0 1) across:2
	edittext et3 "eText3" width:120 text:randomFiles[3]
	checkbox cb4 "cb4" width:50 tristate:(random 0 1) across:2
	edittext et4 "eText4" width:120 text:randomFiles[4]
	checkbox cb5 "cb5" width:50 tristate:(random 0 1) across:2
	edittext et5 "eText5" width:120 text:randomFiles[5]
	checkbox cb6 "cb6" width:50 tristate:(random 0 1) across:2
	edittext et6 "eText6" width:120 text:randomFiles[6]
	checkbox cb7 "cb7" width:50 tristate:(random 0 1) across:2
	edittext et7 "eText7" width:120 text:randomFiles[7]
	checkbox cb8 "cb8" width:50 tristate:(random 0 1) across:2
	edittext et8 "eText8" width:120 text:randomFiles[8]
	checkbox cb9 "cb9" width:50 tristate:(random 0 1) across:2
	edittext et9 "eText9" width:120 text:randomFiles[9]
	checkbox cb10 "cb10" width:50 tristate:(random 0 1) across:2
	edittext et10 "eText10" width:120 text:randomFiles[10]
	button btn1 "SaveData" across:3 align:#left
	button btn2 "ClearData" align:#left
	button btn3 "RestoreData" align:#left
 
	on btn1 pressed do RUN.saveAllData main
	on btn2 pressed do RUN.clearAllData main
	on btn3 pressed do RUN.restoreAllData main
 
	on main close do RUN = undefined
)
createDialog main 250 250 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

bga

Comment viewing options

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