PyMel - Way to check if a ma or mb file has written properly?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  07 July 2012
PyMel - Way to check if a ma or mb file has written properly?

First maya job after 19+ years in another package.... Learning PyMel. Loving it.

I'm writing a scene setup tool that also saves the scene file in the right place with properly structured file naming.

While writing it, I was working locally and hacked together a quick way to test if the file was actually written. I used time.time() to grab the current time, wrote the file and then grabbed time.time() again and tested the file modification time to see if it was between the 2 other times. BUT it only works locally obviously since the server time being only a few seconds different from the local machine time would make this test totally ineffective.

Does anyone have a good PyMel way to test if the file has actually been written/modified?

Not bad. For a hughman.
  07 July 2012
Suddenly towards the end of the paragraph you suddenly have a server... Please explain from the beginning your exact situation, and why you actually need to test if a file was written in a resolution of a few seconds. In the meantime my guess is that you should query the time from the server.
  07 July 2012
You're a funny guy. The server was always there. But if I mention the server first, then other stuff will come later which you might think suddenly appears later in the paragraph. The dilemma of having to mention everything first is melting my brain. But enough with the silliness, here is the question with the order of stuff changed for you.

I have a server. I'm writing .ma and mb files to a drive on that server using the PyMel command pm.system.saveAs(theFilename). I would like to implement some sort of checking to see if the file was saved properly. The only way I could think of was to query modification time. But I don't know how to query the time on the server. Can you help me? Or is there a better way? I'm already checking if the file exists, but the file could have existed before I tried to write it and may have failed for some reason like the file being read-only, so modification time was the best way I could think of with my limited experience with Maya/PyMel.
Not bad. For a hughman.
  07 July 2012
You should have first mentioned that you have a server, then continue that it's your first maya job for 19 years... I just didn't understand at first what exactly is the server role, and when I read the server, I tried to look for a previous reference to it.

To your problem. First you could query the server time using

I think that your server should run a NTP service by default, but if not just add one to it (you could also write your own time service for the server).

But there should be a simpler solution. I'm not sure which protocol (ftp?) do you use to access the files on your server, but most of them should support a query to the update time of the file. Thus first you should query this time, write the file, and read the time again for comparison.
  07 July 2012
doesn't the save function return a success or failure error code?
  07 July 2012
NaughtyNathan, I don't know. I'm looking into it now though.
I can't see any return code. I just did a quick test with the code below and didn't get anything pop up in the script window other than the code I ran.
import pymel.core as pm
  theFilename = "C:/t/"

On a side note, why does some of my code show up here with spaces at the front on here? I've edited it a few times to sort it out, but it keeps putting TABs and spaces in where there are none.

Not bad. For a hughman.

Last edited by 3rd Dimentia : 07 July 2012 at 01:45 AM.
  07 July 2012
It doesn't look like you are sending a file to save on a server, but doing it locally. So again you didn't elaborate on the process of how a client computer sends a file to a server to save.

Anyhow, if you'll try to save for example an illegal file name in 2013:


an exception is thrown:

# Error: RuntimeError: Could not save file "/8/aa*.ma".

In earlier versions it might return the save file name on success (according to which pymel should imitate). Try to play with it or go to the doc and look for the return value.
  07 July 2012
Hi Cg, did you find a good solution yet?
As far as I know, the saveAs and saveFile commands return the name of the saved file if it is successful. These commands will fail with "RuntimeError" if the file exists and is read-only. Probably the same type of fail for other reasons. Its a pity these errors are not more specific.

I would have not thought of checking the time stamp. I'm not even sure I would trust it. I've never noticed this on scene files, but often the jpgs that I playblast seem to retain an old time stamp when I write over the top of old sequences.

Did you consider checking the file size before writing to it, and then again after? I'm making the assumption that it is probably rare to end up with an identical size if something changed in the scene since the last write.


oh... just in case you were wondering, I think I also have a server...
  07 July 2012
You're famous djx. Your stuff was mentioned in Alex Alvarez's new paint fx tuts!

Carrying on.....
  07 July 2012
this is probably a dumb idea, but...

maya ascii files always end with:

// End of <filename>

You could test that the last line of the .ma file starts with "// End of".

Not sure what to do in the case of a binary file tho...
  07 July 2012
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

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
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 05:58 AM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.