fopen warning - unable to open for mode "a"


#1

I’m working on writing rotation information of several objects to a text file, and then in turn reading them back. Following the tutorials from scriptswell I was able to read from a file, but writing to it has cause a bit of a stumble. When I run the following lines of code (Subbing out the path and file with an actual file and path):

proc myProc(){
	string $myString = "Hello World";
	string $myFilePath = "C:/PATHNAME/FILENAME.txt";
	$myFileID = `fopen $myFilePath "a"`;
	fprint $myFileID ($myString);
}

I get this error:

// Warning: line 4: fopen: unable to open file "C:/PATHNAME/FILENAME.txt" for mode  "a". // 

This also happens if I swap the append mode for write, but with the error saying it can’t open for mode w. I am able to read from this file just fine, I’ve tried placing it in the scene folder of the current project, and running Maya as administrator, and neither has made a difference.
I’m going to try on a different machine, and see if I can get that going, but any advice would be welcome!


#2

Does the directory exist?


#3

It does I can open the file in read mode, but write or append throw errors, I can even copy paste the address and filename into explorer and it will open the file in notepad. Also tried swapping out the “/”'s with “\”'s just to see and it still had the same issue.
On a whim just now, I tried running the script in a full version of Maya (I use LT but have an old educational version still running on my home machine), and it works just fine. Quick look around revealed that while both full and LT versions of Maya can run melscript, LT is limited in the commands it has access to (It can’t access features un-available in full Maya of course!) I’m not sure why fopen works in read mode, but that command is not listed in the documentation for LT, so I’m figuring for some reason it is not supported. Looks like your supposed to use fwriteAllLines or fwriteAllText. I’m gonna send in a support ticket to see if there is a specific reason for this, I’ll update here if I get a response.
Thanks for the ideas though!


#4

Does Maya LT allow you to run Python?
Then you could possibly use the Python functions to write into the file.


#5

Unfortunately LT does not have Python support, otherwise I would be all over that! LT’s melscript does support overwriting the contents of a text file, but it looks like it may have some character limits. I was attempting to store rotation information externally, but I think I’ll be able to get around it by just save the information as a number of keyframes, and then exporting those keyframes through an fbx if I need to move the information between files.