ScriptSpot

Forum topic · General Scripting

gwText unregister when mouse move

By tosyk · 2022-07-16

Description

Hi, I want the text I draw to be hidden after mouse move/pan/rotate or over time in viewport.
Here's my code:


(
	global GW_displayText
	unregisterRedrawViewsCallback GW_displayText
	fn GW_displayText = (
		rect = (box2 13 47 96 97)
		gw.Hrect rect red
		gw.hMarker (point3 20 207 0) #smallDiamond color:yellow
		gw.hText (point3 27 200 0) ("This is not a Standard material. Actual typ1e:") color:yellow
		gw.enlargeUpdateRect #whole 
		gw.updateScreen()
	)
	registerRedrawViewsCallback GW_displayText
)
Comments (1)

barigazy · 2022-07-22

You can use Timer.
In the example below, I set a timer to clean the screen after on 3 seconds


(
	global GW_displayText
	local clock = dotNetObject "Timer"
	clock.interval = 3000 -- 3000 milliseconds or 3 sec
	fn cleanScreen = (unregisterRedrawViewsCallback GW_displayText ; completeredraw() ; clock.stop())
	cleanScreen()
	fn GW_displayText = (
		rect = (box2 13 47 96 97)
		gw.Hrect rect red
		gw.hMarker (point3 20 207 0) #smallDiamond color:yellow
		gw.hText (point3 27 200 0) ("This is not a Standard material. Actual typ1e:") color:yellow
		gw.enlargeUpdateRect #whole 
		gw.updateScreen()
	)
	dotnet.addEventHandler clock "tick" cleanScreen
	registerRedrawViewsCallback GW_displayText
	clock.start() 
)