Our Friends: Leaflet Printing , Presented by: Talia Cad Software

Sign In

Subscribe

Subscribe to Daily Autocad.


Dec 20
Saturday
AutoLISP, Programming
AutoLISP.8: Selection sets in AutoLISP programs

By this lesson, we will move on to advanced level. In most of the program that you will create by using AutoLISP, you may also need to make selections other then selections made by user. Or, you may want to filter some specific objects among the selection set created by user or all of the database of the drawing. Thus, for all of these reasons, you should learn about the selection sets and how to manage them.

First of all, let’s take a look at what happens when you enter any editing command in AutoCAD. For example, this is what happens when you enter ERASE command:

Select Objects:

appears in command line. You select entities either by picking, by a selection window or fence and then continue to make selection or exit. At this point, AutoCAD show the objects that you have selected so far as dashed. These entities are members of current selection set. By selecting a new entity, you add a new member to selection set; and when you remove a member by using REMOVE command, you erase a member from selection set. Making all of these operations inside AutoLISP is called creating a selection set and managing selection sets.

Creating a new selection set by using (ssget)

(ssget) function is used to create a selection set. This is how you use this function:

(ssget [sel-method] [pt1 [pt2]] [pt-list] [filter-list])

Arguments are explained as follows:

Selection Method [sel-method] (It is an alphanumerical value that determines the selection method.)
• ”C” crossing (rectangular fence selection type)
• ”CP” crossing polygon (polygon fence selection)
• ”F” fence (fence selection)
• ”I” implied (initially selected set)
• ”L” last (last drawn entitiy)
• ”P” previous (previous selected set)
• ”W” window (window selection)
• ”WP” window polygon (window shaped polygon selection)
• ”X” selects all of the entities inside the drawing (including entities in turned off LAYERS and invisible entities)
• ”:E” selects entities inside the pick-box at the end of drawing cursor
• ”:N” Selects sub-entities inside a complex object like BLOCK or POLYLINE inside the drawing.
• ”:S” Forces user to select one single entity.

[pt1 [pt2]]
If the selection set will be created by using a window, then pt1 and pt2 values determine the two corners of this window.

[point-list] Point list
• Point list  for “CP” “WP” and “F

[filter-list]
• If you are going to make filtering inside a selection set, then you should pass the corresponding list that belongs to it.

Examples:

Command:(ssget)
<Selection Set: 2>

It prompts the user to make a selection and returns the resultant new selection set when the selection is over.

Command: (ssget '(2 2))
nil

Selects and entity if there is one that passes through 2,2 point.

Command: (ssget "_P")
<Selection set: 4>

It creates a new selection set by using the previous selection set.

Command: (ssget "_C" '(0 0) '(1 1))
<Selection set: b>

It inserts into the selection set all of the entities that is included and touched by the crossing window that is made of corners of points 0,0 and 1,1.

Command: (ssget "_W" '(0 0) '(5 5))
<Selection set: d>

It creates a selection set from all of the entities that is inside the 0,0 and 5,5 window.

Command: (ssget "_I" '((0 . "LINE") (62 . 5)))
<Selection set: 4>

This example selects blue lines among entities that have been initially selected.  ‘((0 . “LINE”) (62 . 5)) this part is used to filter entities whose color is blue.

Command: (setq pt_list '((1 1)(3 1)(5 2)(2 4)))
((1 1) (3 1) (5 2) (2 4))
Command: (ssget "_CP" pt_list)
<Selection set: 13>

In this example, entities that is included or touched by the fence polygon that is composed of 1,1 3,1 5,2 2,4 points. You can also see how the point list is passed to ssget function.

Manipulating a selection set.

Fig.1
Fig.1

Once you create a selection set, you can add entities to it or remove entities from it, you can iterate among the objects inside it, or question those entities. In the example, we acquired the first and last entities inside the drawing by using entnext and entlast functions. This example will not work if there are no entities inside our drawing. If our selection set contains some entities, then this example creates a selection set from the first entity inside the drawing and adds the last entity to this selection set.

(ssdel fname ourset)

Above code erases the first entity of the drawing from the selection set. If there is one member inside the drawing, then first and last entity inside the drawing will be same and code will erase the selection set completely.

(sslength) function counts how many entities are there inside the selection set. If there is more then one element inside the drawing, then the example shown above will give the result of 2 when we call (sslength ourset).

Iterating though entities inside the selection set (ssname)

You can call entities inside the selection set by using ssname. Example that is shown below explains how ssname function is used.

Fig.2
Fig.2

Removing entities from selection set

You can remove entities from selection set by using ssdel function. As an example, we can remove ent1 entity from the selection set above by using the following code:

(ssdel ent1 sset)

Filtering selection set

You can make filtering according to the criterions that you want when creating a selection set. To do this, we must pass a filter list while creating a selection set. This list that you will create must be a list with dotted couple list similar to DXF code list. Below, you can find some examples:

Table.1
Table.1

That’s all for this lesson. In following lessons, I will try to give examples for selection sets.

Have a nice day.

Viewed 9,423 times so far... This week: 69 Today: 3 Latest: 5 July 2009, 1:18

Post Tags: , ,

8 Responses to “ AutoLISP.8: Selection sets in AutoLISP programs ”
  1. I have a question about grouping entities into a variable-
    I’m not sure if you should use “List” or “Sets”-
    Suppose your lisp program draws a series of lines, circles, and points…
    Now you wish to group these entities in a variable so you can manipulate them…
    For example you wish to “Rotate” or “Move” all these entities together-
    Can you explain or give me an example of how this can be accomplished?
    Thank you-
    Robert

  2. I am trying to write an autolisp routine to rename the layout tabs. I am having trouble with it picking up the existing ones (only ones with certain labels), sorting, and renaming. I would like to know if you know of any way to build in a “select multiple tabs” selection command into a lisp routine. So far I have been searching the internet and have not found anything on how to select the tabs (like ssget). Any information would greatly be appreciated.
    Thanks,
    Scott D.

  3. i want to know how to read, edit object data of an entity using AutoLisp/VisualLisp code

  4. I need to print the coordinates of the points in the drawing. How can I do it?

  5. Minver,

    We have an AutoLISP programme for this. In near future i’ll publish this utility on our download section.

  6. I want to know how to select the wipeout objects in a drawing through lisp.  I assume that this is a SSGET “X”  selection.  How does one determine the list of object codes of the various entities?

  7. I want to do “ copy” and” move”   by once  selection  of object . i writ follow lisp program but I want to reaplas  ” pause ” wiht an other command for once selection object.please help me.
       
    (setq p1′(0 0))
    (defun c:lift (/ cnt rise mrise)
    (setq cnt 1)
    (setq rise 0)
      (while T
              (setq rise (+ rise 0.35))
              (command “copy” pause “” “0,0″ (strcat (rtos rise 2 3) “,0″))
              (command “rotate” pause “” p1 cnt )
              (setq cnt(+ cnt 1)) 
       )
    )


Post a Comment



All content and source © 2008 Daily Autocad | News Plus wordpress theme brought to you by Zidalgo.