Re: [Maya-Python] Re: Basic question about pyMel

2015-03-25 Thread Jesse Kretschmer
There have been some great explanations here already, but I felt like
chiming in still.

The line of code in your example is a bunch of methods chained together (method
chaining http://stackoverflow.com/questions/1103985). Each returns a new
object and then you call a method on that object. It is possible to rewrite
the code in an expanded view. This creates more variables, but it should
make it more obvious as to why you are only adding one pm. prefix.

Here is the code expanded:

cameras = pm.ls(type='camera')cameraTransform =
cameras[0].getParent()transformMatrix =
cameraTransform.getTranslation()print Value of z: %s %
tranformMatrix.z

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CANESWi32gubjin8xm1V6YQWDn%2B1uYgmsYZ-dgDQQrnO06t2H2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: Basic question about pyMel

2015-03-24 Thread Robert White

Nope this wouldn't work:

pm.ls(type='camera')[0].pm.getParent().pm.getTranslation().z


Instead you'd need:

pm.ls(type='camera')[0].getParent()..getTranslation().z


Its only the initial function that gets prefixed with the module namespace.

On Monday, March 23, 2015 at 12:59:00 PM UTC-5, Simon Davies wrote:

 Hi all,

 I understand that if I import pyMel into Maya like this:

 from pymel.core import *

 I can then build up pyMel functions like this:

 ls(type='camera')[0].getParent().getTranslation().z


 However if I import pyMel with a name space instead:

 import pymel.core as pm

 Would the pyMel methods above all need prefixing with pm like this?

 pm.ls(type='camera')[0].pm.getParent().pm.getTranslation().z


 The above code doesn't work, so how should it be written if I import pymel 
 as pm?

 Thanks a lot.


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/c4f4b6ff-427c-462a-a31f-d4be95354cf2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.