PDA

View Full Version : How to display dynamic text next to an object


Cliff King
09-21-2007, 09:08 AM
There is an attribute (node) on every object named objectinfo that contains subnodes. The names of these subnodes become the text that is displayed next to an object when "Show Names" is checked for the view. The names of these subnodes (i.e. %Processing: 89) are updated with every screen refresh with code in the OnPreDraw event of the class object. The user may overwrite these names with their own names with code in the Custom Draw Code trigger found in the object's Properties Window. In fact there is a picklist option titled "Draw Test near Object's Name" that is available to help you do this. Adding and deleting the number of subnodes to increase or decrease the number of lines of text displayed is allowed.

Some people have asked how to query the values associated with these text displays. Although this is probably not the most direct way to do this, the following code shows you how this could be done:

treenode displaynodes = objectinfo(current);
string utilizationtext = getnodename(rank(displaynodes,3));
int totalstringlength = stringlen(utilizationtext);
int textstringlength = stringlen("%Processing: ");
int numstringlength = totalstringlength - textstringlength;
string numstring = stringpart(utilizationtext, textstringlength, numstringlength);
double utilizationnumber = stringtonum(numstring);

A more direct way to query the processing time of an object would be to query the value of the associated statelist node with code such as this:

treenode stateprofile = state_profile(current);
treenode processingnode = rank(stateprofile, STATE_PROCESSING);
double processingtime = getnodenum(processingnode);

If you prefer a percentage then add this:

double processingpercent = 100 * processingtime / time();

Congshi Wang
11-11-2010, 04:24 AM
Hi Cliff,

could you please tell me how to change (add or delete) stats in objectinfo. For example I'd like to have average content and not maximum content for a queue.

Thanks!

Jason Lightfoot
11-11-2010, 07:57 AM
You can update it's name to the value you want in code in the OnDraw trigger:

setname(rank(objectinfo(current),2),concat("AvgContent: ",numtostring(get(stats_contentavg(current)),0,1))) ;

Note also that you can override the entire box that is displayed, including the name, using setdrawnamefunction() for which there is a good example in the Command Help. This is a version to show how to get multiple lines since you can't just place \n in the text:

if (parval(2) == 0)
setdrawnamefunction(120, 32, c, parval(1), 1);
else
{
glTranslated(-58, -15, 0);
drawflattext("Hello World");
glTranslated(0, -15, 0);
drawflattext("It's a beautiful day");
}

Phil BoBo
11-11-2010, 09:56 AM
There is also a pick option called "Change Object's Stats Display" in the OnDraw trigger of each object that has the AvgContent code Jason pasted.

Jason Lightfoot
11-11-2010, 12:45 PM
I didn't see that! :o