ScriptSpot

Forum topic · General Scripting

ERROR LOOPPING CONTINUOSLY CANNOT CALL FUNCTION JUST ONCE

By artrender.info · 2013-01-24

Description

I WANT TO REFRESH FORM DEPENDING ON SELECTING OBJECTS(COULD BE SINGLE OBJECTS AS WELL AS GROUPS) THIS SCRIPT http://www.scriptspot.com/forums/3ds-max/general-scripting/how-to-enable… IS GIVING ERROR WHEN WORKING WITH GROUPS, THAT IS WHY I WANT TO USE TIMER

timer clock "testClock" interval:1000 --tick once a second

on clock tick do
(

fresh_obj_selection=selection as array

if cur_obj_selection!=fresh_obj_selection

then
(
print("output::"+(fresh_obj_selection as string))
print("output::"+(cur_obj_selection as string))
cur_obj_selection=fresh_obj_selection

)

)

Comments (7)

SOLVED

artrender.info · 2013-01-24

THANK YOU!

function check_selection = (
this_sel_count = (selection as array).count
updatefunction()
)

...................

on my_rollout open do check_selection()

STILL NOT WORKING

artrender.info · 2013-01-24

THX FOR QUICK ANSWER! MY GOAL IS TO CALL FUNCTION ONLY WHEN I SELECT OTHER OBJECTS

-------------BEFORE ROLLOUT I USE-------------------------

cur_obj_selection = selection as array

------------------AFTER ROLLOUT -----------------------------

--I WANT TO CHECK, IS SELECTION CHANGED OR NOT, IF YES THEN PRINT
--I DON'T KNOW WHY BUT IT'S PRINTING CONTINUOUSLY IF EVEN I DON'T SELECT ANYTHING --ELSE, JUST ONE OBJECT SELECTED

timer clock "testClock" interval:1000 --tick once a second

on clock tick do
(

--fresh_obj_selection=selection as array
fresh_obj_selection = for i in selection where not isGroupHead i collect i

if cur_obj_selection!=fresh_obj_selection

then
(
print("output::"+(fresh_obj_selection as string))
print("output::"+(cur_obj_selection as string))
--print cur_obj_selection[1]
--print fresh_obj_selection[1]
cur_obj_selection=fresh_obj_selection

)

)

no need UPPER case typing!

Anubis · 2013-01-24

You cannot compare arrays directly like a1 != a2.
You should compare all elements stored inside.
And to track SELECTION CHANGED via Timer, hmm...
probably (close enough, but not precise):

on clock tick do
(
	if selection.count != lastSelCount do
	(
		lastSelCount = selection.count
		print selection
	)
)

Better is to follow Branko advice and use callbacks.

TRIED THIS AND IS STILL NOT WORKING

artrender.info · 2013-01-24

ITS STILL LOOPING, AND IT'S PRINTING EVERY SECOND
"output::#()"
"output::#()"
"output::#()"
"output::#()"
"output::#()"
"output::#()"
"output::#()"
"output::#()"
"output::#()"
"output::#()"
"output::#()"
"output::#()"

timer clock "testClock" interval:1000 --tick once a second

on clock tick do
(

--fresh_obj_selection=selection as array
fresh_obj_selection = for i in selection where not isGroupHead o collect o

if cur_obj_selection!=fresh_obj_selection

then
(
print("output::"+(fresh_obj_selection as string))
print("output::"+(cur_obj_selection as string))
--print cur_obj_selection[1]
--print fresh_obj_selection[1]
cur_obj_selection=fresh_obj_selection

)

)

barigazy · 2013-01-24

Sorry. I correct for-loop. Look the first code (for o in selection ...)

barigazy · 2013-01-24

Try to isolate group helper object

fresh_obj_selection = for o in selection where not isGroupHead o collect o
-- or
if isGoupMember selection[1] do ...