Results 1 to 5 of 5

Thread: [Maya] Getting all geometry in scene, is it possible?

  1. #1

    Default [Maya] Getting all geometry in scene, is it possible?



    Hello!
    Is there an easy way of getting all the geometry in the scene? When I say geometry I mean NOT the "Shape" or "ShapeOrig" nodes, only the geometry itself. I know the geometry can be referred to as a "mesh" or a "transform" and I dont think I want either. I want the pieces of geometry that I see in the viewport, that has vertices, edges, faces and probably a skinCluster, and I can apply a texture to, NOT the stupid "shape" or "shapeOrig" nodes.

    If I use: ls(EVERY POSSIBLE COMBINATION OF FLAGS HERE)
    I always get the shape and shapeOrig nodes.
    I dont want to dirty up the script with: if 'shapeOrig' in str(Piece_of_geo):

    Is there an easy way of gathering all geometry (meshes) in the scene? I even have a group node with all the geometry in it.

    All i want to do is loop through them and makes sure they have materials and textures assigned to them, and bail out if they dont.

  2. #2
    Moderator Wuffles's Avatar
    Join Date
    Dec 2011
    Location
    Irvine, USA
    Posts
    92

    Default

    Hey Age,

    I managed to get all the transform nodes, which is what you are talking about (the parent of the shape node) with:

    Code:
    import pymel.core as pm
    
    obj = pm.ls(typ="transform")
    
    # Result: [nt.Transform(u'front'),
     nt.Transform(u'pPrism1'),
     nt.Transform(u'pSphere1'),
     nt.Transform(u'persp'),
     nt.Transform(u'side'),
     nt.Transform(u'subdivCube1'),
     nt.Transform(u'top')] #
    This gives you all the transforms of all the things in the scene. However, this will also give you the cameras, any groups (empty or not), transforms of curves, etc...

    If you're looking for the type that links to all the data you are talking about, that is indeed a "mesh" type.

    Code:
    obj = pm.ls(geometry=True)
    
    # Result: [nt.Mesh(u'pPrismShape1'),
     nt.Mesh(u'pSphereShape1'),
     nt.Subdiv(u'subdivCube1Shape')] #

    With pymel you can access all the info listed above with these nodes. However, if you're looking for the transforms of these nodes only you can use:

    Code:
    obj = pm.ls(geometry=True)
    
    transform_list = []
    for o in obj:
        transform_node = pm.listRelatives(o, parent=True)
        transform_list.append(transform_node)
    
    
    transform_list
    # Result: [[nt.Transform(u'pPrism1')],
     [nt.Transform(u'pSphere1')],
     [nt.Transform(u'subdivCube1')]] #
    Is this what you're looking for? :)

    Edit: Oops! Didn't see my sub-d cube in there. Was meant to be a polycube but you get the idea. :P
    Last edited by Wuffles; 04-16-2013 at 01:10 PM.

  3. #3

    Default

    Just to add to what Sophie posted, you can just pass the shape list to the listRelatives command and it'll return a list. Also geometry can spawn stuff like locators etc. :

    Code:
    import pymel.core as pm
    
    shapesList = pm.ls(type="mesh")
    transformList = pm.listRelatives(shapesList,parent=True)
    print transformList
    Last edited by haiddasalami; 04-16-2013 at 01:29 PM.

  4. #4
    struct
    Join Date
    Mar 2011
    Location
    San Francisco
    Posts
    348

    Default

    "When I say geometry I mean NOT the "Shape" or "ShapeOrig" nodes, only the geometry itself"
    is a contradictory statement.

    Those shape nodes ARE the geometry/meshes. They are the maya nodes that contain the component (vert/face/edge) data, and are the nodes that are connected to shadingGroups and used for shading. It can be a little confusing when you use those terms but say you don't want what those terms represent. The ShapeOrig nodes are intermediate nodes used in deformation chains and many functions have arguments that ignore those nodes (cmds.ls(noIntermediate=True), for example).

  5. #5

    Default

    Thanks y'all!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •