0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

says invalid syntax when i run it.
missing last paren; fixed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.