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. lakpo
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 2
    • Best 0
    • Controversial 0
    • Groups 0

    lakpo

    @lakpo

    0
    Reputation
    3
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    lakpo Unfollow Follow

    Latest posts made by lakpo

    • RE: How to access and modify the default gravity value of the scene using Python script in Cinema 4D?

      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.

      posted in Cinema 4D SDK
      lakpoL
      lakpo
    • How to access and modify the default gravity value of the scene using Python script in Cinema 4D?

      Hi everyone,

      I'm working on a Python script in Cinema 4D and I'm trying to toggle the default gravity of the scene between 0 and -981. I've tried several approaches, but I can't seem to find the correct method to access and modify this value.

      Here's what I've attempted so far:

      from typing import Optional
      import c4d
      
      doc: c4d.documents.BaseDocument  # The active document
      op: Optional[c4d.BaseObject]  # The active object, None if unselected
      
      def main() -> None:
          def object() -> Optional[c4d.BaseObject]:
              return doc.GetActiveObject()
      
          active_object = object()
          if not active_object:
              return
      
          current_gravity = active_object[c4d.PBDSCENE_DEFAULTGRAVITY]
          if current_gravity == 0:
              active_object[c4d.PBDSCENE_DEFAULTGRAVITY] = -981
          else:
              active_object[c4d.PBDSCENE_DEFAULTGRAVITY] = 0
      
      if __name__ == '__main__':
          main()
          c4d.EventAdd()
      

      Unfortunately, this doesn't work. If anyone can point me to the correct way to access and modify this value, that would be great!

      Thanks in advance for your help! 😊

      posted in Cinema 4D SDK python
      lakpoL
      lakpo