@zipit said in Changing material projection in takes using Python:
TEXTURETAG_PROJECTION_UVW on the selected objects texture tag. """ import c4d def main(): # Checks if there is an active object. if op is None: raise ValueError("op is none, please select one object.") # Gets the TakeData from the active document (holds all information about # Takes) takeData = doc.GetTakeData() if takeData is None: raise RuntimeError("Failed to retrieve the take data.") # Gets the active Take and check it's not the main one take = takeData.GetCurrentTake() if take.IsMain(): raise RuntimeError("The selected take is already the main one.") # Gets the material tag of the cube. tag = op.GetTag(c4d.Ttexture) if tag is None: raise RuntimeError("Blah, no texture tag on selected object.") # The single level DescId for the projection parameter. descId = c4d.DescID( c4d.DescLevel(c4d.TEXTURETAG_PROJECTION, c4d.DTYPE_LONG, 0)) newValue = c4d.TEXTURETAG_PROJECTION_UVW # Add an override if this parameter is not already overridden, otherwise # returns the already existing override. overrideNode = take.FindOrAddOverrideParam( takeData, tag, descId, newValue) if overrideNode is None: raise RuntimeError("Failed to find the override node.") # Updates the scene with the new Take overrideNode.UpdateSceneNode(takeData, descId) # Pushes an update event to Cinema 4D c4d.EventAdd() if __name__ == '__main__': main()```
Thank you @zipit
I've tried as suggested but still doesn't seems to be working the way I wanted.
I modified my code and included your suggestions, as well as my test scene, so you can see what's my issue. I bet it's something simple ;-).
import c4d
import os
from c4d import documents
listOfParentTakes = []
listOfChildTakes = []
objects = ["Plane","Plane.1","Plane.2"]
def GetListOfParentTakes():
takeData = doc.GetTakeData()
if takeData is None:
return
mainTake = takeData.GetMainTake()
take = mainTake.GetDown()
while take is not None:
listOfParentTakes.append((take))
take = take.GetNext()
def GetListOfChildrenTakes():
for parent in listOfParentTakes:
take = parent.GetDown()
while take is not None:
listOfChildTakes.append(take)
take = take.GetNext()
# Main function
def main():
c4d.CallCommand(13957) # Clear Console
doc = documents.GetActiveDocument()
takeData = doc.GetTakeData()
GetListOfParentTakes()
GetListOfChildrenTakes()
if takeData is not None:
for el in listOfChildTakes:
print ("Current take name : "+ el.GetName())
takeData.SetCurrentTake(el)
for currentObject in objects:
obj = doc.SearchObject(currentObject)
if obj is not None:
# Gets the material tag of the cube.
tag = obj.GetTag(c4d.Ttexture)
if tag is None:
raise RuntimeError("Blah, no texture tag on selected object.")
# The single level DescId for the projection parameter.
descId = c4d.DescID(c4d.DescLevel(c4d.TEXTURETAG_PROJECTION, c4d.DTYPE_LONG, 0))
newValue = c4d.TEXTURETAG_PROJECTION_UVW
# Add an override if this parameter is not already overridden, otherwise
# returns the already existing override.
overrideNode = el.FindOrAddOverrideParam(
takeData, tag, descId, newValue)
if overrideNode is None:
raise RuntimeError("Failed to find the override node.")
# Execute main()
if __name__=='__main__':
main()