I have written a procedure that checks for data stored under a title in a file and if present puts the data into MAYA in the form of slider values. This all works fine but what I need to do now is to allow the user to alter the sliders and thus overwrite the data on the file when an "update info" button is pressed.
With this in mind I open the file using fopen "filename" "r+" and this reads in fine but when I want to write info back into the file it ignores this completely although test messages inserted into the code show that it has reached and passes the relevant parts of the code quite happily. I am getting no error messages or warnings when running, it simply does not alter the file.
I thought that "r+" would allow both reading and writing I cannot use "w+" as this blanks the file (not a good idea!)
Any help gratefully received.
Thanks
Tricky
I don't know if this is the best way to do this, but when I need to do this I make a temp duplicate of the file I'm changing. Then I read from the temp file and write over the original line by line, changing the parts that I need to. Then I delete the temp file. It's kind of a pain but it works. I'd love to know if there is an easier way.
What I would do is to move to the old file and rename it to .bak or .old and then write a new file with the same name as before and then delete the .bak.
U can store the contents of file in an array of strings. By this way u won't have to read the file and you won't need any file managment system as well.
U may use array functions as well.
Perspective
"There is always a way around, you just have to see it from a different angle"
Array option is a substitute for temporary file.
Perspective
"There is always a way around, you just have to see it from a differrent angle"
thanks for the help everyone,
If I use the temporary file workaround is there then a way of renaming and deleting files using MEL? If not how can I get rid of the temporary files created?
Thanks again
Tricky
After re-reading your original question it sounds like using arrays to store stuff may be easier. Look into the 'optionVar' command. It will allow you to save values with your maya preferences and is very handy for what it sounds like you're doing.
If you still want to do the file thing you can use the 'system' command to do DOS stuff like copying, renaming, and deleting files. I have some useful scripts for these that don't care if you use front or back slashes in the file paths. I'll try to upload these later this week as I don't see any other scripts that do that here.
Thats great, thank you very much, I need to stick with the files since I am writing an interface with a text file based program.
Have now sorted the temp file deleting using system() as suggested and by using toNativePath() to sort out / problems. 