June 20, 2013

Filter selection with selection set

4 Flares 4 Flares ×

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.

filter

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
"LAYER" "ANNO-DIMENSION"
"")
);END PROGRAM

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.

DXF code

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.

4 Flares Twitter 0 Facebook 4 LinkedIn 0 Google+ 0 Email -- Email to a friend 4 Flares ×

Advertisement



You might also interested to

About Edwin Prakoso

Edwin works as an Application Engineer in Jakarta, Indonesia. He has 4 years experience in building industry, then start to work for Autodesk reseller.
He is certified as Revit Architecture 2010 certified professional and AutoCAD 2013 certified professional.
He loves sharing his experience and starts to blog on CAD notes. Now using CAD is more to a lifestyle for him than working.
You can reach him on twitter @CADnotes. You can also connect with him on LinkedIn. If you prefer email, reach him at edwin.prakoso@cad-notes.com.