SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Animation / Mel Scripts & Programming / writing a text file
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 13-12-2004, 11:04 PM   #1
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default writing a text file

OK, since you all have been so helpful in my endeavours to get my MEL chops up to par, I'm back again with another question.

I'm trying to write out a text file that lists most of the render globals. I've basically got everything working except for one major problem. I've tried using both fwrite and fprint, but they both only seem to append the specified file.What I need to do is either overwrite the file, or erase the file before re-writing it. Anyone have any thoughts on how to do that?

Thanks again,
-dann
Dann is offline   Reply With Quote
Old 14-12-2004, 01:52 AM   #2
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

got it, used a combo or fprint and fgetline.
Dann is offline   Reply With Quote
Old 14-12-2004, 08:16 AM   #3
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

int $fileid = `fopen $filename "w"`;
fprint $fileid "my lines of code whatever I want to write \n";
fclose $fileid;

That's how you do it.

Alan
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
Old 14-12-2004, 08:19 AM   #4
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

yup, that's part of it, but that appends the file so i had to do a lot more to replace lines within the file. Thanks though.
Dann is offline   Reply With Quote
Old 14-12-2004, 10:14 AM   #5
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

no it doesn't:

open to write (will overwrite the file)
int $fileid = `fopen $filename "w"`;

open to append to the file
int $fileid = `fopen $filename "a"`;

//from the docs
"w" open file for writing (destroys prior contents of file).
"a" append for writing (appends to end of file).
"r" open for reading.



Alan
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
Old 14-12-2004, 09:25 PM   #6
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You are absolutly correct! I could have sworn I tried the "w" and had it append my file. I still had to read some elements of the file into varibles before clearing it, but "w" is cleaner than using a system command to delete the file first.

Regardless, thanks for the help.
Dann is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open a Lightwave file in Maya 2011 radiant777 Maya Basics & Newbie Lounge 2 04-12-2010 02:45 AM

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.