Call for Submission
NAB 2012 Best of the Best Show Reel
Submit your work today!
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / Another really basic python-maya question
  RSS 2.0 ATOM  

Another really basic python-maya question
Rate this thread
 
34029
 
Permlink of this thread   Subscribe to this thread
avatar
  • Ben VZ
  • Posted: 03 September 2009 01:57 PM
  • Total Posts: 7
  • Joined: 27 August 2009 06:34 PM

Sorry for the newbie question, but I cannot seem to find any examples in the documentation that explain this:

I am trying to get a camera matrix…

I am using this command:

cmds.xform("mmCam_Shape", q=True, matrix = 0)

but I just KNOW that is way wrong.

first off, I don’t know how to put myself into “query” mode.  I’m guessing that is what the q=True argument does but that is a TOTAL guess.

secondly, I want to query the matrix, not set it to all zero’s… but I don’t know how to tell the function that I am interested in this particular piece of info.

finally, the above command seems to run, but I just get an error:
RuntimeError: No valid objects supplied to ‘xform’ command.

but that camera shape IS in the scene.

Basically, there is a real disconnect between my understanding of the basic syntax of using the python api and what it really needs.  Could someone point me in the right direction?  Thanks.



Replies: 0
avatar
  • Ben VZ
  • Posted: 03 September 2009 02:57 PM

Aha,

after a lot of trial and error, I seem to have figured it out.

I should not have been handing it the Shape node, but rather the… um… not shape node… aka mmCam_ and not mmCam_Shape.  (I am still kinda new to the differences between the two… time to do some research).

Also, even though the docs would appear to have you supply 16 doubles to the matrix argument, you have to, in fact, just give it a boolean if you are in query mode.  Makes sense, but I have not been able to find the actual docs that explain it.

So the command that works is:

cmds.xform("mmCam_",q=True, matrix=True)

If you looked… thanks for looking.  Hope this helps another hopeless newbie out there.



Replies: 0
avatar

Ben VZ 03 September 2009 09:57 PM

Aha,
Also, even though the docs would appear to have you supply 16 doubles to the matrix argument, you have to, in fact, just give it a boolean if you are in query mode.  Makes sense, but I have not been able to find the actual docs that explain it.

In the User Guide - General - Python - Using Python there is a section on Flags (named arguments)

Flags are handled differently in Python than they are in MEL. MEL was designed with a shell command style syntax.

For Maya commands in Python, the command argument syntax has been adapted in a way that is natural for Python. As a result, flags—both long and short forms—are passed to commands as named arguments. The name of the argument is the flag name and the flag’s arguments are passed to the named argument.

Required arguments (True/False)

Named arguments must have a value associated with them. However, not all Maya flags require a value (for example, ls -sl). In order to maintain a consistent syntax, the Autodesk Maya Python implementation requires you to assign a boolean argument to those flags that do not normally take any arguments. If the boolean value is False, then the flag is ignored; if it is True, the flag is used. 

This is one of the main differences between MEL and Python.  In MEL you would use empty flags for query and the thing you were querying, something like

xform -q -matrix mmCam_

In Python you need to use:

cmds.xform("mmCam_",q=True, matrix=True)

The default value for any flag like this that is not specified is False.  (so you don’t have to go through and remember all those flags that you don’t normally set through MEL)

Also, the 0 that you set the flag to in your first example can be used instead of False, had you used 1 it would have worked.



Replies: 0




   
  Settings Choose Theme color: