I think that it might be useful to redefine the purpose of your `
isEdgesConnected` function by making it do only the work that it is
supposed to: check if 2 edges are connected. Right now, it is also forcing
an unrelated behaviour by retrieving the selection list every time.

What if you need to call this function to compare 1000 edges of a same
mesh? The same selection will be retrieved 1000 times instead of only once.
What if you need this same selection logic for another function `isEdgeLoop`
for example? Will you end up rewriting it in that function?

A better approach would be to run this logic once for all somewhere else,
then directly pass the ready-to-use resulting objects to your function so
it can focus on doing its job, nothing else.

from maya import OpenMaya as om

def isEdgesConnected(meshDagPath, e1Index, e2Index, filter=None):
    # If we have a filter and either one of the edges isn't in it, return.
    if filter and (e1Index not in filter or e2Index not in filter):
        return False

    util = om.MScriptUtil()
    previous_index_ptr = util.asIntPtr()

    eIter = om.MItMeshEdge(meshDagPath)
    eIter.setIndex(e1Index, previous_index_ptr)
    return eIter.connectedToEdge(e2Index)

# Get the first selection object.
sel = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sel)
component = om.MObject()
mDagPath = om.MDagPath()
sel.getDagPath(0, mDagPath, component)

# Store the selected edges in a list.
selectedEdges = []
edgeIterator = om.MItMeshEdge(mDagPath, component)
while not edgeIterator.isDone():
    selectedEdges.append(edgeIterator.index())
    edgeIterator.next()

# Check if the edges are connected, but only if they both are selected.
print(isEdgesConnected(mDagPath, 281, 282, filter=selectedEdges))


This is just an implementation example to give you the idea. Not saying
this is the best one!


PS: Would the function behave normally if the parameters `e1Index` and `
e2Index` were set to `None`? If not, don't set these values as default. In
fact, if these parameters are required and no default values are
acceptable, then definitely don't put any default to force the user to set
them explicitely.


On 12 September 2016 at 00:39, Jean Noval <[email protected]> wrote:

> What I mean by more direct way,  is to not have to select anything like a
> did in my script*
>
> --
> 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/69b5b759-2e21-46f3-86ba-
> 1eb36b306c9e%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/69b5b759-2e21-46f3-86ba-1eb36b306c9e%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/CANuKW51XdcuMeVr%3DDh-dwp_VaFOOtcTrx3kCM%2B6Oi_oeYvPjrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to