Hi Ferdinand,
I just wanted to thank you for your invaluable help! Thanks to your guidance, I was able to solve my issue with toggling the default gravity in Cinema 4D. Honestly, I didn't think it would be this complicated! 😅
For anyone who might encounter a similar problem, here's the script I used, based on your code. It allows access to the global default simulation scene in the simulation hook and toggles the gravity value between 0 and -981:
import c4d doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in the document. Can be None. c4d.SHsimulation: int = 1057220 # The ID of the simulation hook. def main() -> None: """Called by Cinema 4D when the script is executed.""" # Get the simulation hook of the active document simulationHook: c4d.BaseList2D | None = doc.FindSceneHook(c4d.SHsimulation) if not simulationHook: raise RuntimeError("Cannot find the simulation hook.") # Retrieve the object branch from the simulation hook branches: list[dict] = simulationHook.GetBranchInfo() data: dict | None = next(n for n in branches if n["id"] == c4d.Obase) # We're looking for the object branch. if not data: raise RuntimeError("Malformed simulation hook with missing object branch.") # Get the simulation scene simulationScene: c4d.BaseObject | None = data["head"].GetFirst() if not simulationScene: raise RuntimeError("Malformed simulation hook with missing object branch children.") # Toggle gravity between 0 and -981 if simulationScene[c4d.PBDSCENE_DEFAULTGRAVITY] == 0: simulationScene[c4d.PBDSCENE_DEFAULTGRAVITY] = -981 else: simulationScene[c4d.PBDSCENE_DEFAULTGRAVITY] = 0 c4d.EventAdd() if __name__ == '__main__': main()This script toggles the default gravity of the simulation scene between 0 and -981 depending on its current value.
Thanks again for your help! I hope this can be useful to others who might face the same issue.