C4D图层颜色渐变着色层标签管理脚本AR_ColorizeLayersWithGradient - Colorize layers with a gradient 

2022-11-03 15:39 发布 | 作品版权归原作者所有,仅供参考学习,禁止商业使用!

插件脚本 /[脚本预设]
835 0 0
C4D图层颜色渐变着色层标签管理脚本AR_ColorizeLayersWithGradient - Colorize layers with a gradient - C4D之家 - cinema4d_-2022-11-03-15.32.45.jpg

AR_ColorizeLayersWithGradient - Colorize layers with a gradient 渐变着色层颜色,作者Arttu Rautio。我们在制作大场景时我们往往要建立非常多层来管理工程,默认的随机颜色乱七八糟很糟心,有了这个小脚本真是强迫症小神器,很简单看视频:

顶部菜单:扩展-->脚本管理器-->新建,复制粘贴以下脚本代码运行即可:

  1. """
  2. AR_ColorizeLayersWithGradient


  3. Author: Arttu Rautio (aturtur)
  4. Website: http://aturtur.com/
  5. Name-US: AR_ColorizeLayersWithGradient
  6. Version: 1.0.1
  7. Description-US: Colorizes selected layers with custom gradient


  8. Written for Maxon Cinema 4D 2023.0.1
  9. Python version 3.9.1


  10. Change log:
  11. 1.0.1 (02.11.2022) - Fixed a bug
  12. 1.0.0 (02.11.2022) - Initial realease
  13. """


  14. # Libraries
  15. import c4d
  16. from c4d.gui import GeDialog
  17. from c4d.modules import render


  18. GRP_MEGA        = 1000
  19. GRP_MAIN        = 1001
  20. GRP_BTNS        = 1002
  21. GRP_VAL         = 1003
  22. GRP_GRD         = 1004


  23. TINT_VAL        = 2001
  24. TINT_GRD        = 2002


  25. GUI_GRD         = 3001


  26. BTN_OK          = 7001
  27. BTN_CANCEL      = 7002


  28. # Classes
  29. class Dialog(GeDialog):
  30.     def __init__(self):
  31.         self._customGradient = None
  32.         super(Dialog, self).__init__()
  33.         self.res = c4d.BaseContainer()


  34.     # Create Dialog
  35.     def CreateLayout(self):
  36.         doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document
  37.         bd = doc.GetActiveBaseDraw() # Get active basedraw


  38.         self.SetTitle("Colorize Layers with Gradient") # Set dialog title
  39.         # ----------------------------------------------------------------------------------------
  40.         self.GroupBegin(GRP_MEGA, c4d.BFH_CENTER, cols=1, rows=1, groupflags=1, initw=500, inith=0)
  41.         self.GroupBorderSpace(5, 5, 5, 5)
  42.         # ----------------------------------------------------------------------------------------
  43.         self.GroupBegin(GRP_MAIN, c4d.BFH_CENTER, cols=2, rows=1, groupflags=1, initw=500, inith=0)
  44.         self.GroupBegin(GRP_VAL, c4d.BFH_LEFT | c4d.BFH_SCALEFIT, cols=1, rows=1, groupflags=1, initw=500, inith=0)
  45.         self.GroupEnd()
  46.         
  47.         bc = c4d.BaseContainer()
  48.         self._customGradient = self.AddCustomGui(GUI_GRD, c4d.CUSTOMGUI_GRADIENT, "Gradient", c4d.BFH_CENTER, 500, 0, bc)
  49.         defaultGrad = c4d.Gradient()
  50.         defaultGrad.InsertKnot(c4d.Vector(0,0,1), 1, 0, 0.5, 0)
  51.         defaultGrad.InsertKnot(c4d.Vector(0,1,1), 1, 0.25, 0.5, 0)
  52.         defaultGrad.InsertKnot(c4d.Vector(0,1,0), 1, 0.5, 0.5, 1)
  53.         defaultGrad.InsertKnot(c4d.Vector(1,1,0), 1, 0.75, 0.5, 0)
  54.         defaultGrad.InsertKnot(c4d.Vector(1,0,0), 1, 1, 0.5, 2)
  55.         
  56.         self._customGradient.SetGradient(defaultGrad) # Set gradient data
  57.         
  58.         self.GroupEnd()
  59.         # ----------------------------------------------------------------------------------------
  60.         # Buttons
  61.         self.GroupBegin(GRP_BTNS, c4d.BFH_CENTER)
  62.         self.AddButton(BTN_OK, c4d.BFH_LEFT, name="Ok") # Add button
  63.         self.AddButton(BTN_CANCEL, c4d.BFH_RIGHT, name="Cancel") # Add button
  64.         self.GroupEnd()
  65.         # ----------------------------------------------------------------------------------------
  66.         self.GroupEnd()
  67.         return True


  68.     # Processing
  69.     def Command(self, paramid, msg): # Handling commands (pressed button etc.)
  70.         doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document
  71.         bc = c4d.BaseContainer() # Initialize a base container
  72.         # Actions here
  73.         if paramid == BTN_CANCEL: # If 'Cancel' button is pressed
  74.             self.Close() # Close dialog
  75.         if paramid == BTN_OK: # If 'Accept' button is pressed
  76.             grad = self._customGradient.GetGradient() # Get gradient data
  77.             ColorizeWithGradient(grad) # Colorize objects
  78.             self.Close() # Close dialog


  79.         c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_ESC, bc)
  80.         if bc[c4d.BFM_INPUT_VALUE]:
  81.             self.Close()


  82.         c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_ENTER, bc)
  83.         if bc[c4d.BFM_INPUT_VALUE]:
  84.             grad = self._customGradient.GetGradient() # Get gradient data
  85.             ColorizeWithGradient(grad) # Colorize objects
  86.             self.Close() # Close dialog
  87.         return True # Everything is fine


  88. # Functions
  89. def GetNextItem(op):
  90.     if op==None:
  91.         return None
  92.     if op.GetDown():
  93.         return op.GetDown()
  94.     while not op.GetNext() and op.GetUp():
  95.         op = op.GetUp()
  96.     return op.GetNext()


  97. def CollectLayers():
  98.     def IterateLayers(op):
  99.         layerList = [] # Initialize an array for collecting layers
  100.         if op is None: # If there is no layer
  101.             return # This is over
  102.         while op: # While there is an item
  103.             layerList.append(op) # Add layer to layer list
  104.             op = GetNextItem(op) # Get next layer
  105.         return layerList # Return layers


  106.     doc = c4d.documents.GetActiveDocument() # Get active document
  107.     layerRoot = doc.GetLayerObjectRoot() # Get layer object root
  108.     layers = layerRoot.GetChildren() # Get layers
  109.     if layers == []: # Check if there is no any layer
  110.         return None # Return none
  111.     else: # If there is any layer
  112.         startLayer = layers[0] # Get start layer for iterating through all layers
  113.         return IterateLayers(startLayer) # Return collection of all layers


  114. def ColorizeWithGradient(gradient):
  115.     doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document
  116.     doc.StartUndo() # Start recording undos
  117.     irs = render.InitRenderStruct()
  118.     gradient.InitRender(irs)
  119.    
  120.     layers = CollectLayers()
  121.     selectedLayers = []
  122.     for l in layers:
  123.         if l.GetBit(c4d.BIT_ACTIVE):
  124.             selectedLayers.append(l)
  125.             
  126.     for i, s in enumerate(selectedLayers):
  127.         doc.AddUndo(c4d.UNDOTYPE_CHANGE, s) # Add undo command for changing something
  128.         s[c4d.ID_LAYER_COLOR] = gradient.CalcGradientPixel(float(i)/float(len(selectedLayers)))
  129.    
  130.     doc.EndUndo() # Stop recording undos
  131.     c4d.EventAdd() # Update Cinema 4D
  132. def main():
  133.     dlg = Dialog() # Create dialog object
  134.     dlg.Open(c4d.DLG_TYPE_MODAL, 0, -1, -1, 0, 0) # Open dialog
  135.     pass


  136. # Execute the main function
  137. if __name__ == '__main__':
  138.     main()
复制代码
复制以上代码也可以,或者下载下面的附件文件也可以,AR_ColorizeLayersWithGradient.py

附件信息

插件脚本
软件性质: 脚本 
适用版本: C4D R15 - C4D R16 - C4D R17 - C4D R18 - C4D R19 - C4D R20 - C4D R21 - C4D S22 - C4D R23 - C4D S24 - C4D R25 - C4D S26 - C4D 2023
软件版本: Version: unknown
系统平台: Win MAC 
软件语言: 英文 
插件来源: https://www.c4d.cn/c4dsoft.html
百套精美Kitbash3D模型专题合集下载
时尚卡通办公室人物C4D立体图标工程下载Cinema 4D Fashion Cartoon Office Character 3D Icon Project Download
C4D科技新闻片头电视栏目频道包装动画工程下载Cinema 4D Technology News Headline TV Program Channel Packaging Animation Project Download
关闭

C4D精选推荐 上一条 /10 下一条

智能
客服
快速回复 返回顶部 返回列表