Handling Selection Sets

The ObjectARX functions that handle selection sets are similar to those in AutoLISP ® . The acedSSGet() function provides the most general means of creating a selection set. It creates a selection set in one of three ways:

int 
acedSSGet (
    const char *str, 
    const void *pt1,
    const void *pt2,
    const struct resbuf *entmask, 
    ads_name ss);

The first argument to acedSSGet() is a string that describes which selection options to use, as summarized in the following table.

Selection options for acedSSGet 

 

Selection Code

Description

NULL

Single-point selection (if pt1 is specified)

or user selection (if pt1 is also NULL)

#

Nongeometric (all, last, previous)

:$

Prompts supplied

.

User pick

:?

Other callbacks

A

All

B

Box

C

Crossing

CP

Crossing Polygon

:D

Duplicates OK

:E

Everything in aperture

F

Fence

G

Groups

I

Implied

:K

Keyword callbacks

L

Last

M

Multiple

P

Previous

:S

Force single object selection only

W

Window

WP

Window Polygon

X

Extended search (search whole database)

The next two arguments specify point values for the relevant options. (They should be NULL if they don't apply.) If the fourth argument, entmask, is not NULL, it points to the list of entity field values used in filtering. The fifth argument, ss, identifies the selection set's name.

The following code shows representative calls to acedSSGet(). As the acutBuildList() call illustrates, for the polygon options “CP” and “WP” (but not for “F”), acedSSGet() automatically closes the list of points. You don't need to build a list that specifies a final point identical to the first.

ads_point pt1, pt2, pt3, pt4; 
struct resbuf *pointlist; 
ads_name ssname; 
pt1[X] = pt1[Y] = pt1[Z] = 0.0; 
pt2[X] = pt2[Y] = 5.0; pt2[Z] = 0.0; 
// Get the current PICKFIRST set, if there is one; 
// otherwise, ask the user for a general entity selection. 
acedSSGet(NULL, NULL, NULL, NULL, ssname); 
// Get the current PICKFIRST set, if there is one. 
acedSSGet("I", NULL, NULL, NULL, ssname); 
// Selects the most recently selected objects. 
acedSSGet("P", NULL, NULL, NULL, ssname); 
// Selects the last entity added to the database. 
acedSSGet("L", NULL, NULL, NULL, ssname); 
// Selects entity passing through point (5,5). 
acedSSGet(NULL, pt2, NULL, NULL, ssname); 
// Selects entities inside the window from (0,0) to (5,5). 
acedSSGet("W", pt1, pt2, NULL, ssname); 
// Selects entities enclosed by the specified polygon. 
pt3[X] = 10.0; pt3[Y] = 5.0; pt3[Z] = 0.0; 
pt4[X] = 5.0; pt4[Y] = pt4[Z] = 0.0; 
pointlist = acutBuildList(RTPOINT, pt1, RTPOINT, pt2, 
	RTPOINT, pt3, RTPOINT, pt4, 0); 
acedSSGet("WP", pointlist, NULL, NULL, ssname); 
// Selects entities crossing the box from (0,0) to (5,5). 
acedSSGet("C", pt1, pt2, NULL, ssname); 
// Selects entities crossing the specified polygon. 
acedSSGet("CP", pointlist, NULL, NULL, ssname); 
acutRelRb(pointlist); 
// Selects the entities crossed by the specified fence. 
pt4[Y] = 15.0; pt4[Z] = 0.0; 
pointlist = acutBuildList(RTPOINT, pt1, RTPOINT, pt2, 
	RTPOINT, pt3, RTPOINT, pt4, 0); 
acedSSGet("F", pointlist, NULL, NULL, ssname); 
acutRelRb(pointlist); 

The complement of acedSSGet() is the acedSSFree() function, which releases a selection set once the application has finished using it. The selection set is specified by name. The following code fragment uses the ads_name declaration from the previous example.

acedSSFree(ssname); 
Note: AutoCAD cannot have more than 128 selection sets open at once. This limit includes the selection sets open in all concurrently running ObjectARX and AutoLISP applications. The limit may be different on your system. If the limit is reached, AutoCAD refuses to create more selection sets. Simultaneously managing a large number of selection sets is not recommended. Instead, keep a reasonable number of sets open at any given time, and call acedSSFree() to free unused selection sets as soon as possible. Unlike AutoLISP, the ObjectARX environment has no automatic garbage collection to free selection sets after they have been used. An application should always free its open selection sets when it receives a kUnloadDwgMsg, kEndMsg, or kQuitMsg message.