First of all, you might be misunderstanding what `mDagPath.length()`
returns. As per the doc, it “*determines the number of DAG Nodes in the
Path not including the root.*” So basically, it gives you the hierarchy
depth of the DAG path, that is '|pSphere1' will return 1, and
'|pSphere1|pSphereShape1' will return 2.
As such, I believe that in your case `mDagPath.length()` should return a
value greater or equal to 2 when you called it after having selected some
components, since the DAG path would be pointing to a shape nested under a
transform. Maybe you forgot to select some edges when copy/pasting your
output log? :)
“
*Where is the component's info inside my MSelectionList() ?I know the
component's info is in my variable component, but is it possible to
directly extract it from my MSelectionList ?*”
The component info has to be stored somewhere by Maya's internals, maybe
within `MSelectionList`, maybe not, but that doesn't matter because it's an
implementation detail and it is none of our business how they deal with it
internally. As users, what we are provided with is the `
MSelection::getDagPath` method as you've found, and that's most likely the
most direct way that we have to access this data.
So in the end I'm not sure if you actually found out how to iterate through
the components, but in case of here's an example:
edge_iterator = om.MItMeshEdge(mDagPath, component)
while not edge_iterator.isDone():
print(edge_iterator.index())
edge_iterator.next()
As for adding a component to the selection list, there is an `
MSelectionList::add` method that allows this. Now I can't think of many use
cases for doing such a thing, but maybe if you need to pass the selection
through a MEL command that doesn't accept setting explicitely which
nodes/components to operate on.
On 11 September 2016 at 19:01, Jean Noval <[email protected]> wrote:
>
>
> Hello,
>
> I'm trying to get all the infos from an MSelectionList().
>
> Example :
> If I select a transform in maya and then run this script :
>
> sel = om.MSelectionList()
> om.MGlobal.getActiveSelectionList(sel)
>
> mDagPath = om.MDagPath()
> sel.getDagPath(0, mDagPath)
> print(mDagPath.fullPathName())
> print(mDagPath.length())
>
>
> I get :
>
> |pSphere1
> 1
>
> And that' great, but when I select edeges of |pSphere1 and execute this:
>
> sel = om.MSelectionList()
> om.MGlobal.getActiveSelectionList(sel)
>
> component = om.MObject()
> mDagPath = om.MDagPath()
> sel.getDagPath(0, mDagPath, component)
> print(mDagPath.fullPathName())
> print(mDagPath.length())
>
> I also get :
>
> |pSphere1
> 1
>
>
> Where is the component's info inside my MSelectionList() ?
> I know the component's info is in my variable component, but is it
> possible to directly extract it from my MSelectionList ?
>
>
> And a second question:
> How to get the same thing but without selecting anything, like this:
>
> sel = om.MSelectionList()
> sel.add(pSphere1Shape1)
> sel.add(pSphere1.e[317]) <------- I want to had the dges directly in my
> MSelection
>
>
> component = om.MObject()
> meshDagPath = om.MDagPath()
> sel.getDagPath(0, meshDagPath, component)
>
>
> Thank you
>
> --
> 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/bf9d3aa6-1566-418b-aaf1-
> f3ebbfa9395f%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/bf9d3aa6-1566-418b-aaf1-f3ebbfa9395f%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/CANuKW50PvPwX_QV%2BU6duS%2BJLOp7p6oH2uJzyDmpGQbo%2B7CrHww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.