Boundary Edges to Spline in Python
-
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
-
Hi Tomasz,
There're 3 steps you need to accomplish:
- 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).
- 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.
- 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,
IliaDraft 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()
-
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