Selection Set Manipulation

You can add entities to a selection set or remove them from it by calling the functions acedSSAdd() and acedSSDel(), which are similar to the Add and Remove options when AutoCAD interactively prompts the user to select objects or remove objects.

Note: The acedSSAdd() function can also be used to create a new selection set, as shown in the following example. As with acedSSGet(), acedSSAdd() creates a new selection set only if it returns RTNORM.

The following sample code fragment creates a selection set that includes the first and last entities in the current drawing.

ads_name fname, lname; // Entity names
ads_name ourset; // Selection set name
// Get the first entity in the drawing.
if (acdbEntNext(NULL, fname) != RTNORM) { 
    acdbFail("No entities in drawing\n"); 
    return BAD; 
} 
// Create a selection set that contains the first entity.
if (acedSSAdd(fname, NULL, ourset) != RTNORM) { 
    acdbFail("Unable to create selection set\n"); 
    return BAD; 
} 
// Get the last entity in the drawing.
if (acdbEntLast(lname) != RTNORM) { 
    acdbFail("No entities in drawing\n"); 
    return BAD; 
} 
// Add the last entity to the same selection set.
if (acedSSAdd(lname, ourset, ourset) != RTNORM) { 
    acdbFail("Unable to add entity to selection set\n"); 
    return BAD; 
 
} 

The example runs correctly even if there is only one entity in the database (in which case both acdbEntNext() and acdbEntLast() set their arguments to the same entity name). If acedSSAdd() is passed the name of an entity that is already in the selection set, it ignores the request and does not report an error.

As the example also illustrates, the second and third arguments to acedSSAdd() can be passed as the same selection set name. That is, if the call is successful, the selection set named by both arguments contains an additional member after acedSSAdd() returns (unless the specified entity was already in the selection set).

The following call removes the entity with which the selection set was created in the previous example.

acedSSDel(fname, ourset); 

If there is more than one entity in the drawing (that is, if fname and lname are not equal), the selection set ourset now contains only lname, the last entity in the drawing.

The function acedSSLength() returns the number of entities in a selection set, and acedSSMemb() tests whether a particular entity is a member of a selection set. Finally, the function acedSSName() returns the name of a particular entity in a selection set, using an index into the set (entities in a selection set are numbered from 0).

Note: Because selection sets can be quite large, the len argument returned by acedSSLength() must be declared as a long integer. The i argument used as an index in calls to acedSSName() must also be a long integer. (In this context, standard C compilers will correctly convert a plain integer.)

The following sample code shows a few calls to acedSSName().

ads_name sset, ent1, ent4, lastent; 
long ilast; 
// Create the selection set (by prompting the user).
acedSSGet(NULL, NULL, NULL, NULL, sset); 
// Get the name of first entity in sset.
if (acedSSName(sset, 0L, ent1) != RTNORM) 
    return BAD; 
// Get the name of the fourth entity in sset.
if (acedSSName(sset, 3L, ent4) != RTNORM) { 
    acdbFail("Need to select at least four entities\n"); 
    return BAD; 
} 
// Find the index of the last entity in sset.
if (acedSSLength(sset, &ilast) != RTNORM) 
    return BAD; 
// Get the name of the last entity in sset.
if (acedSSName(sset, ilast-1, lastent) != RTNORM) 
    return BAD;