Python command for "Convert Materials"?

Forums: Python command for "Convert Materials"?
Maxon Cinema 4D (Export script developed by abstrax, Integrated Plugin developed by aoktar)

Moderator: aoktar

Python command for "Convert Materials"?

Postby Hurricane046 » Thu Nov 16, 2023 8:35 am

Hurricane046 Thu Nov 16, 2023 8:35 am
Hello!

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.

Image

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()


2x RTX 2080 Ti | 2x RTX 2070 | 2x GTX 1080 Ti | 1x GTX 1080 | 1x GTX980 Ti
User avatar
Hurricane046
Licensed Customer
Licensed Customer
 
Posts: 78
Joined: Wed Jul 25, 2018 6:57 am

Return to Maxon Cinema 4D


Who is online

Users browsing this forum: No registered users and 24 guests

Sun Apr 28, 2024 8:27 am [ UTC ]