SOLVED Polygon corresponding to a selection


I would like to know if we can quickly obtain a polygon corresponding to a selection.

I manage to do it in python, but for the large meshes it's much too slow, because I do treatments on the indices of points and faces.

Below, with python, I create two polygons with the corresponding material, for the two selections (selection_1 and selection_2)
For a large mesh (greater than 100 Mo), the use of indices for points and faces considerably slows down the program.


We see that the initial polygon has been divided correctly, according to the two selections


You are mixing up polygon and polygon object interchangeably in your posts, so I'm not sure what you mean by "obtain a polygon corresponding to a selection". Assuming you mean exactly the stuff you're showing in the screenshots, you can use the high-level functionality instead of going poly by poly: take the selection tag, select the polys within, split off the selection with the fitting SendModelingCommand. You may need to delete the polys from the original, too.
This is most likely faster than handling all polys in Python, as SendModelingCommand will execute the functionality in the native C++ code.

@cairyn said in Polygon corresponding to a selection:


Indeed, with SendModelingCommand it would be faster.
I don't remember how we visualize with C4D the python code corresponding to the actions of the keyboard and the mouse.

I am going to write a new script, using c4d.CallCommand and c4d.utils.SendModelingCommand which can do the same thing much faster.
The Script log window presents the code very well, in real time, for many operations.

Hi @Kantronin I don't think there is that much to add but I want to mention that c4d.CallCommand automatically add an undo to the undo stack, while c4d.utils.SendModelingCommand with it's flags arguments can be defined. But you need to start and end the undo with the c4d.utils.SendModelingCommand, so this way you can have multiple SendModelingCommand within an undo.

See basedocument_undo example for undo management.