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 |
#1
|
|||
|
|||
Setting Visual Tool Text from outside of the object
Hi,
I have a model with a user event that fires every day (24hrs), which will be used in the future to read in daily production data for execution. On the basis of this data, I want to display some text on the background, such as the production date and day (e.g. using an approach similar to Regan Blackett's useful post, with some extensions). Before getting this ambitious, I wanted to try something simpler, so I placed a visual tool (called "StatusDisplay") in the model, setting its display to Text, and setting the Text Display dropdown to the first item "Display Text, which provides a default string of "Hello". Based on some other useful posts I then set a global variable called "StatusDisplayPtr", of type treenode, to speed the referencing. I have tried various approaches to set the "textnode" variable of "StatusDisplay" with no success. I ended up trying the following code in the Script window, with a static string which still didn't work. Code:
setvarstr( StatusLabelPtr, "textnode", "test text"); setvarnum(StatusLabelPtr, "textsize", 30); By this I intuit that it's actual value is set somewhere, and after a bit of searching found that "textcode" sets the string value. I tried commenting this out, but it still won't work. Q: How can I set the text string of a visual tool from within my user event? please help Brett BTW: One of the most brilliant, yet underrated features of Flexsim is the ability to have many dialog boxes open, and yet still issue commands, thus enabling comparisons to be made between different objects. Most software packages only enable one dialog box to be open at a time and ignore input outside of it until it is closed. Well done designers on this feature - excellent!!! Last edited by brett forbes; 02-05-2013 at 05:46 PM. Reason: whoops forgot to check the notification box |
#2
|
||||
|
||||
Hi, I just use a Textlabel in the Visual Tool for this task and this works excellent.
Nonetheless your way should work quiet well. No idea why it doesn´t. But maybe you can find some hints in trying my way.
__________________
Hemmi |
The Following User Says Thank You to Sebastian Hemmann For This Useful Post: | ||
brett forbes (02-06-2013) |
#3
|
|||
|
|||
Developing a workaround
Hi Sebastian,
Thanks for your answer. I have worked out a similar workaround, although I still don't know why I couldn't change the textnode from my user event. My workaround is to use a string-type global variable "timetext", which I set within my user event. Then immediately afterwards I send a delayed message to the Visual Tool, with a delay of 0. In the Visual tool's OnMessage trigger, I then set the value of the text node. My code in the event is as follows Event Code Code:
/** set StatusLabel Text, iftime() is < 1440 set to warmup, else set to actual day value */ if(time()<1440) { // set label towarmup timetext= concat("WarmupPeriod - ", numtostring((60-time()/24),0, 0)); senddelayedmessage(StatusLabelPtr, 0, current, 0, 0, 0); //setvarstr(node("/StatusLabel/variables", model()), "textnode",timetext); } else { // set label toactual production days timetext= concat("ProductionDay - ", numtostring(((time()-1440)/24) + 1, 0, 0)); senddelayedmessage(StatusLabelPtr, 0, current, 0, 0, 0); //setvarstr(node("/StatusLabel/variables", model()), "textnode",timetext); } OnMessage Trigger Code:
treenodecurrent = ownerobject(c); /** on message display thetimetext */ setvarstr(current, "textnode", timetext); Thanks Brett |
#4
|
|||
|
|||
Did you comment out the setnodestr() part of the text display trigger? If not that would override your direct change every time the window is repainted.
|
The Following 2 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
Phil BoBo (02-07-2013) |
#5
|
||||
|
||||
Code:
setvarstr(node("/StatusLabel/variables", model()), "textnode",timetext); Code:
setvarstr(node("/StatusLabel", model()), "textnode",timetext); Next time, it would be easier to tell you what is wrong if you would post the actual model and not just a snippet of code that seems to be fine in context. The VisualTool's Text Display function is called every time it is drawn. If your event is setting it once, then the next time your VisualTool's Text Display function is called (the next time it is drawn on the screen), it will be set back to whatever that function is setting it to. |
The Following User Says Thank You to Phil BoBo For This Useful Post: | ||
brett forbes (02-07-2013) |
#6
|
|||
|
|||
Thanks Jason and Phil,
Thanks for the comment Jason, I did comment out the setnodestr() part of the text display trigger, as i worked out that it would be called automatically, and that i had to nullify it.
Thanks for the comment Phil, yes I had some trouble understanding the node pointing at the begining, which is why I eventually went to a global variable for the pointer (i.e. why my original incorrect code lines were commented out). This is because I had initially thought that everything was a node, and it took me some time to realise that some nodes are attributes and need to be managed differently. I must admit that I also hadn't quite understood how the referencing worked, and when to use > instead of /. I have reached the assumption that I use > when i want to go into an attribute node, like variables. It is interesting that my approach of setting a global string variable and sending a delayed message works perfectly within my user event, yet exactly the same approach does not seem to work within the OnReset trigger (i.e. the global string variable is reset, but the message doesn't update the Visual tool). I will take your advise Phil and try out the debugging tools. Thanks for our useful comments Brett |
Thread | Thread Starter | Forum | Replies | Last Post |
Object statistics in Visual Tool | George Serhan | Q&A | 1 | 08-18-2012 01:16 AM |
Visual Tool Text Wrapping | Todd Benanzer | Q&A | 2 | 12-17-2010 10:30 AM |
Put GlobalTable into Visual Tool | claudia gertheinrich | Q&A | 3 | 03-25-2010 04:04 AM |
Sum in a Visual Tool | jspeece | Q&A | 3 | 09-04-2009 11:31 AM |
Visual tool as a container qs | Paul Dowling | Q&A | 2 | 08-20-2007 07:53 PM |