Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Be able to write to vectorArray attributes (or similar) via the Python MayaAPI2.0

Be able to write to vectorArray attributes (or similar) via the Python MayaAPI2.0

At present we can only write to vectorArray attributes via MEL or python script, and due to the legacy formatting of the command it is limited to 252 vectors. It would be useful to be able to write to 1000s of vectors via using the Python Maya API2.0 using an actual list of tuples or an MVectorArray.

 

Here is the legacy code I used that was limited to 252 values:

 

# set a vector array attribute from a list
def setVectorArrayAttr(node, attr, vectorArrayList):
numVectors = len(vectorArrayList)

cmdString = "mc.setAttr('"+node+'.'+attr+"',"
vectorArrayString = ""
vectorArrayString += str(numVectors)+','
for vectorItem in vectorArrayList:
vectorArrayString += str(vectorItem)+','
cmdString = cmdString+vectorArrayString+"type='vectorArray')"
eval(cmdString)

 

 

1 Comment
mvn882
Explorer

I was having the same issue but found out you can set it using openmaya in python to do it, in case anyone else needs a workaround:

cmds.select(node_path)
cmds.addAttr(longName='attribute', dataType='vectorArray')
 
object_path = node_path
selection_list = OpenMaya.MSelectionList()
selection_list.add(object_path)
m_object = selection_list.getDependNode(0)
m_dag_object = OpenMaya.MFnDagNode(m_object)
plug = m_dag_object.findPlug('attribute', False)
vector_array_data = OpenMaya.MFnVectorArrayData()
vector_array = OpenMaya.MVectorArray()
#populate array here
vector_array_obj = vector_array_data.create(vector_array)
plug.setMObject(vector_array_obj) 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea