Menu Close

3dsMax tips #2 Custom Viewport Tooltip

When your cursor is hovering over an object in the viewport, you can see that a tooltip pops up and shows object name. 3dsMax 2017+ allow you to customize the viewport tooltip of the active viewport. You can not only show any data you want but also have a custom style using a subset of html tags.

This is a template code for a custom viewport tooltip.

global genTooltip
fn genTooltip = (
local obj = callbacks.notificationParam() -- Getting the objects under cursor from callback
local nodeName = obj.name
local mtlName = (if obj.material == undefined then ("undefined") else (obj.material.name))
local faceNum = try(obj.mesh.numfaces as string)catch("0")
local vertsNum = try(obj.mesh.verts.count as string)catch("0")
local tooltipText = "<u><b><font color=blue size=6>" + nodeName + "</b></font></u><br>"
tooltipText += "<font  size=4>Layer : "+ obj.layer.name + "</font><br>"
tooltipText += "<font  size=4>Material : "+ mtlName + "</font><br>"
tooltipText += "Verts Count: " + vertsNum + "<br>"
tooltipText += "Face Count: " + faceNum + ""
viewport.appendtooltip tooltipText
)
callbacks.removeScripts id:#MXSVIewportTooltip
callbacks.addScript #preViewportTooltip "genTooltip()" id:#MXSVIewportTooltip

Let’s see what’s happening here.

First, we made a global function, genTooltip , to assemble the tooltip text and add to viewport.
The first line local obj = callbacks.notificationParam() is how you get the the objects under cursor from callback. It is what it is. Don’t touch it. 🙂

Then we build the text for the tooltip, As you can see, you can use a subset of html tags. The devloper mentioned to check this document. http://doc.qt.io/qt-4.8/richtext-html-subset.html

The above code will make a bold(<b></b>) big blue(<font color=blue size=6></font>) object name with underline(<u></u>).
Adding <br> is like adding enter to make a new line.
Then, the size 4 layer name and the material name will be added.
Then, normal size verts count and face count will be added.

After you build the text to display,viewport.appendtooltip tooltipText will resister the text as tooltip.

Lastly, we call this genTooltip  function as #preViewportTooltip callback.
That’s the lase 2 line. If copy/paste the above code into Maxscript Editor and run this once with CTRL+E, it will last for the session.

If you are lazy like me, you can copy/paste the above code into notepad.
Then, save as “customViewportTooltip.ms” in the user startup script folder.
C:\Users\[username]\AppData\Local\Autodesk\3dsMax\2020 – 64bit\ENU\scripts\startup

OK. if you are lazy again, type this in the listener and press num pad Enter.
getdir #userstartupscripts

Now every time when you start max, the script will run automatically for you.

Bonus tip!

If you have a looooooooooooot of objects(I mean really a lot), the hit testing to detect which object is under cursor might take a little bit of time. If you want to save a few milisecond. You can turn off viewport tooltip from here.

If you like this post, you will like renderStacks, too! Let’s click here and check it out!