Maya beginner confused by nodes and MayaCommands


#2

If you give examples about what you are talking, I can give explanations about them.
Because unlike MEL or C++, there are more ways to achieve same result for Python and I cant guess which one you are talking.


#3

You are right, that’s simply wrong. The command returns the creator node and the transform node, not the shape node. Unfortunately I do not really understand your second question. What exactly do you mean by “identifying the object”? And if a node does not have a radius attribute, you cannot edit it. But of course you can add arbitrary attributes to any maya node and modify these. So you can add a radius float attribute to a polycube. Of course this new attribute has no effect at all.


#4

I think he means the way some commands seem to find the proper node even when you supply the name of the transform instead of the mesh, or vice versa. For example even though radius is an attribute of the polySphere node, you can query it using any of 3 names and it returns the correct value:

nodeNames = ['pSphere1', 'pSphereShape1', 'polySphere1']

for name in nodeNames:
    radius = cmds.polySphere(name, q=True, r=True)
    print radius

I guess the implementation of some commands tests arguments and figures out which node to operate on based on type and connections. But I’ve never seen any docs that specify in which cases this is supposed to work and which it isn’t.


#5

Btw what is an advantage of having separate shape and transfom nodes, for example as opposed to the transform being an attribute of the object?

To me it seems to cause mostly programming overhead


#6

If transforms were designeld as attributes, we would need multi dimensional attributes to modify them since they already have attributes and MEL multi dimensional arrays are limited by choice. I may be wrong about this but even if it wasnt, it would be slower than the current way.
polySphere finds correct node to make the job easier for people who are not programmers, the correct node name above the example is polySphere1 as you can guess. By the way it is actually a MEL code wrapped by Python.
As I already talked about, there are more libraries in Python and each library has its own purpose, vision, etc. The confuse comes from mixing different libraries I think but this case is only for Python since it has some kind of wrappers both from MEL and C++.


#7

Not sure if I understand you correctly, but all commands in the docs show the C, Q and E letters which shows you clearly if you can use the argument only at 'C’reation time, 'Q’uery it or 'E’dit it.


#8

I see no reason for a multidimensional attribute. There is no reason why a direct implementation of the transformation matrix should not work on a shape node. And it would not be slower because the final operations are exact the same. Seperating the transformation from the shape is simply a design decision. It makes life easier if you have complex hierarchies and on the other side if anyone wants to create a new shape node, he does not have to care about any transformations.

polySphere finds correct node to make the job easier for people who are not programmers, the correct node name above the example is polySphere1 as you can guess. By the way it is actually a MEL code wrapped by Python.

Not really. You are mixing pymel and maya.cmds. PyMel is indeed a wrapper for most mel commands (and a really good one). maya.cmds as used above are python commands, not wrappers.

some kind of wrappers both from MEL and C++.

I don’t think that there exist something like a wrapper for C++, at least not for Maya. The python interface offers a direct access to the maya API via native python commands, it has nothing to do with C++.


#9

First of all I agree about the design choice and making easier complex hierarchies. That was what I talking about by multi dimensional attributes. With separate nodes, we dont have to care about dependency.

The official and latest Autodesk developer page says that maya.cmds is a Python wrapper for MEL and Pymel is an alternative Python wrapper for MEL.
http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=GUID-C0F27A50-3DD6-454C-A4D1-9E3C44B3C990

The official and latest Autodesk developer page also says maya.OpenMaya and maya.api.OpenMaya are Python wrappers for the Maya C++ which are defined as version 1 and 2.
http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=GUID-C0F27A50-3DD6-454C-A4D1-9E3C44B3C990

The only native commands are C++ because it is a native language by nature.
Python is indeed gives access to native C++ commands but not direct instead by wrapping them. There cant be native Python commands anyway because Python is not a native language by nature.
Remember native contains compilers.

It wouldnt be slower for C++ but would be slower for interpreted languages like Python and MEL because of the dynamic creation of objects and memory management.
You wouldnt notice a difference for a few objects though but you would notice when you are in a certain number of loops.


#10

In which way does having separate shape and transform nodes simplify complex hierarchies - so you can have a transform without a shape?

Still would dare to say it doesn’t outweight the hoops you have to jump through with this construct.


#11

Hi,
answering to CanerOzdemir51 and haggi too I say “yes”: this is what I mean :slight_smile:
Testing the line of code of the book I saw that I can use the command in edit/query mode supplying the node of any node related to the mesh. It works with transform node name, construction node, shape node…
This quite confused me because I was trying to learn that a node has specific attributes and that I should address it.

I’m now sure that giving the polySphere command a name at creation time actually set that name for the transform node.
BTW, as shown here the name is not crucial while editing an attribute.It sound “disturbing”… Is it really possible to mess things this way? :slight_smile:

cmds.polySphere( n='mySphere')
cmds.polySphere('mySphere', e=True, r=30)
# Result: u'Values edited.' #
cmds.polySphere('mySphereShape', e=True, r=10)
# Result: u'Values edited.' #
cmds.polySphere('polySphere1', e=True, r=3)
# Result: u'Values edited.' #

#12

