How to set OOC parameters in octane Setting using python

Maxon Cinema 4D (Export script developed by abstrax, Integrated Plugin developed by aoktar)

Moderators: ChrisHekman, aoktar

Post Reply
lynnehoo
Licensed Customer
Posts: 1
Joined: Wed Mar 22, 2017 8:29 am

Code: Select all

import c4d

doc: c4d.documents.BaseDocument  # The currently active document.
op: c4d.BaseObject | None  # The primary selected object in `doc`. Can be `None`.

def main() -> None:
    """Called by Cinema 4D when the script is being executed.
    """
    oc_bc = doc.GetDataInstance().GetContainer(1029499)
    for k, v in oc_bc:
        print(k,v)

if __name__ == '__main__':
    main()
I tried to iterate and print all the keys and values in the container with ID 1029499, and I didn't get any key to set “RAM usage limit” or “GPU head room”, how can I use python to set the parameters in the out of core tab?

Any help would be appreciated, cheers!
Attachments
F6CD76FF-8169-4bf0-8A3E-5C7978582853.png
ShivaMist
Licensed Customer
Posts: 80
Joined: Thu Oct 11, 2018 5:07 pm
Location: Paris

You can find all the ID in vprenderer.h (c4doctane\res\description\vprenderer.h)

Here is some code i wrote a few months back but didn't have the time/resource to finish.
To be able to see the changes in the Octane Settings Windows you have to close it and reopen it so it can refresh the container. Same for the live viewer. (I hope this would change, it's very tedious to do anything in C4Dpython with the base containers. Redshift is much more simple since everything related to rendering/OCIO is located inside a VideoPost so it's really straightforward)

Hope it can help :)

Code: Select all

import c4d
from c4d import gui
ID_OCTANE_LIVEPLUGIN = 1029499
import re

def extract_definitions_from_h_file(h_file_path):
    with open(h_file_path, 'r') as h_file:
        h_file_text = h_file.read()
    # Regular expression pattern to match rows like "VP_RENDERSETTINGS_GRP = 1051,"
    pattern = r"(\w+)\s*=\s*(\d+),"
    matches = re.findall(pattern, h_file_text)
    # The dict now maps both ways: int -> string and string -> int
    definitions = {int(num): name for name, num in matches}
    definitions.update({name: int(num) for name, num in matches})
    
    return definitions

def describe_settings(data, definitions):
    for id_val, value in data:
        if id_val in definitions:
            print(f"{definitions[id_val]} ({id_val}): {value}")
        else:
            print(f"Unknown setting ({id_val}): {value}")

def get_octane_settings():
    doc = c4d.documents.GetActiveDocument()
    print("DOC : ", doc)
    data = doc[ID_OCTANE_LIVEPLUGIN]
    print("DATA : ", data)
    settings = data.GetClone(c4d.COPYFLAGS_PRIVATE_CONTAINER_COPY_DIRTY) 

    return settings

def set_octane_settings(settings):
    doc = c4d.documents.GetActiveDocument()
    data = doc[ID_OCTANE_LIVEPLUGIN]
    settings.CopyTo(data, c4d.COPYFLAGS_NONE)
    c4d.EventAdd()

def main():
    '''
    WIP : Accès a la majorité des paramètres de Octane
    #TODO : Créer une class de helpers
    '''
    
    doc = c4d.documents.GetActiveDocument()
    octane_settings = get_octane_settings()
    # print("OCTANE SETTINGS : ", octane_settings)
    h_file_text = r'D:\packages\softwares\octane\dev\c4d-2025\res\description\vprenderer.h'
    definitions = extract_definitions_from_h_file(h_file_text)
    describe_settings(octane_settings, definitions)
    # for d in octane_settings:
        # print(d)
    octane_settings.SetData(3001, 2)
    octane_settings.SetData(3076, 32)
    octane_settings.SetData(3168, 1)
    octane_settings.SetData(3130, 1)
    octane_settings.SetData(c4d.SET_CAMIMAGER_OCIO_VIEW, 'ACES: sRGB')
    octane_settings.SetVector(3190, c4d.Vector(0.5, 0.5, 0.5))
    octane_settings.SetData(c4d.SET_NEWGUI, 1)
    # octane_settings.CopyTo(data, c4d.COPYFLAGS_NONE)
     # # Update the document with the modified settings
    octane_settings.CopyTo(doc[ID_OCTANE_LIVEPLUGIN], c4d.COPYFLAGS_NONE)
    doc[ID_OCTANE_LIVEPLUGIN] = octane_settings
    # c4d.plugins.SetWorldPluginData(ID_OCTANE_LIVEPLUGIN, octane_settings, True)
    worldcontainer = c4d.plugins.GetWorldPluginData(ID_OCTANE_LIVEPLUGIN)
    container_130 = worldcontainer[130].GetClone(c4d.COPYFLAGS_PRIVATE_CONTAINER_COPY_DIRTY)
    container_131 = worldcontainer[131].GetClone(c4d.COPYFLAGS_PRIVATE_CONTAINER_COPY_DIRTY)
    print("WORLD CONTAINER BEFORE : ", worldcontainer)
    for d in worldcontainer:
        print(d)
    print("CONTAINER 130 - Jsp :( ): ", container_130)
    for d in container_130:
        print(d)
    print("CONTAINER 131 - OCIO Stuff : ", container_131)
    for d in container_131:
        print(d)
    # worldcontainer.SetData(13, 1)
    # worldcontainer.SetData(25, 10)
    # worldcontainer.SetData(32, 'my.exe')
    # print("WORLD CONTAINER AFTER : ", worldcontainer)
    # for d in worldcontainer:
    #     print(d)
    # container_131.CopyTo(worldcontainer[131], c4d.COPYFLAGS_NONE)
    # c4d.plugins.SetWorldPluginData(ID_OCTANE_LIVEPLUGIN, worldcontainer, True)
    # c4d.plugins.GetWorldPluginData(ID_OCTANE_LIVEPLUGIN)[131] = container_131
    # c4d.plugins.GetWorldPluginData(ID_OCTANE_LIVEPLUGIN)[130] = container_130
    c4d.plugins.SetWorldPluginData(ID_OCTANE_LIVEPLUGIN)[131].SetData(13, 32)
    c4d.EventAdd()
    c4d.CallCommand(1031195)
if __name__ == '__main__':
    main()

Code: Select all

"""
Boilerplate for Octane data management inside C4D 
- OctaneRenderDataHelper : Provides methods to read and write Octane-related RenderData
- OctaneSettingsHelper : Provides methods to read and write Octane-related settings inside C4D
- OctaneOCIOHelper : Provides methods to read and write OCIO-related settings inside Octane
"""
import c4d
import os
import re 

ID_OCTANE_LIVEPLUGIN = 1029499


class OctaneSettingsHelper():
    def __init__(self) -> None:
        pass        

    def get_octane_settings(self, doc=None):
        if not doc:
            doc = c4d.documents.GetActiveDocument()
        data = doc[ID_OCTANE_LIVEPLUGIN]
        settings = data.GetClone(c4d.COPYFLAGS_PRIVATE_CONTAINER_COPY_DIRTY)
        return settings

    def extract_definitions_from_h_file(self, h_file_path=None, file_name=None):
        if not file_name:
            file_name = 'vprenderer'
        if not h_file_path:
            octane_root = os.environ.get('REZ_OCTANE_ROOT')
            octane_root = octane_root.replace('\\', '/')
            print(octane_root)
            c4d_version = os.environ.get('REZ_C4D_MAJOR_VERSION')
            print(c4d_version)
            h_file = f'/c4d-{c4d_version}/c4doctane/res/description/{file_name}.h'
            print(h_file)
            h_file_path = octane_root + h_file
            h_file_path = os.path.normpath(h_file_path)
            print(h_file_path)
        with open(h_file_path, 'r') as h_file:
            h_file_text = h_file.read()
        pattern = r"(\w+)\s*=\s*(\d+),"
        matches = re.findall(pattern, h_file_text)
        definitions = {int(num): name for name, num in matches}
        definitions.update({name: int(num) for name, num in matches})
        return definitions

    def describe_settings(self, data, definitions):
        for id_val, value in data:
            if id_val in definitions:
                print(f"{definitions[id_val]} ({id_val}): {value}")
            else:
                print(f"Unknown setting ({id_val}): {value}")

filepath = r'D:\packages\softwares\octane\dev\c4d-2025\res\description\vprenderer.h'
helper = OctaneSettingsHelper()
definitions = helper.extract_definitions_from_h_file(h_file_path=filepath)
data = helper.get_octane_settings()
helper.describe_settings(data, definitions)
Post Reply

Return to “Maxon Cinema 4D”