We're quite often in a situation where we need to convert many Standard C4D Materials to Octane ones.
We've already made a script which will do a lot of steps for us such as optimizing the models or adding their materials into corresponding layers, but when it comes to automatically converting all the native C4D materials to Octane ones we are struggling to automate this step.
FULL SCRIPT HERE - It's for automatic setup of 3D exported World of Warcraft characters:
- Code: Select all
import c4d
from c4d import documents
# ------------------------------------------------------------
# MOVE ALL POLYGON OBJECTS UP
def main():
doc = documents.GetActiveDocument()
# Find polygon objects
objects = doc.GetObjects()
for obj in objects:
if obj.GetType() == c4d.Opolygon:
obj.SetBit(c4d.BIT_ACTIVE)
child = obj.GetDown()
while child:
if child.GetType() == c4d.Opolygon:
child.SetBit(c4d.BIT_ACTIVE)
child = child.GetNext()
# Move up
selected_objects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
for obj in selected_objects:
if obj.GetUp():
obj.InsertBefore(doc.GetFirstObject())
c4d.CallCommand(14039) # Optimize...
# Deselect
for obj in selected_objects:
doc.SetSelection(obj, c4d.SELECTION_SUB)
# Update UI
c4d.EventAdd()
if __name__=='__main__':
main()
# -------------------------------------------------------------
# REMOVE ALL SUBDIVISION SURFACE OBJECTS
def main(keyword):
doc = c4d.documents.GetActiveDocument()
# Find Subdiv objects
all_objects = doc.GetObjects()
for obj in all_objects:
if keyword.lower() in obj.GetName().lower():
obj.Remove()
# Update UI
c4d.EventAdd()
if __name__ == '__main__':
main("Subdivision")
# -------------------------------------------------------------
# REMOVE LAST BONE OBJECT
def main():
doc = c4d.documents.GetActiveDocument()
all_objects = doc.GetObjects()
for obj in all_objects:
if "item" in obj.GetName().lower() and "rig" in obj.GetName().lower():
obj.Remove()
c4d.EventAdd()
if __name__ == '__main__':
main()
# -------------------------------------------------------------
# ROTATE CHARACTER BONE STRUCTURE UPWARDS
def main():
doc = c4d.documents.GetActiveDocument()
all_objects = doc.GetObjects()
for obj in all_objects:
if obj.GetType() == 1019362:
doc.SetSelection(obj, c4d.SELECTION_ADD)
selected_object = doc.GetActiveObject()
current_rotation = selected_object.GetRelRot()
new_rotation = c4d.Vector(current_rotation.x , current_rotation.y - 1.570795765, current_rotation.z)
selected_object.SetRelRot(new_rotation)
c4d.EventAdd()
if __name__ == '__main__':
main()
# -------------------------------------------------------------
# REMOVE SDS TAGS
import c4d
def main():
doc = c4d.documents.GetActiveDocument()
all_objects = doc.GetObjects()
for obj in all_objects:
tags = obj.GetTags()
for tag in tags:
if "SDS" in tag.GetName().upper():
tag.Remove()
c4d.EventAdd()
if __name__ == '__main__':
main()
# -------------------------------------------------------------
# ADD MATERIAL LAYER
def GetFirstLayer(doc):
return doc.GetLayerObjectRoot().GetDown()
def main():
doc = c4d.documents.GetActiveDocument()
project_path = doc.GetDocumentPath()
path_components = project_path.split("\\")
last_word_after_backslash = path_components[-1]
print("{}".format(last_word_after_backslash))
fl = GetFirstLayer(doc)
name = last_word_after_backslash
nl = c4d.documents.LayerObject()
nl.SetName(name)
if not fl:
nl.InsertUnder(doc.GetLayerObjectRoot())
else:
nl.InsertAfter(fl)
c4d.EventAdd()
if __name__ == '__main__':
main()
# -------------------------------------------------------------
# ADD MATERIALS INTO LAYER
def main():
c4d.CallCommand(300001025) # Select All
c4d.CallCommand(200000148, 299989000) # Layer
if __name__=='__main__':
main()
# -------------------------------------------------------------
# DISABLE MATERIAL REFLECTANCE
import c4d
def main():
doc = c4d.documents.GetActiveDocument()
materials = doc.GetMaterials()
for material in materials:
material[c4d.MATERIAL_USE_REFLECTION] = False
c4d.EventAdd()
if __name__=='__main__':
main()