Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- ------------------------------------------------------------------
- =================================================================|
- This script deletes all Texturetags on every Object in the Scene |
- and inserts a new Texturetag with the selected Material. |
- =================================================================|
- --------------------|--------------------------------------------|
- written by: | Niklas Rosenstein |
- license: | Use this software at your own risk. |
- | Open Source for all. |
- ====================|============================================|
- ------------------------------------------------------------------
- """
- import c4d
- from c4d.documents import GetActiveDocument
- from c4d.gui import GeDialog
- from threading import Thread
- def GetHNext(op):
- """ Walks the hierarchy. """
- if not op: return
- if op.GetDown(): return op.GetDown()
- while op.GetUp() and not op.GetNext():
- op = op.GetUp()
- return op.GetNext()
- def DeleteAllTags(op, tpe = None, undo = True):
- doc = op.GetDocument()
- tag = op.GetFirstTag()
- while tag:
- ntag = tag.GetNext() # get next tag
- if tpe and tag.CheckType(tpe):
- if undo and doc:
- doc.AddUndo(c4d.UNDOTYPE_DELETE, tag)
- tag.Remove() # remove tag
- tag = ntag # set 'tag' to next tag
- def main(undo = True):
- doc = GetActiveDocument()
- if doc is None:
- return False
- op = doc.GetFirstObject()
- mat = doc.GetActiveMaterial()
- if mat is None:
- return False
- if op is None:
- return False
- # iterate over all objects in the document
- while op:
- DeleteAllTags(op, c4d.Ttexture) # delete all Texturetags
- tag = op.MakeTag(c4d.Ttexture) # create new Texturetag
- tag[c4d.TEXTURETAG_MATERIAL] = mat # assign new material
- if undo:
- doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
- op = GetHNext(op) # get next object
- c4d.EventAdd() # update cinema 4d
- return True
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement