Display Message on Viewport (toggle)

Hello, I have a small macro and would like to have some text displayed on the viewport when I activate it, I've tried the code from this page:

https://forums.cgsociety.org/t/draw-a-text-in-corner-of-the-viewport/163...

but I get an error Exception message: "registerRedrawViewsCallback() expected function, got: undefined."

My macro is the following:

macroScript LockSnapScale
category:"# sampei"
buttonText: "Lock,Snap,Scale"
toolTip:"Lock,Snap,Scale"

(
actionMan.executeAction 0 "59231" -- Selection: Selection Lock Toggle
actionMan.executeAction 0 "40072" -- Snaps: Snaps Toggle
actionMan.executeAction 0 "40223" -- Snaps: Percent Snap Toggle
macros.run "Tools" "Non_Uniform_Scale"
toolMode.selectionCenter()
)

Comments

Comment viewing options

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

.

To hide the text execute only this:

try(unregisterRedrawViewsCallback GW_displayText)catch()
sampei's picture

alright thanks, I take it

alright thanks, I take it it's quite complicated to incorporate a ON/OFF switch type thing in the same script then? perhaps the way to it would be with 2 different events in the script?

miauu's picture

.

If your script has an UI then you can use a checkbutton. When it is ON - show the info in viewport, when it is Off - hide the info.

sampei's picture

no UI, just the macro I

no UI, just the macro I posted above as I'm rather hopeless with scripting unfortunately. My aim was to have a one click solution, even with the checkbutton I would still need 2 separate shortcut keys to activate and deactivate it. Thanks anyway, appreciate your help :)

miauu's picture

.

macroScript LockSnapScale
category:"# sampei"
buttonText: "Lock,Snap,Scale"
toolTip:"Lock,Snap,Scale"
(
	actionMan.executeAction 0 "59231" -- Selection: Selection Lock Toggle
	actionMan.executeAction 0 "40072" -- Snaps: Snaps Toggle
	actionMan.executeAction 0 "40223" -- Snaps: Percent Snap Toggle
	macros.run "Tools" "Non_Uniform_Scale"
	toolMode.selectionCenter()
 
	global GW_displayText_state	
	global GW_displayText
 
	try(unregisterRedrawViewsCallback GW_displayText)catch()
	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() 
	)
 
 
	if GW_displayText_state == undefined or GW_displayText_state == false then
	(
		GW_displayText_state = true
		registerRedrawViewsCallback GW_displayText
	)
	else
	(
		GW_displayText_state = false
		try(unregisterRedrawViewsCallback GW_displayText)catch()
	)
)
sampei's picture

yes that's it! you are

yes that's it! you are amazing, thanks a million! :D

Since we're here, I always had an idea for a specific script and I'm sure you know if it's possible or not (but I imagine it would be very complicated).

Basically you would have the current number of selected sub elements (points, edges or polygons) placed above the mouse cursor, so when you moved the cursor this number would move with it, remaining above it at all times. This would work with all selection tools.

So for example, as you are selecting points with the Paint Selection Region tool, the number goes from 0 to N of selected points.

This would ensure you are immediately aware if you selected an unwanted element by accident, which happens to me quite frequently. Of course you can do this by looking at the statistics on the top left corner, but this breaks the modeling "flow".

Would such a thing possible in theory?

miauu's picture

.

What you describe is possible.

I will post a script in the coming days, if someone else not do it meanwhile.

sampei's picture

outstanding! really looking

outstanding! really looking forward to seeing what you come up with ;)

miauu's picture

.

Works with Edit Poly modifier and Editable Poly objects only.

(
	global GW_displayText_state	
	global GW_displayText
 
	try(unregisterRedrawViewsCallback GW_displayText)catch()
	fn GW_displayText =
	(
		if selection.count == 1 do
		(
			curO = selection[1]
			curMod = modPanel.getCurrentObject()
			selectionBA = #{}
			case classOf curMod of
			(
				editable_poly:
				(
					case subobjectlevel of
					(
						1: (selectionBA = polyop.getVertSelection curO)
						2: (selectionBA = polyop.getEdgeSelection curO)
						3: (selectionBA = polyop.getEdgeSelection curO)
						4: (selectionBA = polyop.getFaceSelection curO)
						5: (selectionBA = polyop.getFaceSelection curO)
					)
				)
				edit_poly:
				(
					case subobjectlevel of
					(
						1: (selectionBA = curMod.getSelection #Vertex)
						2: (selectionBA = curMod.getSelection #Edge)
						3: (selectionBA = curMod.getSelection #Edge)
						4: (selectionBA = curMod.getSelection #Face)
						5: (selectionBA = curMod.getSelection #Face)
					)
				)
			)
			mousePos = mouse.pos
			gw.wtext [mousePos.x+10,mousePos.y-10,0] ((selectionBA.numberset) as string) color:yellow
			gw.updateScreen() 
		)
	)
 
	if GW_displayText_state == undefined or GW_displayText_state == false then
	(
		GW_displayText_state = true
		registerRedrawViewsCallback GW_displayText
	)
	else
	(
		GW_displayText_state = false
		try(unregisterRedrawViewsCallback GW_displayText)catch()
	)
)

Comment viewing options

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