PDA

View Full Version : Displaying the simulation time with the various date/time formats.


Regan Blackett
08-03-2007, 10:35 AM
This can be accomplished with the use of a VisualTool object. Simply drag a VisualTool into your model and set it display text. Under "Text Display", choose "Display Time". The code inside gives good ideas about how to display on-screen texts.

If you want to compute the week and day using code, you can do following:

double startTime = 0;
int week = (time()-startTime)/7/24/3600;
int day = (time()-startTime-7*24*3600*week)/24/3600;
In order to display week and day in the VisualTool, replace the code in the Text Display with the following:

treenode current = ownerobject(c);
treenode textnode = parnode(1);

/**Display Time. Format - Week w, Day d*/
double startTime = 0;
int week = (time()-startTime)/7/24/3600;
int day = (time()-startTime-7*24*3600*week)/24/3600;

string timetext =
concat(
"Week ",
numtostring(week,0,0),", Day ",
numtostring(day,0,0)
);

setnodestr(textnode, timetext);

Dan Cremer
08-11-2008, 07:14 AM
Regan:
This did not work. When I started running the model, the date did not change from "Week 0, Day 0".

Pablo Concha
08-11-2008, 08:00 AM
It does work for me, code assumes you're working on seconds, so it may take a while to change days/weeks if you're running the model slow (86400 time units for each day).. you can change the 3600 on the model for 60 to work in minutes... or 1 in hours, etc...

regards,

Pablo Concha E.

Dan Cremer
08-19-2008, 05:40 AM
I meant to thank you sooner for your reply.

JMEngelhart
10-24-2008, 08:23 AM
How about if I want to display the Day of the week - ie: Sunday, Monday, etc.?

Pablo Concha
10-27-2008, 08:41 AM
How about if I want to display the Day of the week - ie: Sunday, Monday, etc.?

Hello,

I think this works... (working on minutes)....


treenode current = ownerobject(c);
treenode textnode = parnode(1);

/**Display Time. Format - Week w, Day d*/
double startTime = 0;
int week = (time()-startTime)/7/24/60;
int day = (time()-startTime-7*24*60*week)/24/60;

string daystr;

switch(day)
{
case 0: daystr = "Monday";break;
case 1: daystr = "Tuesday";break;
case 2: daystr = "Wednesday";break;
case 3: daystr = "Thursday";break;
case 4: daystr = "Friday";break;
case 5: daystr = "Saturday";break;
case 6: daystr = "Sunday";break;
}

string timetext =
concat(
"Week ",
numtostring(week,0,0),", ",
daystr
);

setnodestr(textnode, timetext);
regards,

Pablo Concha E.

Albert Munoz
10-26-2010, 03:42 PM
Any chance you could describe how to have this display on a GUI?

Thanks
Albert

Phil BoBo
10-26-2010, 04:56 PM
You can do this with a hotlinkx on a static control in a GUI.

Use setviewtext(c,timetext) instead of setnodestr(textnode, timetext)

See the attached model.

Albert Munoz
10-26-2010, 07:55 PM
Thanks Phil,

I am having trouble opening the attached model, when I open it, the system console displayes the following message;

exception: Exception caught in flexscript execution of VIEW:/nodefunctions/menucommands/File/openmodel line 44 instruction 109. Discontinuing execution.

Phil BoBo
10-27-2010, 09:46 AM
Is anyone else having this problem? The model is opening fine on my computer.

Make sure you have the latest version of the software (5.0.4).

Pablo Concha
10-27-2010, 11:24 AM
no problem here, (v 5.04)

regards

Pablo Concha Erilkin

Albert Munoz
10-27-2010, 09:54 PM
Sorry, I am running on Version 5.00 in a computer where I have no admin priviledges. I have contacted the admin of the university faculty where the licenses are stored, hopefully this can be remedied soon.

Thanks
Albert