Reply
Reply
 
Thread Tools Display Modes
malcolm's Avatar
Old (#1)
Anyone got a script that deletes groups with nothing in them or groups that have groups in them.
Offline , card carrying polycounter, 2,029 Posts, Join Date Oct 2004, Location Vancouver Canada  
   Reply With Quote

Shawner's Avatar
Old (#2)
Run this in the python tab in your script editor.

Code:
import maya.cmds as cmds

transforms =  cmds.ls(type='transform')
deleteList = []
for tran in transforms:
    if cmds.nodeType(tran) == 'transform':
        children = cmds.listRelatives(tran, c=True) 
        if children == None:
            print '%s, has no childred' %(tran)
            deleteList.append(tran)
            
cmds.delete(deleteList)
Offline , null, 24 Posts, Join Date Oct 2004, Location Canada  
   Reply With Quote

THNKR's Avatar
Old (#3)
or use File->Optimize Scene Size [options]

Remove empty: (check) Transforms.
Offline , null, 23 Posts, Join Date Oct 2009,  
   Reply With Quote

malcolm's Avatar
Old (#4)
THNKR, that rarely works. Not sure what maya considers empty transforms but it's pretty picky, I think even a group within a group doesn't qualify for delete.
Offline , card carrying polycounter, 2,029 Posts, Join Date Oct 2004, Location Vancouver Canada  
   Reply With Quote

sama.van's Avatar
Old (#5)
Quote:
Originally Posted by malcolm View Post
THNKR, that rarely works. Not sure what maya considers empty transforms but it's pretty picky, I think even a group within a group doesn't qualify for delete.

Yeah but if your group is in another group and the last group in the hierarchy doesn't have any child, do you want to delete this group or to keep it?

Example :


-group1
--group2
---group3

Do you want to delete group3 or not?

or :

- cube01
--group1
---group2

Do you want to delete group2 or not?


I think Maya will clean one time.... after that "oh damn this grp is empty! ok.. then // I will delete it..."
Offline , polygon, 659 Posts, Join Date Mar 2007, Location Mie-Tsu (Japan) Send a message via MSN to sama.van  
   Reply With Quote

claydough's Avatar
Old (#6)
Quote:
Originally Posted by malcolm View Post
Anyone got a script that deletes groups with nothing in them or groups that have groups in them.

So any transform without any other node children ( shape node? etc ) other than transform nodes??
Offline , polygon, 712 Posts, Join Date May 2008, Location Austin/Baltimoron  
   Reply With Quote

MoP's Avatar
Old (#7)
I usually found Optimise Scene Size works pretty well, provided you've deleted history.
If you don't delete history on all your objects, the transforms which appear "empty" in the outliner may still have connections to valid objects in your scene (eg. after a Combine operation, the previous transforms are now empty but still affect the position of the combined objects).

If you first Delete History on all objects (or Non-Deformer history to be safer), then do Optimise Scene Size, it should always get rid of all empty groups.
Offline , MoP, 11,603 Posts, Join Date Oct 2004, Location London, UK  
   Reply With Quote

malcolm's Avatar
Old (#8)
Did a delete all by type history before running delete unused transform did not fix the problem.
Offline , card carrying polycounter, 2,029 Posts, Join Date Oct 2004, Location Vancouver Canada  
   Reply With Quote

sama.van's Avatar
Old (#9)
lol it starts to be confuse to me...

Do you have a scene example, or screen of your complete outliner ?
Then you could explain what are the node you would like to delete or not?

I also remember some bugs with the Optimize Scene Size in Maya but before the 2008 version.
What version are you using right now?
Offline , polygon, 659 Posts, Join Date Mar 2007, Location Mie-Tsu (Japan) Send a message via MSN to sama.van  
   Reply With Quote

malcolm's Avatar
Old (#10)
Shawner that script works great thanks a lot man.
Offline , card carrying polycounter, 2,029 Posts, Join Date Oct 2004, Location Vancouver Canada  
   Reply With Quote

Shawner's Avatar
Old (#11)
Awsome good to here.
Offline , null, 24 Posts, Join Date Oct 2004, Location Canada  
   Reply With Quote

Toast's Avatar
Old (#12)
In 2011, running that script I get this error

Quote:
# Error: TypeError: file <maya console> line 12: Object [] is invalid #
Offline , spline, 184 Posts, Join Date Jul 2008,  
   Reply With Quote

Shawner's Avatar
Old (#13)
try

Code:
import maya.cmds as cmds

transforms =  cmds.ls(type='transform')
deleteList = []
for tran in transforms:
    if cmds.nodeType(tran) == 'transform':
        children = cmds.listRelatives(tran, c=True) 
        if children == None:
            print '%s, has no childred' %(tran)
            deleteList.append(tran)

if len(deleteList) > 0:            
   cmds.delete(deleteList)
Offline , null, 24 Posts, Join Date Oct 2004, Location Canada  
   Reply With Quote

Toast's Avatar
Old (#14)
Perfect!
Offline , spline, 184 Posts, Join Date Jul 2008,  
   Reply With Quote

funshark's Avatar
Old (#15)
Never had any issue with the Optimize Scene Size.
If the empty groups don't disappear, that means they're connected to something and I recommend you to double check if it's something important or not.
Offline , spline, 242 Posts, Join Date Oct 2006, Location France, paris  
   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Copyright 1998-2012 A. Risch