ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
|
Downloads |
Tips and Tricks Share helpful modeling ideas |
#1
|
||||
|
||||
How to display dynamic text next to an object
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(); Last edited by Cliff King; 11-26-2007 at 08:20 PM. |
The Following User Says Thank You to Cliff King For This Useful Post: | ||
Congshi Wang (11-11-2010) |
#2
|
|||
|
|||
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! |
#3
|
|||
|
|||
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"); } Last edited by Jason Lightfoot; 11-13-2010 at 09:44 AM. |
The Following User Says Thank You to Jason Lightfoot For This Useful Post: | ||
Congshi Wang (11-11-2010) |
#4
|
||||
|
||||
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.
|
The Following User Says Thank You to Phil BoBo For This Useful Post: | ||
Jason Lightfoot (11-11-2010) |