How to get all the groups


#1

Hello,

I am trying to export a large amount of groups and geo from maya into katana. I am working on building the scenegraphXML. The course I am working on says to manually input all the groups then manually input all the object. There must be a better way of doing this. How can I loop over my scene and get A) A python list of all the groups and B) A python list of all the objects?

Alternatively, if someone has a scenegraphxml exporter that dose not requerer you to imput all this info by hand that also works : )


#2

How well do you know maya? The terms “groups” and “objects” and even “geo” can mean slightly different things in different contexts. You should be looking at how to get all the transform nodes (“groups”) and find the transform nodes that the immediate parent of a shapeNode which is a mesh (“geo”/“objects”). The trouble is that a transform node can have several shapes of any type under it and it may also have other transforms as well, and at the same time.

How you decide whether they are groups might mean making some assumptions, like does it have relatives that are not mesh or nurbsSurface shapeNodes, or cameras, etc

import pymel.core as pm
nt = pm.nodetypes
allTransforms = pm.ls(type=‘transform’)
allGroups = [t for t in allTransforms if not isinstance(t.getShape(), (nt.Mesh, nt.NurbsSurface, nt.Camera))]

Getting the objects might be something like:

import pymel.core as pm
allGeoShapes = pm.ls(type=‘mesh’)
allGeo = [s.getParent() for s in allGeoShapes ]

David