If .ma is an option, then it supports comment blocks.
// Comment here
...
addAttr ...
connectAttr..
A perhaps more common approach might be to store metadata relative an absolute path in a database.
{
"c:\path\to\some\file.mb": {
"any": "data",
"here": True
}
}
Then you can query files and metadata somewhat similarly.
fname = r"c:\path\to\some\file.mb"
with open(fname) as f:
f.read()
with metadata(fname) as f:
f.read()
Where metadata()
is a function of your own design, for example..
import contextlib
import mongo
@contextlib.contextmanager
def metadata(fname):
return mongo....find_one({"fname": fname})
Leaving out the details of how to communicate with the database for brevity.
Well if you like your MB and your current json/xml file solution but just want them tied together so they don't get disconnected you may want to consider just using a .zip to bind them. Uncompressed they can be very fast and you can access files directly (to query your metadata etc) without having to extract the zip with python. You'll just need a bit of code to enable opening/saving them back together.
https://docs.python.org/2/library/zipfile.html
Ian
Marcus: MA not an option, so no comment blocks, but thanks, good idea. However, I like your idea of just writing data to somewhere on the server that corresponds to the Maya file in question. That could be a legit answer. not tagging the file with metadata itself, but the data isn't living next to the Maya file itself, which I find scary :PJuan: Your thought has merit, and technically I could do it with a pre-scene-open callback. Would be worth a test to prove out, but it's a little scary that unless that callback fires, your scene is garbage. However, it does make for an interesting way to copy-protect in-house data....
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4485d4ba-a768-4116-a1da-87445e01da69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
By golly, that does actually work!
from maya_scenefile_parser import MayaBinaryParser
fname = "C:/Users/marcus/Desktop/temp.mb"
class Parser(MayaBinaryParser):
def on_file_info(self, key, value):
print("%s = %s" % (key, value))
with open(fname, "rb") as f:
parser = Parser(f)
parser.parse()
Output:
mykey = myvalue
application = maya
product = Maya 2015
version = 2015
cutIdentifier = 201503261530-955654
osv = Microsoft Windows 8 Enterprise Edition, 64-bit (Build 9200)\n
Where mykey = myvalue
was added via cmds.fileInfo("myvalue", "mykey")
before saving the mb
file. Tested on a file saved with Maya 2015.
Nice one, Alok!
> To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/065048f8-05b6-beea-10d1-2302693168d2%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/64C17806-7F48-456D-B05B-01DA327C8106%40gmail.com.To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Thanks Alok & Marcus: I tried that code and it does indeed work. Nice job on the scenefile parser Marcus!
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/6c44d89c-d1c5-4c93-9ffa-d2466b6b9617%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/563ef7ef-a5a4-4007-aa2d-f978cf569aff%40googlegroups.com.
Basically you can write anything to your “c:/project/mayascene.mb:trololo”, “:attr1”, “:whatever” even with the shell commands, or your file manager.
Sounds interesting! Would you be able to post an example?
Basically you can write anything to your “c:/project/mayascene.mb:trololo”, “:attr1”, “:whatever” even with the shell commands, or your file manager.
Sounds interesting! Would you be able to post an example?
@echo off
copy c:\windows\explorer.exe test_subject.txt
dir /r
pause
type c:\windows\win.ini > test_subject.txt:attr1
dir /r
pause
more < test_subject.txt:attr1
import sys, os, shutil, subprocess, time
curdir = os.path.dirname(__file__)
target = os.path.join(curdir, 'test_subject.txt')
target2 = os.path.join(curdir, 'test_subject.txt:attr1')
shutil.copy2('c:/windows/explorer.exe', target)
os.system('dir /r')
time.sleep(3)
shutil.copy2('c:/windows/win.ini', target2)
os.system('dir /r')
time.sleep(3)