Reading from the Project Settings
-
Hello, I was looking for a way to read some of the Project Settings of a document but I can't figure out the method. I know how to read some of them, the SDK example shown below, but how do I access the latter tabs? I'm struggling to read from the Simulation sub tabs specifically.
// This example switches the statue of the "Use Generators" setting. const BaseContainer data = doc->GetData(DOCUMENTSETTINGS::GENERAL); const Bool useGenerators = data.GetBool(DOCUMENT_USEGENERATORS); // set new settings BaseContainer settings; settings.SetBool(DOCUMENT_USEGENERATORS, !useGenerators); doc->SetData(DOCUMENTSETTINGS::GENERAL, settings);
Thanks for the help,
Dan -
Hello @d_schmidt,
Thank you for reaching out to us. This question has been answered here before. I have attached the Python code example below. The example is for Python and another paramater of the global simulation scene, but otherwise exactly what you need. When you need help with translating the example to C++, please say so in this thread.
The TLDR is here that not everything in the various places where Cinema 4D stores settings - world settings, document settings, render setting, im/export settings - is a literal in some settings container. Often more advanced settings are encapsulated by a node. This is also here the case where the 'Simulation' settings in the document settings are actually the default simulation scene stored in the simulation hook of the document.
Cheers,
Ferdinand"""Demonstrates how to access the global default simulation scene of the simulation hook. """ import c4d doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. c4d.SHsimulation: int = 1057220 # The ID of the simulation hook. def main() -> None: """Called by Cinema 4D when the script is being executed. """ # We must get the branches of the simulation hook and there the object branch to get hold of the # global default simulation scene. A branch is a way to express a generic relation between two # nodes, it is Cinema's way of expressing entity relationships beyond a simple parent-child # hierarchy. The actual relationship is between a node (GeListNode) and a branch head # (GeListhHead) which then can have traditional children. In a simplified manner, a scene can # look like this: # # Document 'MyScene' # ├── Objects Branch (Obase) # │ ├── Object1 # │ │ └── Tags Branch (Tbase) # │ │ ├── Tag1 # │ │ └── Tag2 # │ ├── Object2 # │ └── Object3 # ├── Materials Branch (Mbase) # │ ├── Material1 # │ │ └── Shaders Branch (Xbase) # │ │ ├── Shader1 # │ │ └── Shader2 # │ ├── Material2 # │ └── Material3 # └── Scene Hooks Branch (ID_BS_HOOK) # └── Simulation Hook # └── Object Branch (Obase) # └── Simulation Scene # Get the simulation hook of the active document, this will reach for us into the scene hooks # branch and return the simulation hook if it exists. simulationHook: c4d.BaseList2D | None = doc.FindSceneHook(c4d.SHsimulation) if not simulationHook: raise RuntimeError("Cannot find the simulation hook.") # Now we must pry out the object branch from the simulation hook. The branches of a node can # be accessed via the GetBranchInfo() method. This method returns a list of dictionaries, each # dictionary contains information about a branch, the relevant information for us is the branch # head and the branch ID. The branch ID is a unique identifier for the branch, the branch head is # the GeListHead object that represents the branch. branches: list[dict] = simulationHook.GetBranchInfo() data: dict | None = next(n for n in branches if n["id"] == c4d.Obase) # We look for the object branch. if not data: raise RuntimeError("Encountered malformed simulation hook with missing object branch.") # A branch is guaranteed to have have a branch head (so we can just blindly access it), but a # branch head may not have any children (should not be the case for the simulation hook). simulationScene: c4d.BaseObject | None = data["head"].GetFirst() if not simulationScene: raise RuntimeError("Encountered malformed simulation hook with missing object branch children.") print (simulationScene) simulationScene[c4d.PBDSCENE_SUBSTEPS] = 45 c4d.EventAdd() if __name__ == '__main__': main()
-