Introduction to Maya - Rendering in Arnold
This course will look at the fundamentals of rendering in Arnold. We'll go through the different light types available, cameras, shaders, Arnold's render settings and finally how to split an image into render passes (AOV's), before we then reassemble it i
# 1 14-12-2004 , 12:04 AM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695

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

# 2 14-12-2004 , 02:52 AM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
got it, used a combo or fprint and fgetline.

# 3 14-12-2004 , 09:16 AM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
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
# 4 14-12-2004 , 09:19 AM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
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.

# 5 14-12-2004 , 11:14 AM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
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.

user added image

Alan


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 6 14-12-2004 , 10:25 PM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
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.

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads