Selection filters are very powerful device yet most of the times it is overlooked, using selection filters you can achieve many regular tasks of conditional selections.
In this snippet we will see, how you can leverage the selection filters to get a circle(s) from a given a centre point!
Do let me know if you have used conditional filters in any interesting scenario.
How do I prepare a conditional filter sequence ?
For example, we have a task to find all the MTEXT
entities with particular background mask color fill
From the above picture, we have few MText entities with different colors, suppose if I want to get a MText with green background color fill ?
First, I would check the entity information, I can use this entity information in building a selection filter, (entget (car (entsel)))
Applying this code and pick MTEXT entity with green background mask would give me
((-1 .) (0 . "MTEXT") (330 . ) (5 . "299") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbMText") (10 1495.9 1933.67 0.0) (40 . 2.5) (41 . 17.7906) (46 . 0.0) (71 . 1) (72 . 5) (1 . "AUTOCAD") (7 . "Standard") (210 0.0 0.0 1.0) (11 1.0 0.0 0.0) (42 . 16.8895) (43 . 2.58697) (50 . 0.0) (73 . 1) (44 . 1.0) (90 . 1) (63 . 3) (45 . 1.0) (441 . 0))
Now referring to MTEXT DXF reference, it is clear that DXF Code 90 is background mask on and 63 is the color when Background mask is enabled
Now, to pick all MTEXT entities with background color Green
The conditional filter would be (90 . 1) (63 . 3)
This give length of entities respecting our filter
(sslength (ssget "X" (list (cons 0 "MTEXT")(cons 90 1)(cons 63 3))))
Back to our topic, applying similar logic we can construct a code to filter circle based on given center point
AcDbObjectIdArray getCirclesFromAGivenPoint(AcGePoint3d centerPoint) { AcDbObjectIdArray idArray; ads_name ss, entName; /*Construct a filter list*/ resbuf* filterRb = acutBuildList(RTDXF0, L"CIRCLE", 10, asDblArray(centerPoint), RTNONE); bool hasSS = false; /*Make selection based on filtered list*/ if (acedSSGet(_T("_X"), NULL, NULL, filterRb, ss) == RTNORM) { Adesk::Int32 len; acedSSLength(ss, &len); if (len > 0) { hasSS = true; /*Collect and append the objectId to an array*/ for (int nEnt = 0; nEnt < len; nEnt++) { if (acedSSName(ss, nEnt,entName) == RTNORM) { AcDbObjectId selId; if (acdbGetObjectId(selId, entName) == Acad::eOk) idArray.append(selId); } } } freeResbuf(&filterRb); if (hasSS) acedSSFree(ss); } return idArray; }