Advertisement
nux95

Cinema 4D - Replace Texturetags Script

Jun 17th, 2011
1,645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.30 KB | None | 0 0
  1. """
  2. ------------------------------------------------------------------
  3. =================================================================|
  4. This script deletes all Texturetags on every Object in the Scene |
  5. and inserts a new Texturetag with the selected Material.         |
  6. =================================================================|
  7. --------------------|--------------------------------------------|
  8. written by:         |   Niklas Rosenstein                        |
  9. license:            |   Use this software at your own risk.      |
  10.                    |   Open Source for all.                     |
  11. ====================|============================================|
  12. ------------------------------------------------------------------
  13. """
  14.  
  15. import  c4d
  16. from    c4d.documents   import GetActiveDocument
  17. from    c4d.gui         import GeDialog
  18. from    threading       import Thread
  19.  
  20. def GetHNext(op):
  21.     """ Walks the hierarchy. """
  22.     if not op: return
  23.     if op.GetDown(): return op.GetDown()
  24.     while op.GetUp() and not op.GetNext():
  25.         op = op.GetUp()
  26.     return op.GetNext()
  27.  
  28. def DeleteAllTags(op, tpe = None, undo = True):
  29.     doc     = op.GetDocument()
  30.     tag     = op.GetFirstTag()
  31.  
  32.     while tag:
  33.         ntag    = tag.GetNext()     # get next tag
  34.  
  35.         if tpe and tag.CheckType(tpe):
  36.             if undo and doc:
  37.                 doc.AddUndo(c4d.UNDOTYPE_DELETE, tag)
  38.             tag.Remove()            # remove tag
  39.         tag     = ntag              # set 'tag' to next tag
  40.  
  41. def main(undo = True):
  42.     doc     = GetActiveDocument()
  43.  
  44.     if doc is None:
  45.         return False
  46.  
  47.     op      = doc.GetFirstObject()
  48.     mat     = doc.GetActiveMaterial()
  49.  
  50.     if mat is None:
  51.         return False
  52.  
  53.     if op is None:
  54.         return False
  55.  
  56.  
  57.     # iterate over all objects in the document
  58.     while op:
  59.         DeleteAllTags(op, c4d.Ttexture)                    # delete all Texturetags
  60.  
  61.         tag     = op.MakeTag(c4d.Ttexture)          # create new Texturetag
  62.         tag[c4d.TEXTURETAG_MATERIAL]    = mat       # assign new material
  63.  
  64.         if undo:
  65.             doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
  66.  
  67.         op      = GetHNext(op)                      # get next object
  68.  
  69.     c4d.EventAdd()                                  # update cinema 4d
  70.  
  71.     return True
  72.  
  73. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement