What is different about Maya MSelectionList between python API 1.0 and 2.0?



I want to translate ( from api 1.0 to api 2.0) a maya python script which select mesh’s vertex by ids , but i always get error:

TypeError: an integer is required

at line :to_sel.add(mdag, components)
what is different about MSelectionList between API 1.0 and 2.0?

code as follow,the first script which write by python api 1.0, it works, the second one which is translated from first one, it does not work,can anyone give me a hint?

import maya.cmds as cmds
cmds.polyCube(n= 'test_meh')
#api 1.0, it works------------------------------------------- 
import maya.OpenMaya as om
def select_edges( mesh_name, ids ):
    list = om.MSelectionList()
    mdag = om.MDagPath()
    list.getDagPath(0, mdag)

    mfn_components = om.MFnSingleIndexedComponent()
    components = mfn_components.create(om.MFn.kMeshEdgeComponent)
    map(mfn_components.addElement, ids)
    to_sel = om.MSelectionList()

    to_sel.add(mdag, components)
select_edges('test_meh', (1,2,3,4,5))

#api 2.0, it does not work------------------------------------------- 
import maya.api.OpenMaya as om2
def select_edges( mesh_name, ids ):
    list = om2.MSelectionList()
    mdag = om2.MDagPath()
    mdag = list.getDagPath(0)

    mfn_components = om2.MFnSingleIndexedComponent()
    components = mfn_components.create(om2.MFn.kMeshEdgeComponent)
    map(mfn_components.addElement, ids)
    to_sel = om2.MSelectionList()

    to_sel.add(mdag, components)
select_edges('test_meh', (1,2,3,4,5))
# TypeError: an integer is required # 


According to the docs:

A component is passed as a tuple containing the MDagPath of the DAG node and an MObject containing the component.

So I think you need to change

to_sel.add(mdag, components)


to_sel.add((mdag, components))


Mlefevre, thanks! it works now!

PS:I got wrong info from maya api 2.0 exsample files