Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. lionlion44
    3. Topics
    L
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 4
    • Best 0
    • Controversial 0
    • Groups 0

    Topics created by lionlion44

    • L

      'Octane Renderer' menu settings not appearing when I switch render data to octane with python.

      Cinema 4D SDK
      • windows python 2025 • • lionlion44
      3
      0
      Votes
      3
      Posts
      165
      Views

      ferdinandF

      Hey @lionlion44,

      Thank you for reaching out to us. We cannot provide support on third party libraries (Octane). But, yes, in general you are on the right track. We have this C++ example, which I loosely translated to Python. The thing to do which you are missing, is to check if such VP already exists, as you otherwise can land in a world of hurt.

      For everything else, you would have to talk with the Octane devs (of which some are here on this forum), if there are any special further steps to be taken for Octane.

      Cheers,
      Ferdinand

      """Provides an example for generically setting a render engine in Cinema 4D. Note that there is no guarantee that every render engine has a video post node, and when it has one, that it uses the same ID as the render engine. But it is highly conventional to implement a render engine like this. Derived from the C++ Example "Set Render Engine to Redshift": https://developers.maxon.net/docs/cpp/2023_2/page_manual_redshift_rendrer.html """ import c4d import mxutils doc: c4d.documents.BaseDocument # The active Cinema 4D document. def SetRenderEngine(doc: c4d.documents.BaseDocument, newEngineId: int, createsVideoPostNode: bool) -> bool: """Sets the render engine of the given document to the specified ID. """ # Make sure we are on the main thread, as we plan to modify the document and ensure that our # inputs are what we think they are. if not c4d.threading.GeIsMainThread(): raise RuntimeError("SetRenderEngine must be called from the main thread.") mxutils.CheckType(doc, c4d.documents.BaseDocument) mxutils.CheckType(newEngineId, int) mxutils.CheckType(createsVideoPostNode, bool) # Get the currently active render engine ID and get out if it matches the new one. renderData: c4d.documents.RenderData = doc.GetActiveRenderData() currentEngineId: int = renderData[c4d.RDATA_RENDERENGINE] if currentEngineId == newEngineId: print(f"Render engine {newEngineId} is already set, no changes made.") return True # Try to find a video post with the render engine ID. There is no absolute guarantee that every # render engine either has a video post node or that is gives it the same ID as the render # engine (but it is strongly conventional). if createsVideoPostNode: # Try to find an already existing video post node with the render engine ID. node: c4d.documents.BaseVideoPost | None = renderData.GetFirstVideoPost() while node: if node.GetType() == newEngineId: break node = node.GetNext() # There is no video post for the render engine, so we try to a new create one. if not node: try: node: c4d.documents.BaseVideoPost = c4d.documents.BaseVideoPost(newEngineId) renderData.InsertVideoPost(node) except Exception as e: raise RuntimeError(f"Failed to create video post node for render engine {newEngineId} ({e}).") # Finally, we set the render engine ID in the render data. renderData[c4d.RDATA_RENDERENGINE] = newEngineId return True def main() -> None: """Called by Cinema 4D to run the script. """ # Setting the standard render engine, here we do not have to create a video post node, since # the standard renderer is one of the rare cases that does not have a dedicated video post. SetRenderEngine(doc, newEngineId=c4d.RDATA_RENDERENGINE_STANDARD, createsVideoPostNode=False) # Set Redshift as the render engine, which does have a video post node. SetRenderEngine(doc, newEngineId=c4d.VPrsrenderer, createsVideoPostNode=True) # Push an update event. c4d.EventAdd() if __name__ == "__main__": main()
    • L

      Automatically solo objects by using the 'path' of the object manager?

      Cinema 4D SDK
      • python r25 • • lionlion44
      4
      0
      Votes
      4
      Posts
      577
      Views

      ferdinandF

      Hey @lionlion44,

      Well, doing what you want to do is only halfway possible. An object being soloed just means setting the flag EHIDE on all othe objects. And while there is OHIDE which can be used to hide scene elements in managers, e.g., an object in the Object Manager, it is not being used by the 'Set as Root/Path Bar'-function of the Object Manager. So, you cannot hook into that.

      What you can do is just write a simple script which operates both flags for you. But to make this air-tight, you will have to implement a plugin (to avoid accidentally saving a scene with hidden elements).

      Cheers,
      Ferdinand

      Result

      Code """Demonstrates how to set the visibility of objects in the viewport and the managers. - When CTRL is not pressed while the script is invoked, the visibility state of the selected objects is set, i.e., everything that is not selected will be hidden. - When CTRL is pressed, the visibility state of the selected objects is cleared. - When HIDE_DESCENDANTS_OF_SELECTED_OBJECTS is set to True, the descendants of selected objects will be considered selected as well. WARNING: The visibility state is written PERMANENTLY into the scene graph, i.e., when one hides objects and saves the scene, the visibility state will be saved as well. One can of course just run the script while pressing CTRL to clear the visibility state of such saved and then loaded back scene, but this could possibly brick scenes for other users. To make this air-tight, one would have to implement a plugin which handles un-hiding objects before a scene is being saved (which is not super trivial in Python atm). Use this script at your own risk. """ __author__ = "Ferdinand Hoppe" __copyright__ = "Copyright 2025, Maxon Computer GmbH" import c4d import mxutils doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. # Wether to hide objects that are descendants of selected objects. I.e., when you have A-> B -> C, # and A is selected, B and C will be considered selected as well. HIDE_DESCENDANTS_OF_SELECTED_OBJECTS: bool = True def IsSelected(node: c4d.BaseObject) -> bool: """Returns if #node is selected or if any of its predecessors are selected (when selecting descendants implicitly is enabled). """ while node: if node.GetBit(c4d.BIT_ACTIVE): return True if not HIDE_DESCENDANTS_OF_SELECTED_OBJECTS: break node = node.GetUp() return False def SetObjectVisibility(doc: c4d.documents.BaseDocument, clearSate: bool = False) -> None: """Sets the visibility of the object in the managers and the viewport. """ for node in mxutils.IterateTree(doc.GetFirstObject(), True, True, True): isSelected: bool = clearSate or IsSelected(node) node.ChangeNBit(c4d.NBIT_OHIDE, c4d.NBITCONTROL_CLEAR if isSelected else c4d.NBITCONTROL_SET) node.ChangeNBit(c4d.NBIT_EHIDE, c4d.NBITCONTROL_CLEAR if isSelected else c4d.NBITCONTROL_SET) def main() -> None: """Called by Cinema 4D whhen the """ if not op: c4d.gui.MessageDialog("No object selected.") return state: c4d.BaseContainer = c4d.BaseContainer() if not c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE, 0, state): raise RuntimeError("Failed to get input state") ctrlIsPressed: bool = state[c4d.BFM_INPUT_QUALIFIER] & c4d.QUALIFIER_CTRL # If Ctrl is pressed, clear the visibility state, otherwise set it. SetObjectVisibility(doc, True if ctrlIsPressed else False) c4d.EventAdd() if __name__ == '__main__': main()