Hello, everyone! Im learning python and trying to make useful stuff, but it`s hard to understand some things.
I`m writing now a simple script for Redshift users. The task is:
- Add individual Object ID tags to selected objects (for examle, obj1 = 1, obj2 = 2 , ...)
- Create Redshift Pazzle Matte AOVs (PM)
The trick is to make enough PM to be enough for each object that is selected in the scene.
1 PM AOV is equal to 3 objects in scene. For example I generated 9 Object ID tags. Every tag assign uniqe number for every object (1, 2, 3, ...). For each of them I need PMs where every channel is object in scene.
- How to generate multiple PMs with uniqe names and increasing numbers for my Object IDs?
- How to improve this code?
Thank you for your attention!
import c4d
import c4d.documents
from c4d import gui
import redshift
from pprint import pprint
def ob_tags():
flags = (c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER |
c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
selection = doc.GetActiveObjects(flags)
if not selection:
c4d.gui.MessageDialog("Please select objects")
doc.StartUndo()
for i, obId in enumerate(selection):
tag = c4d.BaseList2D(1036222)
tag[c4d.REDSHIFT_OBJECT_OBJECTID_OVERRIDE] = True
tag[c4d.REDSHIFT_OBJECT_OBJECTID_ID] = i+1
obId.InsertTag(tag)
doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
doc.EndUndo()
def CreateAOVs(vpRS):
flags = (c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER |
c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
selection = doc.GetActiveObjects(flags)
# 1 AOV is 3 channels, for 9 objects for example need 3 Pazzle Matte
aovs_quantity = int(len(selection) // 3)
#to be sure numbers ok in console
print('aovs_quantity is ', aovs_quantity )
print('objects in scene ', len(selection))
aovs = redshift.RendererGetAOVs(vpRS)
aov = redshift.RSAOV()
aov.SetParameter(c4d.REDSHIFT_AOV_TYPE, c4d.REDSHIFT_AOV_TYPE_PUZZLE_MATTE)
aov.SetParameter(c4d.REDSHIFT_AOV_ENABLED, True)
aov.SetParameter(c4d.REDSHIFT_AOV_NAME, "My PuzzleMatte")
aov.SetParameter(c4d.REDSHIFT_AOV_PUZZLE_MATTE_MODE, c4d.REDSHIFT_AOV_PUZZLE_MATTE_MODE_OBJECT_ID)
#this is where channels need to assign
aov.SetParameter(c4d.REDSHIFT_AOV_PUZZLE_MATTE_RED_ID, 1)
aov.SetParameter(c4d.REDSHIFT_AOV_PUZZLE_MATTE_GREEN_ID,2)
aov.SetParameter(c4d.REDSHIFT_AOV_PUZZLE_MATTE_BLUE_ID,3)
aovs.append(aov)
return redshift.RendererSetAOVs(vpRS, aovs)
def main():
ob_tags()
doc = c4d.documents.GetActiveDocument()
renderdata = doc.GetActiveRenderData()
flags = (c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER |
c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
selection = doc.GetActiveObjects(flags)
aovs_quantity = int(len(selection) // 3)
# Get the Redshift videoPost and render settings
vprs = redshift.FindAddVideoPost(renderdata, redshift.VPrsrenderer)
if vprs is None:
return
# Switch renderer
renderdata[c4d.RDATA_RENDERENGINE] = redshift.VPrsrenderer
CreateAOVs(vprs)
if __name__=='__main__':
c4d.CallCommand(13957)
c4d.EventAdd()
main()