Selections in python
-
Hi, how to work with selections in python, I need a script that receives two selected polygons as input and completes the selection of polygons to a rectangle with limited selected polygons
-
Hello @SemyonShapoval,
Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:
- Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
- Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
- Forum Structure and Features: Lines out how the forum works.
- Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you should follow the idea of keeping things short and mentioning your primary question in a clear manner.
About your First Question
The goal you're trying to achieve is not impossible (to an extent of ambiguity produced by its lacking any details description). However, it is out of support scope for this forum:
If necessary, we will provide code examples, but we will not provide full solutions or design applications.
You can refer to the github Extrude polygons example as a starting source of info on how to work with polygon objects and selected polygon data. You can use a simple code snippet below as a starting point for your investigation.
There's no such functionality in Cinema4D, so you need to develop proper algorithm yourself. However, it seems there're quite many of pitfalls and edge cases one needs to face for the functionality you describe (e.g. polys being triangles and quads, poorly polygonized meshes, meshes with islands etc.).
Let me know if you have any further questions.
Cheers,
IliaA starting point code snippet that prints out coordinates of the selected polygons:
import c4d doc: c4d.documents.BaseDocument def main() -> None: ops: list[c4d.BaseObject] = [item for item in doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) if item.CheckType(c4d.Opolygon)] if not len(ops): raise Exception('Please select polygons') pOp: c4d.PolygonObject = ops[0] print(f'Selected object: {pOp.GetName()}') selectedPolyIdcs: list[int] = [i for i, state in enumerate(pOp.GetPolygonS().GetAll(pOp.GetPolygonCount())) if state] if not len(selectedPolyIdcs): raise Exception('Please select polygons') polygons: list[c4d.CPolygon] = pOp.GetAllPolygons() points: list[c4d.Vector] = pOp.GetAllPoints() for sPolyIdx in selectedPolyIdcs: sp: c4d.CPolygon = polygons[sPolyIdx] spPoints: list[c4d.Vector] = [points[idx] for idx in (sp.a, sp.b, sp.c, sp.d)] print(f' Poly #{sPolyIdx}: {", ".join([str([p[i] for i in range(3)]) for p in spPoints])}') if __name__ == '__main__': main()
-
Hello @SemyonShapoval
without further questions or postings, we will consider this topic as solved by Friday, the 11th of august 2023 and flag it accordingly.
Thank you for your understanding,
Maxon SDK Group