In the last tutorial, we learned how to use object selection in AutoLISP.
This time we will extend the object selection by using selection filter. Using filter in AutoLISP is very similar with using AutoCAD filter.
We can define which kind of object we want to select. We can define objects with specific properties to select.
For example, we can create a program to run and select dimensions in drawing, and move it to annotation layer. We will create this program in this tutorial.
This kind of program probably very simple, but can help you to maintain drawing standard.
As we did before, we can select all object using this line.
(setq sel1 (ssget "x"))
The Object filter
Now we want to select all dimensions in our drawing. To filter the selection, we can use this code:
(setq sel1 (ssget "x" '((0 . "DIMENSION"))))
The complete code become:
defun c:dimla (/ sel1 CLAYER )
(setq sel1 (ssget "X" '((0 . "DIMENSION")))) ; SELECT ALL DIMENSION
(setq OLDLAYER (getvar "CLAYER")) ;GET CURRENT LAYER
(command "_layer" "m" "ANNO-DIMENSION" "") ;CREATE NEW LAYER
(setvar "CLAYER" OLDLAYER) ; SET ACTIVE LAYER TO PREVIOUS
(command "CHPROP" sel1 "" ; CHANGE DIMENSION LAYER TO NEW LAYER
With that simple code, you can quickly find and move all dimensions to desired layer. Very useful, right? You can also modify it to allow user to check the selection visually before move dimensions to other layer.
More about selection filter
Afralisp covers this material in more advanced topic here. I won’t cover it further here, because they have detailed explanation about it. Go ahead, read more about conditional operators of selection filter there.
One more thing that you might want to know is the DXF code.
(0 . "DIMENSION") - Using DXF code 0 allows you to define object to select by objects type. This code will only allows you to select dimensions.
(8 . "ANNO-DIMENSION") - Using DXF code 8 allows you to define object to select by their layers. This code will only allows you to select objects on layer ANNO-DIMENSION.
We use DXF codes with selection filters in AutoLISP.
See the complete dxf associative code here.