Difference between executing something from a UI button and raw execution?

I have a script, as an exsample, lets say its.

for i = 0 to 10 by 1 do print i

what is the difference between running it as it is, and running it from inside a rollout button like

rollout Count "count" width: 100 height:100
(
button countbutton "count it" pos....
on countbutton pressed do
(
for i = 0 to 10 by 1 do print i
)

)

My script is a lot longer than this but if I run it raw as in the first example, it works perfectly. But if I just cut and paste it into a button only parts of the script works. I did not realize that it would behave any different.

Any ideas?

Comments

Comment viewing options

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

Confirmed

Yea I can literally take the hole code with variables and all and paste it into a button and it will not work the same as if I leave it outside of a rollout.

This is my signature! WOOT! Gratz to me!

Anubis's picture

debug suggestion

Try to move UIAccessor's part of the code into separate function, or the whole code, if necessary. If that not help, may move the function outside of the rollout body. But... its better to debug the code itself by inserting print/format on many placesses inside the code, and catch the problem.

my recent MAXScripts RSS (archive here)

miauu's picture
Anxo's picture

No Toolbox

Than the scene would not work on your machine. Till Max 2014 when box 2 and 3 will be part of max by default.

But the only thing I am changing between the 2 scripts is taking the function out of the rollout and it work. I do not get an error, it just does not skin the mesh to the particles as it does when I have the script outside of the rollout.

It must somehow treat the execution of the loop differently.

This is my signature! WOOT! Gratz to me!

miauu's picture

Can you provide the test

Can you provide the test scene?

Anxo's picture

can you provide the test

Do you have toolbox #2?

This is my signature! WOOT! Gratz to me!

miauu's picture

Post the code, so we can find

Post the code, so we can find where is the problem when you use the script in a rollout. May be there is a problem with the variables, may be something else. If the script is written correctly there is no difference between executing it from the rollout or raw execution.

Anxo's picture

The Code

Code in Rollout

rollout paperSpawnner "Paper Spawnner" width:162 height:302
(
	local clonedPaper = #()
	local sf = animationrange.start
	local ef = animationrange.end
	local spawnRate = 1
	button spawnButton "Boom!" pos:[17,188] width:115 height:39
	label lbl1 "Animation Range:" pos:[2,2] width:88 height:14
	spinner spn1_startFrame "" pos:[71,26] width:58 height:16 range:[-1000,1000,0] scale:1
	label lbl2 "start frame:" pos:[6,28] width:62 height:14
	spinner spn2_endFrame "" pos:[68,54] width:58 height:16 range:[-1000,1000,0] scale:1
	label lbl3 "end frame:" pos:[6,54] width:64 height:14
	label lbl4 "Spawn Rate:" pos:[4,99] width:88 height:14
	spinner spn3_spawnRate "" pos:[13,123] width:58 height:16 range:[-1000,1000,1] type:#integer scale:1
	label lbl5 "per second" pos:[81,122] width:64 height:14
	button resetButton "Reset" pos:[45,278] width:61 height:20
	on spawnButton pressed do
	(
		--clonePaper = #()
		adjustedSP= 24/spawnRate
		print adjustedSP
		for i = 8 to 80 by 8 do (
			slidertime = i
			--thePaper = $tpt
			maxOps.cloneNodes $tpt clonetype:#copy newNodes:&nnl
			thePaper = nnl[1]
			--append clonedPaper thePaper
			unhide thePaper
			select thePaper
			max modify mode
			theMod = Particle_Skinner() 
			addModifier $ theMod 
			myPS = $.modifiers[1]
			myPS.Before_Hide = off
			masterSystem = $'PF Source 005'
			masterDriver = $'MeshDriver'
			-- pressing/depressing the 'Add' seems to initiate the function 
			maxHWND = windows.getMAXHWND() 
			cmdHWND = for d in UIAccessor.GetChildWindows maxHWND where UIAccessor.GetWindowText d == "Command Panel" do exit with d 
			btnHWND = (windows.getChildHWND cmdHWND "Add")[1] 
			if findstring (UIAccessor.GetWindowDllDescription btnHWND) "Box#2" != undefined do -- check to see if it's the add button from particle skinner 
			( 
				UIAccessor.PressButton btnHWND -- press the 'Add' button 
				UIAccessor.PressButton btnHWND -- depress the 'Add' button 
			)	 
			myPS.Particle_Flow_Systems = #(masterSystem) 
			myPS.All_Particle_Flow_Events = false
			myPS.Particle_Flow_Events = #(masterDriver) 
			myPS.activateSkinning()
		)
		slidertime = sf
	)
	on spn1_startFrame changed val do
(
		sf = val
	print sf 
	)
	on spn2_endFrame changed val do
(
		ef = val
	print ef 
)
	on spn3_spawnRate changed val do
	(
			spawnRate = val
		print spawnRate
		)
	on resetButton pressed do
	(
		delete clonePaper
		)
)
createdialog paperSpawnner

Does not work, but If I take it out of the rollout

        clonedPaper = #()
        sf = animationrange.start
	ef = animationrange.end
	spawnRate = 1
	adjustedSP= 24/spawnRate
		print adjustedSP
		for i = 8 to 80 by 8 do (
			slidertime = i
			--thePaper = $tpt
			maxOps.cloneNodes $tpt clonetype:#copy newNodes:&nnl
			thePaper = nnl[1]
			--append clonedPaper thePaper
			unhide thePaper
			select thePaper
			max modify mode
			theMod = Particle_Skinner() 
			addModifier $ theMod 
			myPS = $.modifiers[1]
			myPS.Before_Hide = off
			masterSystem = $'PF Source 005'
			masterDriver = $'MeshDriver'
			-- pressing/depressing the 'Add' seems to initiate the function 
			maxHWND = windows.getMAXHWND() 
			cmdHWND = for d in UIAccessor.GetChildWindows maxHWND where UIAccessor.GetWindowText d == "Command Panel" do exit with d 
			btnHWND = (windows.getChildHWND cmdHWND "Add")[1] 
			if findstring (UIAccessor.GetWindowDllDescription btnHWND) "Box#2" != undefined do -- check to see if it's the add button from particle skinner 
			( 
				UIAccessor.PressButton btnHWND -- press the 'Add' button 
				UIAccessor.PressButton btnHWND -- depress the 'Add' button 
			)	 
			myPS.Particle_Flow_Systems = #(masterSystem) 
			myPS.All_Particle_Flow_Events = false
			myPS.Particle_Flow_Events = #(masterDriver) 
			myPS.activateSkinning()
		)
		slidertime = sf
	)

it works.

This is my signature! WOOT! Gratz to me!

Comment viewing options

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