get scene data python

119 views
Skip to first unread message

Matias Volonte

unread,
Jun 7, 2012, 10:40:37 AM6/7/12
to python_in...@googlegroups.com
Hello everyone,

I would like to get scene data (size, number of vertexes, faces, or anything else) and print it in a panel. I have a panel with textscrolllists and I want to have that information when I select files, can anyone give me any tip to follow, thanks.

Justin Israel

unread,
Jun 7, 2012, 11:27:48 AM6/7/12
to python_in...@googlegroups.com, python_in...@googlegroups.com
What you are probably looking for is to create a scriptJob that fires your update function every time the selection changes: 

They have both an event and a condition for this that are similar and they show the condition example in that doc link

jobid = cmds.scriptJob(ct=["SomethingSelected", updateMyPanel()])

...where updateMyPanel() is a callable you defined to check the current selection and update your panel. 

To get all that information, its a mixture of whatever commands you need for the object type. 



On Jun 7, 2012, at 7:40 AM, Matias Volonte <volont...@gmail.com> wrote:

Hello everyone,

I would like to get scene data (size, number of vertexes, faces, or anything else) and print it in a panel. I have a panel with textscrolllists and I want to have that information when I select files, can anyone give me any tip to follow, thanks.

Matias Volonte

unread,
Jun 7, 2012, 4:07:22 PM6/7/12
to python_in...@googlegroups.com
Justin thanks for answering. I will definitely check what your suggestion. 

Also, I found a youtube video that shows a similiar concept to what I need. I would like to have a tool that access files and retrieves data (size, face amount, file path, etc) and image of the scene. I already have built the core of the tool, but for some reason is hard to achieve the scene data of the maya.mb's file.

Pseudo example:

Thanks and any tip will help.

Justin Israel

unread,
Jun 7, 2012, 4:28:24 PM6/7/12
to python_in...@googlegroups.com
What parts are giving you trouble specifically though? That video is really long as does a lot of stuff

Here are some examples:

# number of poly faces in scene?
faceCount = cmds.polyEvaluate(cmds.ls(g=True), face=True)

# path and file size of current scene?
import os
name = cmds.file(q=True, sceneName=True)
sizeBytes = os.path.getsize(name)




--

John Patrick

unread,
Jun 7, 2012, 7:28:16 PM6/7/12
to python_in...@googlegroups.com, python_in...@googlegroups.com
Without having watched the video ... If you're trying to read the contents of maya binary file externally, check out the mayabinary.py module in the python cg kit:
http://cgkit.git.sourceforge.net/git/gitweb.cgi?p=cgkit/cgkit;a=blob;f=cgkit/mayabinary.py;h=4706e64feb129924a42869ede3146a7496d68de7;hb=HEAD

You can subclass it and override the callback methods to retrieve particular chunks you're interested in.  You could write file metadata in a file-save callback using the fileInfo command, and retrieve it in the 'HEAD' group (I think the chunks are named 'INFO').  It can be a handy way to record character , environment, and other sorts of data that would otherwise require opening the scene.  Use the abort method after you're done reading the HEAD group so you don't parse the whole file.

If you're gzipping files, override the read method and use the gzip module to get a file-like object, then pass it into the read method of the base class.

JP

Sent from my iPhone

AK Eric

unread,
Feb 9, 2018, 2:15:52 PM2/9/18
to Python Programming for Autodesk Maya
Revive this old thread:  I tried using the mayabinary module, and, I'm getting no love, just running the built in example.  It seems like the mayabinary reader actually expects an iff (image) file instead.

> python mayabinary.py metaTest.mb
> ValueError: The file "C:\temp\maya\metaTest.mb" is not a Maya IFF file.

If I then go into the code and disable that check, I get this error:
> ValueError: The file "metaTest.mb" is not a Maya file.

Anyone got that code working?


Justin Israel

unread,
Feb 9, 2018, 3:30:23 PM2/9/18
to python_in...@googlegroups.com
What version of Maya are you using? Keep in mine that the mayabinary.py code doesn't show an update single 2010



--
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/428feaab-7ae0-49c6-b36e-a9aa3da60cf2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Feb 9, 2018, 4:27:33 PM2/9/18
to python_in...@googlegroups.com
I updated what I think is a flavour of mayabinary.py a while ago, though it's very rudimentary still.


On 9 February 2018 at 20:30, Justin Israel <justin...@gmail.com> wrote:


On Sat, Feb 10, 2018, 8:15 AM AK Eric <war...@sbcglobal.net> wrote:
Revive this old thread:  I tried using the mayabinary module, and, I'm getting no love, just running the built in example.  It seems like the mayabinary reader actually expects an iff (image) file instead.

> python mayabinary.py metaTest.mb
> ValueError: The file "C:\temp\maya\metaTest.mb" is not a Maya IFF file.

If I then go into the code and disable that check, I get this error:
> ValueError: The file "metaTest.mb" is not a Maya file.

Anyone got that code working?

What version of Maya are you using? Keep in mine that the mayabinary.py code doesn't show an update single 2010


--
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.

--
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/CAPGFgA1QePi0cgCPqNEAvtKzPtt5zHPzEvA45RJNqMU8i%3DOdnw%40mail.gmail.com.

AK Eric

unread,
Feb 9, 2018, 6:01:22 PM2/9/18
to Python Programming for Autodesk Maya
Thanks, I'll take a look at that too.  I'm on 2016, so yah, maybe the file format has changed since then.  This is actually related to another issue, I'll start a new thread for it.
Reply all
Reply to author
Forward
0 new messages