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

    Boundary Edges to Spline in Python

    Cinema 4D SDK
    s26 python 2024 2023
    2
    3
    817
    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.
    • F
      Futurium
      last edited by

      Hi,

      I am looking for assistance in automating a specific process in Cinema 4D using Python. My current manual method involves navigating to the Mode in the Attributes Panel, selecting Modelling and Mesh checking, and then opting for Check Mesh. Following this, I choose Boundary Edges and subsequently use the 'Edge to Spline' feature, which effectively transforms these edges into a spline.

      This manual method serves its purpose well; however, my goal is to streamline this process through automation. I would greatly appreciate any guidance or suggestions on how to achieve this via a Python script. Automating this task would significantly enhance efficiency in my workflow.

      Thank you for your time.

      Best regards,

      Tomasz

      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @Futurium
        last edited by i_mazlov

        Hi Tomasz,

        There're 3 steps you need to accomplish:

        1. Enable Check mesh tool
        • The mesh checking settings live in a snap scene hook, so this is how you access it. Unfortunately its not that easy as with snap settings, but you can iterate over BranchInfo of the snap scene hook and find the modeling settings one (check getModelingSettings() function in the script below).
        1. Make corresponding selection
        • You need to call the corresponding button. In C++ you normally do this using the DescriptionCommand, but in python you can simply use CallButton() function.
        1. Run corresponding command
        • Just an ordinary usage of SendModelingCommand(). Specifically for the edge to spline command is discussed in the thread: Edge To Spline Modeling Command

        Please find the code sketch that presumable does what you need below.

        Cheers,
        Ilia

        Draft code snippet:

        import c4d
        
        doc: c4d.documents.BaseDocument  # The currently active document.
        
        ID_SNAP_SCENEHOOK = 440000111
        
        def getModelingSettings() -> c4d.GeListNode:
            # Find Snap scene hook
            snapHook: c4d.BaseList2D = doc.FindSceneHook(ID_SNAP_SCENEHOOK)
        
            # Search for the modeling settings in its branch info
            branchInfo: dict
            for branchInfo in snapHook.GetBranchInfo():
                if branchInfo.get('name') != 'MdSH':
                    continue
                head: c4d.GeListHead
                if head := branchInfo.get('head'):
                    return head.GetFirst()
            
            return None
        
        def main() -> None:
            # Retrieve modeling settings
            ModelingSettings: c4d.GeListNode = getModelingSettings()
            if not ModelingSettings:
                return print('Unexpected error')
            
            # Enable mesh check
            ModelingSettings[c4d.MESH_CHECK_ENABLED] = True
        
            # Call select boundary edges button
            c4d.CallButton(ModelingSettings, c4d.MESH_CHECK_BOUNDARY_SELECT)
        
            # Run edge to spline command
            objects: list[c4d.BaseList2D] = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_NONE)
            if not c4d.utils.SendModelingCommand(c4d.MCOMMAND_EDGE_TO_SPLINE, objects, c4d.MODELINGCOMMANDMODE_EDGESELECTION):
                print('Error on SendModelingCommand() execution')
            
            c4d.EventAdd()
        
        
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 2
        • F
          Futurium
          last edited by

          Dear Ilia,

          I greatly appreciate your assistance; it was precisely what I needed. Thank you for your guidance and I wish you a wonderful day.

          Best regards,
          Tomasz

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