ScriptSpot

Forum topic · General Scripting

progress bar + fileIn

By citizenWOLF · 2017-07-15

Description

Hello!

I run a script that has a running time of more than a few seconds and i was thinking to add a progress bar.

It is possible to run the script via fileIn "myscript.ms" with progress bar?


rollout test "Testing" width:300 height:100
(
	button btn "Run!"
	progressbar pbar height:30 color:orange
	label lbl1 ""
	on btn pressed do
	(
		start = timeStamp()
		try (filein "myScript.ms") catch(messagebox "Error" beep:false)
		pbar.value = --> -------------------------------- what should i do here?!?!?
		if pbar.value > 99 do (pbar.value=0)
		completeredraw()
		end = timeStamp()
		lbl1.caption =  " Done in " + (formattedPrint ((end - start) / 10)) + " sec"
	)
)
createDialog test

Comments (4)

3dwannab · 2017-07-18

in your filein code you could control the pbar by placing the rollout name first like example.


if classof test == RolloutClass do
(
	test.pbar.value = -- what you were going to do in other code
	if test.pbar.value > 99 do (pbar.value=0)
	)

citizenWOLF · 2017-07-18

do you mean?


if classof test == RolloutClass do
	(
	test.pbar.value = 
		/*
		My code here ?
		*/
	if test.pbar.value > 99 do (pbar.value=0)
	)

It won't work.. Can you, please, write an example to understand better what you mean?
Thank you in advance,
-M.

3dwannab · 2017-07-19

Here's an example. Without your filein code I can't do an exact example.

This should get you started


try destroyDialog testRol1 catch()
try destroyDialog testRol2 catch()

rollout testRol1 "Close me"
(
	progressBar pbar "" value:0 color:[0,0,0]
	on testRol1 moved pos do
	(
		SetDialogPos testRol2 [((GetDialogPos testRol1).x+8),((GetDialogPos testRol1).y-25)]
		)
	)
createDialog testRol1 200 30

rollout testRol2 ""
(
	spinner spnSelectAmount "Change me: " range:[0,100,0] type:#float

	on spnSelectAmount changed val do
	(
		prog = spnSelectAmount.value

		-- reference is made to the pbar by placing the rollout internal name before with .
		testRol1.pbar.value = prog
		testRol1.pbar.color.r = (255-((255/100)*prog))
		testRol1.pbar.color.g = ((255/100)*prog)
		testRol1.pbar.color.b = 0
		)
	)
createDialog testRol2 200 20 ((GetDialogPos testRol1).x+8) ((GetDialogPos testRol1).y-25) parent:testRol1.hwnd style:#() bgcolor:black


.

miauu · 2017-07-18


pbar.value = --> -------------------------------- what should i do here?!?!?

You should update the progressBar value using the data from the "myScript.ms". For example, if "myScript.ms" is a loop that counts the selected objects pass the iterations to the pbar and update its value. This way when the loop in "myScript.ms" stops the pbar will be "full".