HAS MOVED TO http://cadpanacea.com
20 August 2008
Exploring the autolisp SSGET function - part 2          

Ok, getting back to the last (ssget) call in part 1...

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

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" 
'((8 . "TEMP")(62 . 3))
)

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" 
'((0 . "DIMENSION")(3 . "DIM##"))
)

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.

Labels: , ,


PermaLink       Posted 8/20/2008 08:59:00 PM     
1 COMMENTS!


Comment from: Blogger CES
Date: January 26, 2009 at 10:15:00 PM CST  

I want to use ">" symbol to filter text.

Post a comment