PDA

View Full Version : programming a little joke inside my window


deadalvs
12-29-2007, 04:13 PM
i am programming a rather large window with lots nice stuff for our landscape architecture office...

now since i will leave the company in march, i am currently rewriting the whole baby.

after i leave here, some other person will work with the script for our design process.

* * *

now i'd like to build in a little pop-up that tells the user at 9:30 am and at 4:00 pm that it's time for a coffee break.

i want this to work only when the window window exists, not while the normal maya session...

would i do this with a script job ? the popup should then disappear when hitting "ok"

thanks for any input !

hehe... :applause:

Gravedigger
12-29-2007, 04:38 PM
i've never thought about anything like that :-D

is it possible to get the system time in maya? maybe you'll need to write a plugin for this but i'm not sure. easier would be to use the system () command to execute a little programm which returns the current system time.

you could implement the whole thing outside of maya. so write a little programm that checks for a specific system time. if it's time for the popup the return value is true else it's false. then in maya you could write a scriptjob which checks for the return value of the program and opens the popup if the return value is true. you should create the scriptjob when your main script is opened and delete the scriptjob when it's closed so it won't disturb during working in maya.

there surely are better solutions. but this could be a working method to do it.
if there is a function to get the current system time in maya you do not need a programm outside maya.

what os do you use in your office? if there are different ones it gets a bit complicated because you'd first have to check what os is running and then using the system () command to the programm. if your office uses windows exclusivly it won't be a big problem because i could quickly write such a program for you.

if you need any help with programming just ask.

Iconoklast
12-29-2007, 06:00 PM
In Maya 8.5 on Windows Vista, the command System "time"; works.

Example output:

system "date";
// Result: The current date is: Sat 12/29/2007
Enter the new date: (mm-dd-yy) //
system "time";
// Result: The current time is: 9:59:43.26
Enter the new time: //

Gravedigger
12-29-2007, 06:12 PM
well then it should be quite easy to implement.
thanks iconoklast! your post makes live far easier :D

deadalvs
12-30-2007, 06:53 PM
thanks guys till now ... :)

* * *


i still have this problem with scriptJobs...

as seen in this thread here:
http://forums.cgsociety.org/showthread.php?f=89&t=573174

* * *

