Frage

I have a few basic questions which will help me understand some arrays in maya using python.

  1. How can I collect all the selected nodes into an array called 'curSel'?
  2. How can I then collect just the 'meshes' of that array 'curSel' into a new array called 'meshArr'
  3. How can I then collect the 'curves' from array 'curSel' to a new array called 'curvesArr'

In short I'm essentially trying to collect all the selected nodes into a variable. Then I create two more arrays by collecting specific nodes from that array.

War es hilfreich?

Lösung

This is a bit trickier than it really should be

import maya.cmds as cmds
curSel = cmds.ls(sl=True)

gives you a list with the selected objects. However you will only have transforms in your list unless you explicitly selected the mesh or curve shape nodes, so you can't just ask for the meshes or shapes in the list.

To get the shapes you need to use listRelatives:

curveSel = []
meshSel = []
for xform in curSel:
   shapes = cmds.listRelatives(xform, shapes=True) # it's possible to have more than one
   for s in shapes:
       if cmds.nodeType(s) == 'mesh':
          curveSel.append(xform)
       if cmds.nodeType(s) == 'nurbsCurve':
          meshSel.append(xform)

This checks the shapes on each object and assigns it to the right list based on the shape types.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top