In maxscript each mesh is a node and something like “$meshname.transform.position” gives you the location of the object in one shot. I have to admit I find this way of design more simple and more similar to my previous coding knowledge.


#13

meshes have no direct positions on maya I suppose.
meshes have pivots and pivots have positions.
pivots also have more attributes.
there are two default pivots for rotation and scaling, you can extend on your mesh by adding more pivots or create simple locators which can be used as pivots.
maya can seem complicated at first but when you jump into a complex project you will see its benefits.


#14

My old knowledges as programmer are quite faded in time but… does this mean that any command called from maya.cmds is actually a MEL piece of code?
From the book I understood that MEL and Python could communicate with the Maya Command Engine to acces data from the core, but not that che Command Engine itself was basically… MEL :slight_smile:


#15

https://en.wikipedia.org/wiki/Wrapper_library
One of the reasons of wrapper libraries as defined enabling cross language and/or runtime interoperability and allow different piece of codes to work together.

It is not just for Maya
Softwares are built in one brain.
That brain is MEL for Maya.
However procedural MEL can be limited for some situations, that is why it can be quickly extended to Python by thin wrappers so you can use its object-oriented advantages, more libraries, so on and so forth.

But the OpenMaya wrapper is different, it gives access of C++ codes as haggi told.
Learning OpenMaya is a harder challenge if you are a beginner. People generally mix different libraries and use OpenMaya when they need more performance or flexibility.
http://radks.blogspot.com.tr/2012/08/performance-comparison-mel-vs-pymel-vs.html

You can also use native C++ to get inside of that brain and develop highest performance AAA plugins but it will be the hardest challange. You can start with MEL and when you are ready you can jump to Python or C++. Anyway you will need to learn MEL for both of them.


#16

haggi, I meant a reference or set of rules as to which commands you can expect to automatically “convert” the node name if you feed them the wrong one. For instance, unlike polySphere, xform doesn’t do it:

cmds.xform(‘pSphere1’, q=True, scale=True) # returns the scale
cmds.xform(‘pSphereShape1’, q=True, scale=True) # Error: RuntimeError: file <maya console> line 2: No valid objects supplied to ‘xform’ command. #

As far as I can tell there doesn’t seem to be any overarching rule, it’s just on a case-by-case basis.


#17

Ah, okay. So if you don’t know which type of node you have, you do not know which type of attribute you can query or edit. An automatic conversion does not exists and would be a problem because maya does not know if you use this node by intention or not.

In most cases you do not operate on an arbitrary set of nodes, but only on certain ones. e.g. if you want to modify translation of all nodes you will not do this:

allNodes = pm.ls()
for node in allNodes:
   if node is a transformNode:
        rotate it a bit


But you do:

for transformNode in pm.ls(type="transform"):
    rotate the node


#18

As Haggi already said, this is a special design decision. The shape node cannot be repositioned by itself. But it owns the position data of its components (vertices etc). It is always the child of a transform node, which is used to offset the component data (what happens when you move/rotate/etc. the transform node). This design makes sense and is the foundation of the Maya node design: always create a node so that it has one purpose and can be combined with other nodes of another purpose. In this case, one node has the structural data (and is responsible for modifying them), the other is for repositioning these data in the world as a whole.

Of course you can also have a transform without a shape. Also, when you create a ‘group’ node, this is simply a transform node.
Personally, I would say it makes things more simple because of the clear separation of transformation and shape data. Moreover, you can access the shapes attributes via its transform node…

The maya docs not always tell the ‘truth’. Also, don`t believe the ‘E’/‘C’/‘Q’ letters. I remember cases where there was no ‘E’, but I could edit the attribute…

Shape nodes do not have pivots. Only transform nodes have them.
And meshes simply have no direct positions in Maya because they are not allowed to. If that would be allowed, they always were as if untransformed at world zero. And that would make no sense.

Mel is not the brain of Maya. The brain of Maya is its algorithms, put together in a specific design and Mel operates on the attributes of Mayas functioning entities called nodes to modify their data.


#19

I have to thank you all for your replies! :slight_smile:
The discussion went behiond my initial question but it’s very interesting and it’s helping me a lot in my trial to understand Maya architecture and design!

Question:
I can access to shape’s attributes via its transform too because the transforma node is parent of the shape one.
Having instances it’s ok too… many transform nodes pointing to the same shape.
But sciLoop mentioned groups as a single transform node: I suppose this means that a group basically is a transform node parent of several other transform nodes that are linked to shapes, isn’t it?


#20

Yes. Personally, I dont like the term 'group' which is used by Mayas interface (and the node is then also named ‘group’), because it confuses new users : )
However, transform nodes are an essential method for grouping DAG nodes together, either pure logically (then turn off the ‘inheritTransform’ attribute of the transform node) or also functionally, so all nodes underneath that transform node are transformed together as a group : )


#21

I didnt claim shape nodes have pivots anyway.
Of course I meaned ‘transforms’ by the word of ‘mesh’.
I dont understand why you explain these to me, I have no problem with that, I get the idead behind it and I agree with it eventually.

By the word of ‘brain’ I meaned processes which operates the logic and GUI’s anyway. I didnt mean core, just meaned a central neuron system.

Anyway I agree with these so you didnt had to quote me.