well. getting the time and splitting up to hours and minutes is not a great problem, but i still have not been able to figure out how to put that stuff into a properly working script job that checks for itself ...
:banghead:
i have tried with the «condition» command, but this node also gets not updated automatically... hmmmmmmm... :(


code so far:


int $booleValue = `isTrue checkCoffeeTimeCondition`;
//scriptJob -kill $scriptJobID;
//scriptJob -listJobs

condition
-initialize
-s "checkCoffeeTime"
checkCoffeeTimeCondition;
//condition -delete checkCoffeeTimeCondition;


int $scriptJobID = `scriptJob -conditionTrue checkCoffeeTimeCondition "showPauseWin"`;


//checkCoffeeTime;
global proc int checkCoffeeTime(){
string $RealWorldTime = `system "time"`;
string $buffer[];
$numTokens = `tokenize $RealWorldTime ":" $buffer`;
int $RealWorldHour = $buffer[1];
int $RealWorldMinute = $buffer[2];
if ( (($RealWorldHour == 10) && ($RealWorldMinute == 00)) || (($RealWorldHour == 16) && ($RealWorldMinute == 00)) ){
return 1;
}
return 0;
}

global proc showPauseWin(){
if (`window -exists "coffeeTimeWindow"` == 1){deleteUI "coffeeTimeWindow";}
window -title "coffeeTimeWindow" -width 250 -height 150 -mnb 0 -mxb 0 coffeeTimeWindow;
columnLayout -adjustableColumn 1;
text -l "";
text -l "";
text -l "it's time for coffee !";
text -l "";
text -l "";
button -l "okay, i'll get one!" -command "deleteUI coffeeTimeWindow;";
text -l "";
setParent ..;
setParent ..;
showWindow coffeeTimeWindow;
}

Gravedigger
12-31-2007, 02:48 PM
well the script works now!
needed some changes...


if(`scriptJob -ex $scriptJobID`)
scriptJob -kill $scriptJobID;
$scriptJobID = `scriptJob -e idle checkCoffeeTime`;

//checkCoffeeTime;
global proc int checkCoffeeTime()
{
string $rt = `system "time"`;
string $buffer1[];
string $buffer2[];
tokenize $rt "\n" $buffer1;
tokenize $buffer1[0] " " $buffer2;

$buffer2[2] = `substring $buffer2[2] 1 8`;
if ((`strcmp $buffer2[2] "10:00:00"`==0) || (`strcmp $buffer2[2] "16:00:00"`==0))
{
showPauseWin();
return 1;
}
return 0;
}

global proc showPauseWin()
{
if (`window -exists "coffeeTimeWindow"` == 0)
{
window -title "coffeeTimeWindow" -width 250 -height 150 -mnb 0 -mxb 0 coffeeTimeWindow;
columnLayout -adjustableColumn 1;
text -l "";
text -l "";
text -l "it's time for coffee !";
text -l "";
text -l "";
button -l "okay, i'll get one!" -command "deleteUI coffeeTimeWindow;";
text -l "";
setParent ..;
setParent ..;
showWindow coffeeTimeWindow;
}
}


there's no need of a condition node. you just need a scriptjob which checks every time when maya's idle if the given time is reached. then it opens the window. it's important to add the seconds to the checking because else your friend has to wait one minute until he can close the window without causing a new popping up.

the solution with using: system "time" is not a real nice solution. better would be writing a plugin to get the actual time but it's a bit too much just for one command. i'm not sure if `system "time"`returns the same on a system with linux running on it. or maybe osx. but on windows it should work.

it would be nicer to write a little programm which returns the time nicely formatted. so you wouldn't need to double tokenize the string and the time checking would be much easier.

well the problem with this script is that there's a lot of checking so your cpu is used alot. there must be a better method than using scriptjob with the idle event. i try to find something but i've still some things to do for new years eve.

i wish you a happy new years eve!

deadalvs
12-31-2007, 03:11 PM
whoa, thanks a lot ! this helps very much...

young people impress me the more the older i get... hehe... :)

* * *

i had the thought that the minutes have to be checked too so no new window appears... but certainly i could not check it since the whole thing didn't work...
( the system, this script will be running on will be osX )

* * *

so we'll be around in '08 !
enjoy Your time and have a nice fiesta ! :)

deadalvs
12-31-2007, 03:12 PM
i have the idea that a pause could be implemented for the two time ranges. maybe this will take less cpu cycles...

well... just an idea...

Gravedigger
01-01-2008, 01:13 PM
hmm... i don't think this could work. the problem is that theres no event that fits for this problem.
you could programm a timerevent outside of maya but this gets a bit complicated just for a joke script

i don't really have any other ideas at the moment sorry

Iconoklast
01-01-2008, 02:17 PM
Only alternative I can think of would be to specify the script to run on a frequently used event, such as the OnSelectionChanged event. If someone's not changing their selection within a 1-2 minute interval, they're probably taking a break already anyway.

You could do a check to see if the the current time falls within a specific tolerance value (10 minutes after the set time) and if so then pop the window.

Gravedigger
01-01-2008, 03:06 PM
hey iconokast
i thought of that aswell. but the problem is that sometimes you aren't really working but it would be nice when the popup would appear anyway.

isoparmB
01-02-2008, 03:08 PM
With regards to time:

about -ct;

should do the trick.

deadalvs
01-02-2008, 05:09 PM
hey iso!

thanks for that precious input !

but that flag has indeed to be improved... even when maya works for this scriptJob only when idle ...

this is why i was working on a new type of event... the premade ones like idle or such are just too simplistic... :(

let me think some more...

BenBarker
01-04-2008, 10:45 PM
Haha, you had better make this rock solid or the new guy will think his predacessor was a jack-ass :D

CGTalk Moderation
01-04-2008, 10:45 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.