Is there better way to do this?


#1

I wanted a callback that only triggers when user switch from one view to other.
but since i couldn’t find something like that,
I coded something like this ;

global before_av= viewport.activeViewport

fn viewport_swtich_trigger= (
curent_av=viewport.activeViewport
if before_av != curent_av then (
completeRedraw()***
before_av=viewport.activeViewport
)
)

callbacks.addScript #viewportChange “viewport_swtich_trigger()” id:#ViweSwtcd

Since i wonder this will slow down the view ports,
is there a better way of doing this?

*** - (actually what im trying to do is clear a text generated on view port using gw commands; when i switch frm one view to another. )


#2

i think you want something like this:


(
	global GW_displayText
	unregisterRedrawViewsCallback GW_displayText
	fn GW_displayText =
	(
		wPos = 40 -- horizontal position max = gw.getWinSizeX() 0 is left
		hPos = 40 -- vertical position max = gw.getWinSizeY() . 0 is lower left
		gw.htext [wPos,hPos,0] "Potatoes" color:red

		gw.updateScreen() 
	)
	registerRedrawViewsCallback GW_displayText
	
	global before_av= viewport.activeViewport
	global viewport_switch_trigger
	fn viewport_switch_trigger= 
	(
		current_av=viewport.activeViewport
		if before_av != current_av then 
			unregisterRedrawViewsCallback GW_displayText
		else
			registerRedrawViewsCallback GW_displayText
	)

	callbacks.addScript #viewportChange "viewport_switch_trigger()" id:#ViewSwtcd
)


Put text in the viewport corner
#3

Thanks a lot bro!
Will #viewportChange callback effect the viewport performance? (since its running everytime we make a change to the viewport?


#4

You´re welcome.

Any callback has a cost. You must unregister a callback if you don´t need it more.

Look at the maxscript help.

callbacks.removeScripts [<callback_type_name>] [id:<name>]
This method is used to unregister and remove one or more callback scripts.

Specifying just a callback event type name removes all the callback scripts for that event type.

Specifying just an id: removes all callback scripts in all events with that ID.

Specifying both limits the ID-based removal to the specified event type.


#5

Thanks a lot man! for the great help!


#6

if you need to change a viewport 100 times per second the callback will slow it a little :slight_smile:

#viewportChange itself doesn’t effect. it happens only when a viewport changes (not for every redraw). for every change to viewport you use redraw callback.

the script that you call can. but it’s a different story.


#7

Thanks a lot for the explanation bro! :thumbsup: