you have no idea how much I appreciate your explanation! thank you very much! I don´t now c++ so that was a huge help. thanks!
El miércoles, 10 de agosto de 2016, 12:31:24 (UTC+2), Christopher Crouzet escribió: > > If you look at the C++ Maya API doc, you'll see that the ` > MSelectionList::getDagPath` method is defining a parameter `MDagPath & > dagPath`. In C++, the `&` character denotes what is called a reference > <https://en.wikipedia.org/wiki/Reference_%28C%2B%2B%29>. What it means > here is that `dagPath` is an input/output parameter to the ` > MSelectionList::getDagPath` method—the method can read but also modify > the content of the `dagPath` argument. > > In your code, you initialize your `mDagPath` variable with ` > OpenMaya.MDagPath()`. At this point in time, `mDagPath` is like an empty > “shell”, with uninitialized data that is not pointing to any valid DAG node > in your scene, so calling some methods, such as `MDagPath::fullPathName`, > might result in an undefined behaviour (in other words: don't do it). When > you pass `mDagPath` to `MSelectionList::getDagPath`, the method will fill > it with a new “substance”, that is the data required to point to a valid > DAG node. Now you can safely access or modify the DAG node like you've > already done with the `MDagPath::fullPathName` method and others. > > Arguably, this whole reference thing is popular in C++ but not so much in > Python. If the Python version of the Maya API v1 would have received a bit > more love, you'd probably only would have had to type `mDagPath = > mSel.getDagPath(0)` instead. > > Now, `mDagPath.fullPathName('pCube1')` doesn't make so much sense in > itself as one would expect the method `MDagPath::fullPathName` to return > the full path of the DAG node, nothing else. But it surely would make sense > to have another method allowing to easily retrieve a `MDagPath` object > from its name. Alas there's none available and that's why many develop > their own utilities by wrapping the `MGlobal::getSelectionListByName` > function. > > > On 10 August 2016 at 16:43, Rudi Hammad <[email protected] <javascript:>> > wrote: > >> So this is the code ( it is quite simple so I didn´t use paste bin, I >> hope it is okey) >> >> import maya.OpenMaya as OpenMaya >> >> cmds.polyCube() >> mSel = OpenMaya.MSelectionList(); mSel.add('pCube1') >> mDagPath = OpenMaya.MDagPath() >> mSel.getDagPath(0, mDagPath) >> mDagPath.fullPathName() >> >> that is what I learn in a cgcircuit course. they say that MObject or >> MDagPath are handles that you need to use to access maya data. Okey. no >> problem. >> The thing that I am trying to understand in the code I posted is this: >> I am creating an object mDagPath that is requiered as an argument --> >> mSel.getDagPath(0, mDagPath) >> by doing that, I can use that object method .fullPathName(). >> >> what I want to understand is what is happening there. what happens when >> you pass an object as argument? why doing that allows you to use some >> methods of that object. >> in my mind it would be more intuitive something like : >> >> import maya.OpenMaya as OpenMaya >> >> cmds.polyCube() >> mDagPath = OpenMaya.MDagPath() >> mDagPath.fullPathName('pCube1') >> >> does my question make any sence? >> >> thnks >> >> -- >> 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 [email protected] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/d7383962-8cee-4e9c-b57d-df86ea8226f0%40googlegroups.com >> >> <https://groups.google.com/d/msgid/python_inside_maya/d7383962-8cee-4e9c-b57d-df86ea8226f0%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Christopher Crouzet > *http://christophercrouzet.com* <http://christophercrouzet.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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/6cfb9839-f440-4ce7-b21e-c6fc7f4697fb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
