Notifications
Clear all

[Closed] Help with text in viewport is needed

Hello, respective community… Recently i started to learn maxscript and encountered following problem: i made script which switches (on/off) state of the lights depending on “ambient only” checkbox i.e. we have few lights in the scene, some are ambient and some aren`t. I need to switch ones off while others are on. My script is working just well but i wanted to implement it with displaying which lights are currently on, “ambient” or “normal”. The problem itself is in not displaying text with such code :


 
 gw.setTransform (Matrix3 1)
 gw.Text [10,10,0] "some text" color:green
 strRect = (Box2 50 50 50 50)
 gw.enlargeUpdateRect strRect
 gw.updateScreen()
 
 

Also I very appreciate if you place some critics and advices for the whole code


 macroScript SwitchLights
 	category:"myScripts"
 	toolTip:""
 
 (
 local LightningState = ""
 for l in lights do 
 	(
 	if l.baseobject.ambientOnly == true then
 		(
 		if l.baseobject.Enabled == true then 
 			(
 			for n in lights do
 				(
 				if n.baseobject.ambientOnly == false and n.baseobject.Enabled == false then
 				n.baseobject.Enabled = true; l.baseObject.Enabled = false
 				)
 			)
 		else if l.baseobject.Enabled == false do 
 			(
 			for n in lights do
 				(
 				if n.baseobject.ambientOnly == false and n.baseobject.Enabled == true then
 				n.baseobject.Enabled = false; l.baseObject.Enabled = true
 				if l.baseobject.Enabled == true then LightningState = "ambient lightning"
 				if n.baseObject.Enabled == true then LightningState = "normal lightning"
 				)
 			)
 
 		)
 )
 gw.setTransform (Matrix3 1)
 gw.Text [10,10,0] LightningState color:green
 strRect = (Box2 50 50 50 50)
 gw.enlargeUpdateRect strRect
 gw.updateScreen()
 
 
 )
 
 

P.S. Sorry for my English – its not my native language. P.P.S. Oh, yes, Ive read other threads relative to my problem, but didnt understood, why my text isnt working…

10 Replies

In recent versions of Max (well, in the last 4, at least), viewport text display in world space has severe issues in DirectX mode. It might work in SZB and OpenGL mode, but we all want to use DirectX after all, it is the fastest mode.

It looks like text display in screen coordinates does not have the same issues, so a possible workaround would be to convert the world space position into screen space (see the “How To … Develop a Vertex Renderer” tutorial in MAXScript Help for the actual code) and then draw the text in 2D screen coordinates instead.

Woah, thats cool

Wow!! Borislav Petrov himself answered me, Im very very pleased. Man i decided to try scripting after watching your tutorials of CG Acadamy, you are the best hellish scripter ever :bowdown: :buttrock: About my script.. In search of solution ive tried this script and it worked sometimes… But when i used part of the code where text is creating itself it does nothing in my case ((…
And I`ll surely follow you advice and see what i can do. Thank you!

edited…
Just in case… i used max 9

Well, it is not Krakatoa, but with a couple of objects, it tends to run in real time!

Thanks for the flowers!

(
	fn mapWorldToScreen thePoint =
	(
		local thePos = thePoint * viewport.getTM()
		local screenSize = getViewSize()
		local screen_origin = mapScreenToView [0,0] (thePos.z) screenSize
		local end_screen = mapScreenToView screenSize (thePos.z) screenSize
		local world_size = screen_origin-end_screen
		local x_aspect = screenSize.x/(abs world_size.x)
		local y_aspect = screenSize.y/(abs world_size.y)
		point3 (x_aspect*(thePos.x-screen_origin.x)) (-(y_aspect*(thePos.y-screen_origin.y))) 0
	)
	
	for theObj in selection do
	(
		gw.setTransform (matrix3 1)
		gw.wText (mapWorldToScreen theObj.pos) theObj.name color:green
	)
	gw.enlargeUpdateRect #whole
	gw.updateScreen()
)

This works with Max 9.
Select a couple of objects and evaluate to see if it works for you too…

it works well for max 9 and 2008 too.
Thank you very much

It seems like problem was not in the drawing methods, but somewhere else in my code. When I run Bobo`s script it works perfectly, but if i paste it into my, it becomes dead ond do nothing at all. Please somebody explain to stupid me where i have to paste working code and why there

Hi Phaeton, try using:

Gw.EnlargeUpdateRect #whole

this string already in the code but it doesnt work in my script.. Please check my first post and tell me, where i have to paste Bobos code for it to work properly. It seems like i missed right place or something else

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Keep in mind that the viewport can update after the drawing and your update and clear all the text you wrote. So it is not very persistent, and it is possible that calling it in a macroScript is doing just that – drawing and redrawing after it. Will have to take a closer look.

You can put the code into a function and register it as a redraw callback so it gets updated constantly. (but will be flashing a bit)