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

    python plugin in debugging mode

    Cinema 4D SDK
    2
    2
    756
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      Yaroslav
      last edited by Yaroslav

      Dear c4d fellows,
      Long ago I wrote a simple plugin for cinema4d in python.
      I didn't know how to code python back then, and learned it while writing the plugin.
      So I didn't even know how to debug the .pyp file in debugging mode.
      Now I decided to improve it. The question is: how to set up a debugging mode (the analogue of visual studio for c4d but for python). Is it possible? (I mean going line by line through pyp file and see the values of local variables in console)

      Yaroslav.

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by m_adam

        Hi @Yaroslav this is indeed possible however a bit clunky for the moment, but here a full step by step.

        1. Install pip with c4dpy -m ensurepip
        2. Install Python Visual Studio Debugger with c4dpy -m pip install ptvsd.
        3. Within Visual Studio in your launch.json just set up a basic attach setting, here is mine but for more information see
          Python debug configurations in Visual Studio Code.
        {
            "version": "0.2.0",
            "configurations": [
                {
                    "name": "Cinema 4D: Remote Debugger Attacher",
                    "type": "python",
                    "request": "attach",
                    "connect": {
                        "host": "127.0.0.1",
                        "port": 3000
                    },
                    "pathMappings": [
                        {
                            "localRoot": "${workspaceFolder}",
                            "remoteRoot": "."
                        }
                    ]
                },
            ]
        }
        
        1. The *.pyp plugin should be of course in the same workspace as your launch.json.
        2. Edit the *.pyp plugin and write the next code in the first line of your pyp file.
        import ptvsd
        ptvsd.enable_attach(address = ('127.0.0.1', 3000))
        
        1. Start Cinema 4D, wait until its UI is loaded, meaning the pyp plugin is loaded, and the client (your script) is attachable from a debugger.
        2. Run the previously created debug configuration (called Cinema 4D: Remote Debugger Attacher).
        3. Put a breakpoint somewhere (like in the Execute of a CommandData) to trigger the BP.
        4. Enjoy 😄

        Note this also works nicely for the script, however for script you should call ptvsd.wait_for_attach() after the ptvsd.enable_attach.

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • First post
          Last post