Here is the complete list.
Hurricane Ike hit the area one month ago this Friday/Saturday. We are about 70 miles inland and most of the area here is back to "normal", as far as work and school go, but the closer you get towards the coast, the longer it will be until things are back to "normal". Many people I know even around here didn't have power restored until 2+ weeks after the storm. There are still some schools closed. Galveston and eastward are pretty much still a wreck.
A common site up in this area even a month later is the mountains of what used to be living trees, still piled along neighborhood streets.
Interstate 45 just north of the Galveston causeway, the day after the storm.
Highway 146 a few miles inland.
Some people think all of Texas is like this...
...but we do have a few towns here also... Downtown Houston after the storm.
Ok, getting back to the last (ssget) call in part 1...
(ssget "_W"The "_W" is the window selection method. Then we are passing it two points (5,5 and 8,8). Then we are telling it to only accept circle entities. The last two pieces tell it to only accept circles whose radius (DXF code 40) is less than 1.0.
So in summary, this bit of code will search the entire database and return only circles whose radius is less than 1.0 who also lie inside a polygon defined by the corners of 5,5 and 8,8.
The -4 group code is a special code that lets you perform relational testing. There are codes for equal, not equal, less than, less than or equal, greater than, greater than or equal, and two bitwise operators.
This type of filtering works great for locating entities on a certain layer, or that have a certain color or linetype. (ssget "_X"
'((0 . "LINE")(8 . "TEMP"))
)
The code above will select all LINE entities on the TEMP layer.
(ssget "_X"The code above will select all entity types on the TEMP layer whose color is green (3). Be careful when filtering for color, linetype and lineweight. These filters only apply if the particular property is explicitly set. In the example above, if the color of all entities on the TEMP layer is set to BYLAYER, the selection set will be empty, even if the color of layer TEMP is green (3).
You can use wildcard matching in selection set filtering also.
(ssget "_X"The code above will select all dimensions whose dimstyle is DIM## (where the # represents a single numeral). For example, a dimension whose dimstyle is DIM55 or DIM39 will be selected. Dimensions with a dimstyle of DIM4T, DIM777, DIMKK, or DIM are not selected. Other wildcard syntax can be found under the (wcmatch) function in the Autolisp Reference Guide.
You may have figured it out by now, but "AND" is implied when when combining multiple filters such as above. In other words, in the above example, it's going to find entities that have the type dimension AND whose dimension style is DIM##. There may be cases were you want to specify "AND", especially if you are using an "OR" also. (ssget "X"
'(
(-4 . "<OR")
(-4 . "<AND")
(0 . "CIRCLE")
(40 . 1.0)
(-4 . "AND<")
(-4 . "<AND")
(0 . "LINE")
(8 . "ABC")
(-4 . "AND<")
(-4 . "OR<")
)
)
The code above is straight out of the Autolisp Developer's Guide. It creates a selection set out of CIRCLE entities that have a radius of exactly 1.0 and LINE entities on the ABC layer. If you did not use the "OR" condition, then the (ssget) function would be trying to find entities that are a CIRCLE and a LINE, which is obviously impossible. Let's look at one more example.
(ssget '((0 . "POLYLINE,LWPOLYLINE")(-4 . "&")(70 . 1)))Last, but not least... The code above uses a "bitwise AND" to filter on a bit coded DXF code. In this case, DXF code 70 on a POLYLINE and/or LWPOLYLINE. The goal here is to create a selection set of closed polylines. If DXF code 70 has the "1" bit set, this indicates a closed polyline. However, we cannot simply filter for DXF code 70 = 1, because this is a bit coded field. If LTGEN is turned on and it's a closed polyline, then DXF code 70 will equal 129, not 1. This is why you must use the "&" (Bitwise AND) special filter.
There is much more information in the Autolisp Developer's Guide on advanced selection set handling. Good luck and post some of your examples in the comments section if you want.
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"More details on this code and other examples in part 2.
Notice that we did not directly define (S::STARTUP). Because this function can be defined in other places, it is best to append to it rather than overwrite it. Use (defun-q) to create a function defined as a list, so it can be appended. To finish the example from the previous post... ;;; acaddoc.lsp
(load "mylisp")
(load "another_lisp")
(load "\\\\server\\share\\a_lisp_and_specify_the_path")
(setvar "blipmode" 0)
(setvar "highlight" 1)
(defun-q mystartup ()
(command "._purge" "_R" "*" "_N")
(command "-scalelistedit" "_R" "_Y" "_E")
)
(setq S::STARTUP (append S::STARTUP mystartup))
;;; end acaddoc.lsp
If you have lisp routines that you want to make available in each drawing session, forget the "Startup Suite" and load them using the "acaddoc.lsp" file. "acaddoc.lsp" is not included with AutoCAD, you create it yourself. But it is nothing more than a plain lisp file, except that the first one found at drawing startup (just put it in your support file search path), is loaded automatically each time a drawing is opened.
Why use this approach instead of the "Startup Suite"? Ease of migration for one thing. When you upgrade from your current version of AutoCAD to the next version, simple add the path of your "acaddoc.lsp" file to the support file search path and your done. More details about this can be found here in a earlier article.
The second reason is that if you have more than one AutoCAD install to manage, using a networked copy of "acaddoc.lsp" means that you can control each machine using a single file as opposed to using the "Startup Suite" where your startup routines would have to be updated one machine at a time.
Remember that the file "acad.lsp" can contain startup code also, but "acad.lsp" is only loaded once per session of AutoCAD (assuming that the system variable ACADLSPASDOC is set to it's default value of zero). Each drawing has it's own lisp environment so it's necessary to load your startup lisp routines using "acaddoc.lsp" so that they will be loaded for each drawing.
Since "acaddoc.lsp" is like any other lisp file, it can contain functions and/or lisp code itself. Be careful when including lisp code because the (command) function should not be called until after AutoCAD initializes. You can do this safely by using the (s::startup) function. More on that next time.
Here is a sample "acaddoc.lsp" file.
;;; acaddoc.lsp