ATTENTION

This 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

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 02-05-2013
brett forbes brett forbes is offline
Flexsim User
 
Join Date: Oct 2011
Posts: 34
Downloads: 0
Uploads: 0
Thanks: 27
Thanked 3 Times in 2 Posts
Rep Power: 107
brett forbes is on a distinguished road
Default 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);
I used the textsize change to ensure my pointer was correct. When I run the script, the text size changes, and the textnode value in the tree view appears to change to "test text", although the screen display remains as "Hello", until I click on the treenode, at which point its value changes back to "Hello".

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  
Old 02-06-2013
Sebastian Hemmann's Avatar
Sebastian Hemmann Sebastian Hemmann is offline
Flexsim User
 
Join Date: Sep 2009
Location: Braunschweig (Germany)
Posts: 439
Downloads: 52
Uploads: 0
Thanks: 472
Thanked 217 Times in 154 Posts
Rep Power: 319
Sebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to beholdSebastian Hemmann is a splendid one to behold
Default

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  
Old 02-06-2013
brett forbes brett forbes is offline
Flexsim User
 
Join Date: Oct 2011
Posts: 34
Downloads: 0
Uploads: 0
Thanks: 27
Thanked 3 Times in 2 Posts
Rep Power: 107
brett forbes is on a distinguished road
Thumbs up 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); 
}      
Then in my Visual Tool OnMessage Trigger, I use
OnMessage Trigger
Code:
 
treenodecurrent = ownerobject(c);
/** on message display thetimetext */
setvarstr(current, "textnode", timetext);
I still don't understand why I couldn't set the textnode from the event, but this workaround, which is similar to the one suggested by Sebastian, seems to work fine.

Thanks

Brett
  #4  
Old 02-07-2013
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

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  
Old 02-07-2013
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Code:
setvarstr(node("/StatusLabel/variables", model()), "textnode",timetext);
should be

Code:
setvarstr(node("/StatusLabel", model()), "textnode",timetext);
Your initial post of setvarstr( StatusLabelPtr, "textnode", "test text"); imples that you have an accurate pointer to your StatusLabel object. Looking at your second code snippet, your pointer is probably null. You should use the Flexscript debugger to see what is happening in your code.

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  
Old 02-07-2013
brett forbes brett forbes is offline
Flexsim User
 
Join Date: Oct 2011
Posts: 34
Downloads: 0
Uploads: 0
Thanks: 27
Thanked 3 Times in 2 Posts
Rep Power: 107
brett forbes is on a distinguished road
Default 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


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.