Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 14-12-2004, 12:04 AM   #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, 02: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, 09: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, 09: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, 11: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, 10: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
Reply


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 03:45 AM

Thread Tools





A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.