reading fileInfo from binary scenes

427 views
Skip to first unread message

bbdea...@gmail.com

unread,
Oct 22, 2013, 12:36:55 PM10/22/13
to python_in...@googlegroups.com
I need a standalone script that reads fileInfo data from binary scenes.
I tried using cgKit mayabinary class but I'm not sure how to parse bin
data chunks.
Any tips ?

thanks

Justin Israel

unread,
Oct 23, 2013, 5:01:19 AM10/23/13
to python_in...@googlegroups.com
I don't have much experience trying to parse maya binary files, and cgkit doesn't give any indication really of how to handle the groups and chunks beyond it just giving them to you in the callbacks... But a quick google search turned up this mayatools python package:

Pretty easy to grab and install. And it seemed to easily hand you the chunk and data objects in at least a meaningful way for dealing with the fileinfo portion.

$ cd mayatools
$ python setup.py install

$ python
>>> from mayatools.binary import Parser

>>> f = open("sphere.mb")
>>> p = Parser(f)
>>> p.parse_all()

>>> p.pprint()
# Maya group (FOR4); 64336 bytes for 31 children:
#    HEAD group (FOR4); 344 bytes for 16 children:
#        VERS; 4 bytes as string(s)
#            0020: 32303133                    '2013'
# ... snip ...
# Produces a huge dump of the file structure,
# indicating that the tag we are interested in
# is the first group, called "HEAD"

>>> head = p.find_one('HEAD')

>>> head.pprint()
# HEAD group (FOR4); 344 bytes for 16 children:
#     VERS; 4 bytes as string(s)
#         0020: 32303133                        '2013'
#     UVER; 5 bytes as string(s)
#         002c: 756e6465 66                     'undef'

# Then just deal with the child chunks?
>>> head.children
>>> head.find(...)

Not sure if that was what you are after.





--
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/a2e99d69-95fc-4091-887d-cb9a48b3f366%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

f.michal

unread,
Oct 23, 2013, 1:58:38 PM10/23/13
to python_in...@googlegroups.com
W dniu 2013-10-23 11:01, Justin Israel pisze:
> I don't have much experience trying to parse maya binary files, and
> cgkit doesn't give any indication really of how to handle the groups
> and chunks beyond it just giving them to you in the callbacks... But a
> quick google search turned up this mayatools python package:
> https://mayatools.readthedocs.org/en/latest/binary.html

That perfect !
Here's a braindead snippet to get fileInfo as a dictionary:

def ExtractFileInfo(fPath):
RES = {}
f = open(fPath)
p = Parser(f)

Chunk = p.parse_next()
max_cnt = 100
fileInfoBlockFound = 0
while( Chunk and max_cnt ):
max_cnt -= 1
if(fileInfoBlockFound == 1 and Chunk.tag != "FINF"):
break

if(Chunk.tag == "FINF"):
fileInfoBlockFound = 1
bits = string.split( str(Chunk.string), '\x00')
RES[bits[0]] = string.join(bits[1:], ' ')

Chunk = p.parse_next()

return RES



Reply all
Reply to author
Forward
0 new messages