SHARE
TWEET

Untitled

a guest Jan 29th, 2015 223 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import c4d
  2. from c4d import gui
  3.  
  4. """
  5. Author: Owen Lim
  6. Date Modified: 190314
  7. Date Created: 270813
  8. Version 1.10
  9. """
  10.  
  11.  
  12.  
  13. def pressRecycle():
  14.        
  15.     # get selected
  16.     selectedObjects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)
  17.    
  18.     if len(selectedObjects) == 0:
  19.    
  20.         # run clear bin proccess
  21.         clearBin()
  22.        
  23.     else:
  24.  
  25.         # call select all children command
  26.         c4d.CallCommand(16388)
  27.        
  28.         # renew selected objects with their children
  29.         selectedObjects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
  30.        
  31.         # get list of layers
  32.         layerList = doc.GetLayerObjectRoot().GetChildren()
  33.        
  34.         # rBin status
  35.         rBin = False
  36.        
  37.         for layer in layerList:
  38.            
  39.             # searches for binLayer
  40.             if layer.GetName() == "recycleBin":
  41.                
  42.                 # set rBin to True
  43.                 rBin = True
  44.                
  45.                 # adds objects to layer
  46.                 for obj in selectedObjects:
  47.                     obj.SetLayerObject(layer)
  48.                 c4d.EventAdd()
  49.                 return True
  50.    
  51.         if rBin == False:
  52.            
  53.             # create new layer
  54.             c4d.CallCommand(100004738)
  55.            
  56.             # get last layer
  57.             newLayerList = doc.GetLayerObjectRoot().GetChildren()
  58.             binLayer = newLayerList[-1]
  59.             binLayer.SetName("recycleBin")
  60.            
  61.             # sets layer options
  62.             layerData = binLayer.GetLayerData(doc)
  63.             layerData["render"] = False
  64.             layerData["view"] = False
  65.             layerData["expressions"] = False
  66.             layerData["generators"] = False
  67.             layerData["deformers"] = False
  68.             layerData["manager"] = False
  69.             layerData["locked"] = False
  70.             layerData["animation"] = False
  71.             binLayer.SetLayerData(doc,layerData)
  72.            
  73.             # adds objects to layer
  74.             for obj in selectedObjects:
  75.                 obj.SetLayerObject(binLayer)
  76.    
  77.    
  78.     print "run complete"
  79.     c4d.EventAdd()
  80.    
  81. def clearBin():
  82.    
  83.     print "Run clear bin proccess"
  84.    
  85.     # ask for confirmation
  86.     confirmResult = gui.QuestionDialog(("Are you sure you want to clear the recycle bin?\n\n"
  87.     "            THIS CANNOT BE UNDONE!!"))
  88.    
  89.     if confirmResult == True:
  90.        
  91.         # delete objects
  92.        
  93.         # get list of layers
  94.         layerList = doc.GetLayerObjectRoot().GetChildren()
  95.        
  96.         for layer in layerList:
  97.            
  98.             # searches for binLayer
  99.             if layer.GetName() == "recycleBin":
  100.                
  101.                 # Unlocks layer
  102.                 layerData = layer.GetLayerData(doc)
  103.                 layerData["locked"] = False
  104.                 layer.SetLayerData(doc,layerData)
  105.                
  106.                 # selects layer
  107.                 layer.SetBit(c4d.BIT_ACTIVE)
  108.                
  109.             else:
  110.                 layer.DelBit(c4d.BIT_ACTIVE)
  111.                
  112.         # call select from layer
  113.         c4d.CallCommand(100004737)
  114.        
  115.         # get newly selected objects
  116.         objectsToDelete = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
  117.        
  118.         for eachObj in objectsToDelete:
  119.             eachObj.Remove()
  120.                
  121.     else:
  122.         # do nothing
  123.         print "User Defined Cancel"
  124.         return False
  125.    
  126.    
  127. pressRecycle()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top