The function acedNEntSelP() provides an argument for context data, refstkres. (This is another feature not provided by acedEntSel().) The refstkres argument is a pointer to a linked list of result buffers that contains the names of the entity's container blocks. The list is ordered from lowest to highest. In other words, the first name in the list is the name of the block containing the selected entity, and the last name in the list is the name of the block that was directly inserted into the drawing. The following figure shows the format of this list.
If the selected entity entres is not a nested entity, refstkres is a NULL pointer. This is a convenient way to test whether or not the entity's coordinates need to be translated. (Because xformres is returned as the identity matrix for entities that are not nested, applying it to the coordinates of such entities does no harm but does cost some needless execution time.)
Using declarations from the previous acedNEntSelP() example, the name of the block that immediately contains the user-selected entity can be found by the following code (in the acedNEntSelP() call, the pickflag argument is FALSE for interactive selection).
status = acedNEntSelP(NULL, usrent, usrpt, FALSE, matrix, &containers); if ((status != RTNORM) || (containers == NULL)) return BAD; containent[0] = containers->resval.rlname[0]; containent[1] = containers->resval.rlname[1];
The name of the outermost container (that is, the entity originally inserted into the drawing) can be found by a sequence such as the following:
// Check that containers is not already NULL. rb = containers; while (rb != NULL) { prevrb = rb; rb = containers->rbnext; } // The result buffer pointed to by prevrb now contains the // name of the outermost block.
In the following example, the current coordinate system is the WCS. Using AutoCAD, create a block named SQUARE consisting of four lines.
Command: line
Specify first point: 1,1
Specify next point or [Undo]: 3,1
Specify next point or [Undo]: 3,3
Specify next point or [Close/Undo]: 1,3
Specify next point or [Close/Undo]: c
Command: -block
Enter block name or [?]: square
Specify insertion base point: 2,2
Select objects: Select the four lines you just drew
Select objects: ENTER
Then insert the block in a UCS rotated 45 degrees about the Z axis.
Command: ucs
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World] <World>: z
Specify rotation angle about Z axis <90>: 45
Command: -insert
Enter block name or [?]: square
Specify insertion point or [Scale/X/Y/Z/Rotate/PScale/PX/PY/PZ/PRotate]:7,0
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: ENTER
Enter Y scale factor <use X scale factor>: ENTER
Specify rotation angle <0>: ENTER
If an ObjectARX application calls acedNEntSelP() (or acedNEntSel()) and the user selects the lower-left side of the square, these functions set the entres argument to equal the name of the selected line. They set the pick point (ptres) to (6.46616,-1.0606,0.0) or a nearby point value. They return the transformation matrix (xformres) as shown in the following figure. Finally, they set the list of container entities (refstkres) to point to a single result buffer containing the entity name of the block SQUARE.