PDA

View Full Version : Notes script problem


Adam
03-19-2006, 12:38 AM
hey guys, i'm pretty new to mel so this is prouably (hopefully) and easy fix. This script creates a window for you to write notes in. When you hit the save button it writes the text out to your file with the fileinfo command. The next time you run the script it searches for the fileinfo you wrote out and then creates the window and queries the fileinfo into it allowing for you to store notes in the file. The problem comes that when I query it in it include line breaks and /r but since the query doesn't include "" it just write the /n and /r in the window instead of actually returning and breaking (does that make sense). Try running it yourself. Enter notes in the window add some returns and more text and then click the save button. Rerun the script and you will see the problem. Help would be much appreciated.

$notes = `fileInfo -q "Notes"`;
window -s 0 notesWindow;
windowPref -h 265 -w 320 notesWindow;
columnLayout -adj 1;
scrollField -tx $notes -ww 1 -h 215 tF;
scrollField -e -tx $notes tF;
rowColumnLayout -nc 2 -cw 2 155 -cw 1 155;
button Save;
button Cancel;
showWindow notesWindow;
button -e -c saveProc Save;

proc saveProc()
{
$newNotes = `scrollField -q -tx tF`;
fileInfo -rm "Notes";
fileInfo "Notes" $newNotes;
}

RyanT
03-20-2006, 10:01 PM
So I tried to solve your problem. I think I am only part way there but this might help you along. So I found when you query the scrollField it is giving you a string such as "test\r\n1\r\n2\r\n3" this is bad. It has a rand a neweturn carriage line. What is wierd is if you actualy tell the scrollField that this is the string it will work. Open the note window you have and in the command line type:

scrollField -e -tx "test\r\n1\r\n2" tF;

But when you pass it a variable with this text in it, you get the newlines and carriage as text which they shouldnt be included as text.

My solution was to tokenize the string and remove the \n and \r in the string. This unfortunately has the ramifications of removing blank lines in your notes so if you hit enter twice to give space between notes that will get removed. Give it a try. I have to get back to work but hopefully this helps.


window -s 0 notesWindow;

windowPref -h 265 -w 320 notesWindow;

columnLayout -adj 1;

scrollField -ww 1 -h 215 tF;

scrollField -e -tx $notes tF;

rowColumnLayout -nc 2 -cw 2 155 -cw 1 155;

button Save;

button Cancel;

showWindow notesWindow;

button -e -c saveProc Save;

loadNotes();

proc loadNotes()

{

string $theNotes[] = `fileInfo -q "Notes"`;

string $buffer[];

$numTokens = `tokenize $theNotes[0] "\\rn" $buffer`;

string $newString;

$newString = $buffer[0];

for ($i = 1; $i < $numTokens; $i = $i + 1)

{

$newString = ($newString + "\n" + $buffer[$i]);

}

print $newString;

scrollField -e -tx $newString tF;

}



proc saveProc()

{

$newNotes = `scrollField -q -tx tF`;

fileInfo -rm "Notes";

fileInfo "Notes" $newNotes;

}



string $theNotes[] = `fileInfo -q "Notes"`;

$numTokens = `tokenize $theNotes[0] "\\r" $buffer`;

print $buffer;



-RyanT

Adam
03-20-2006, 11:52 PM
thanks ryan... I thought about doing it that way but was hoping there might be an easier solution. your method works pretty good all and all though. maybe I will just stick with

Adam
03-23-2006, 12:47 AM
well I managed to find a better way around making my notes with fprint but now that I'm finished I can't seem to fix this very minor problem. for some reason my script won't source through my main global proc. I want to make it so you don't have to source it each time you open Maya but for some reason right now you do even though i source it directly in the main proc. Also I really want ot do this sourcing through the script that way the script is easily installable.

Here is



global proc theNotes()
{
source "theNotes";
window -s 1 notesWindow;
windowPref -h 265 -w 320 notesWindow;
columnLayout -adj 1;
scrollField -ww 1 -h 215 tF;
rowColumnLayout -nc 2 -cw 2 155 -cw 1 155;
button Save;
button Close;
showWindow notesWindow;
button -e -c saveProc Save;
button -e -c closeProc Close;

string $FileName = (`file -q -sn` + "_notes.tmp");
$fileId=`fopen $FileName "r"`;
string $nextLine = `fgetline $fileId`;
while ( size( $nextLine ) > 0 )
{
$line = `scrollField -q -tx tF`;
scrollField -e -tx ($line + $nextLine) tF;
$nextLine = `fgetline $fileId`;
}
}
proc closeProc()
{
string $smell;
$dialog = `confirmDialog
-m "Do you want to save changes"
-button Yes
-button No`;
print $dialog;
if ($dialog == "Yes")
{
saveProc;
}
if ($dialog == "No")
{
deleteUI notesWindow;
}
}

proc saveProc()
{
string $scrollQ = `scrollField -q -tx tF`;
string $FileName = (`file -q -sn` + "_notes.tmp");
int $fileId = `fopen $FileName "w"`;
fprint $fileId $scrollQ;
fclose $fileId;
}

Adam
03-26-2006, 05:15 AM
Anyone....?
I would appreciate the help

A_New_Hope
03-26-2006, 08:22 AM
you cant source your script in your main proc because you need to source it to be able to run your main proc, so its a catch 22(?)

what you can do is add your script "theNotes.mel" to the \maya\7.0\scripts folder and it will be source when maya start.

Adam
03-26-2006, 08:02 PM
Thanks New Hope but I have already tried this. I know that scripts are suppose to be in the scripts folder so they source on start.. If I put it in my maya/7.0/scripts folder I can run the script by typing the theNotes into my command line but only the Global proc works. When I run the save proc through my global proc it can't find the proc. Same with my close proc. But if I open the script in the script editor and source it all of it runs fine. If someone could give it a try and see what happens it wopuld be appreciated.
.

goleafsgo
03-27-2006, 12:35 AM
The only type of proc that you can call in a file is a global one. The non-global procs inside the file can be called from the global ones. So, in your case, if you want to be able to call the save proc you have to make it global.

Pretty much everything that you execute from the script editor gets made global automatically so that's why it works when you do it from there.

Adam
03-27-2006, 04:17 AM
thanks goleafsgo that works.

CGTalk Moderation
03-27-2006, 04:17 AM
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.