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.

AutoCAD Design Challenge… See the results


Wow! There are a lot of ways to get to the same result in AutoCAD!

Thanks to all of you that responded to the Autocad design chalnge Feel free to continue responding (in the comments section of the original post) with your solutions! In the mean time I decided to start posting some of the existing solutions with graphics and demos to help you visualize. There’s something to be learned from each solution… even if a particular step isn't the quickest option for this particular drawing, it might be for a different drawing!

This solution combines several of your solutions into one. It assumes default (install) values, options, and settings and it primarily uses the command line interface (CLI). I counted every click and keystroke (that was the REAL challenge) and included them in parenthesis at the end of each step. If you tend to use buttons and menus instead of the CLI, don’t let this scare you. The buttons and menus are a more intuitive and graphical way to access commands but when it comes to clicks and picks, the CLI is usually more efficient.

You can view a video of this solution or follow the steps below.

ADC01


X pick (Explode the polyline - 4)
O E 4 pick pick pick pick (Offset the two top lines 4 units up, automatically erasing the two original lines - 12)

ADC02

F M pick pick pick pick pick pick (Fillet the new lines and the two sets of parallel lines. The multiple options saves a few clicks. Also, notice fillet of two parallel lines automatically creates a 180deg arc between them - 11)

ADC03

pick pick pick (Grip edit to move the center of the circle to the center of the arc - 3)
pick pick pick (Gotta love grips! - 3)

ADC04

pick pick erase (In this case it saves you a click to select the Erase tool from the toolbar/ribbon rather than “3 ”... assuming it’s currently displayed, which it is by default - 3)

ADC05

So, if I counted correctly, the grand total for this solution is 36 picks, clicks, and keystrokes. Not bad!

  © Blogger template 'Perfection' by Ourblogtemplates.com 2008

Back to TOP