Transitioning from 2d to 3d autocad drawings

Monday, March 16, 2009

Exploring the autolisp SSGET function - part 1


If you have written routines with Autolisp, then you have probably used the (ssget) function to select entities on the screen, either automatically or by prompting the user.

(ssget) is a powerful function that can do more than you probably realize. Let's look at a simple example.

(ssget '((0 . "TEXT")))

This prompts the user for a general selection set, but only TEXT entities are added to the resulting selection set.

(ssget '((0 . "*TEXT")))

Notice the wild card that was added. This is the same as above, except now any entity type that ends in TEXT is added to the selection set. At first, this looks like a good way to select TEXT and MTEXT, and it is. However, you have to be careful because this will also select RTEXT entities, and if your code is not equipped to deal with RTEXT, it may fail.

(ssget '((0 . "MTEXT,TEXT")))

This is a better way to select MTEXT and TEXT entities. But what if you don't want to bother the user to select entities, you just want to select ALL the MTEXT and TEXT entities in the drawing?

(ssget "_X" '((0 . "MTEXT,TEXT")))

Notice the "_X" that was added. This tells the (ssget) function to evaluate every entity in the drawing and then the filtering mechanism will filter out everything except MTEXT and TEXT. Entities on frozen layers are included when using the "_X" selection method.


Let's look at some other selection methods.

(ssget "_W" (list 5.0 5.0)(list 8.0 8.0))

Above is an example that will select objects inside a window from 5,5 to 8,8.

(ssget "_CP" (list (list 5.0 5.0)(list 8.0 8.0)(list 8.0 3.0)))

The line above will select all entities inside or touching a triangle defined by the points 5,5; 8,8; and 8,3. The CP is for crossing polygon.


The power of (ssget) comes from the incredibly fast filtering that it performs. Can you imagine having to evaluate an entire database of entities and manually filter out all the circles whose radius is less than 1.0 that fall inside a particular polygon? (ssget) can do this very fast. Example below.

(ssget "_W"
(list 5.0 5.0)(list 8.0 8.0)
'((0 . "CIRCLE")(-4 . "<")(40 . 1.0))
)

More details on this code and other examples in part 2.

0 comments:

  © Blogger template 'Perfection' by Ourblogtemplates.com 2008

Back to TOP