• Home
  • Training Books
  • Subscribe to Our Email Newsletter
  • About
    • Contributors
    • Feedback
    • Contact
    • Privacy policy
    • Cookie Policy

CADnotes

CAD Tutorials and Best Practices for professionals and students

  • Featured
  • AutoCAD
    • AutoLISP
  • Revit
    • Revit Architecture Basic
    • Revit MEP Basic Tutorial
  • Inventor
  • MicroStation
    • MicroStation Basic Tutorial
You are here: Home / AutoCAD / AutoLISP / AutoLISP: Filter selection with selection set

AutoLISP: Filter selection with selection set

July 26, 2011 by Edwin Prakoso Leave a Comment

In this Article...

  • The Object filter
  • More about selection filter
  • DXF code

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.

About Edwin Prakoso

I work as a Sr. Consultant in PT Cipta Satria Informatika. I've been using AutoCAD since R14 and Revit since Revit Building 9. I occasionally write for AUGIWorld magazine and I am also active in Autodesk discussion forum. I'm a member of Autodesk Expert Elite, an appreciation for individuals who give contributions to the Autodesk community.
Connect with me on twitter or LinkedIn.

Filed Under: AutoLISP Tagged With: selection, selection filter

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments

Featured

How to add dimensions in Revit 3D view

You can create a 3D view with dimension in Revit. Using visual effects on this view will make it a stunning image for your presentation!

Recent Articles

  • Autodesk Construction Cloud Activity Log
  • Exporting AutoCAD Plant 3D Model to Navisworks
  • Autodesk Data Connector for Power BI is Now Available

Advertisement

New on CADnotes

  • Autodesk Construction Cloud Activity Log
  • Exporting AutoCAD Plant 3D Model to Navisworks
  • Autodesk Data Connector for Power BI is Now Available
  • Autodesk Forma Design Contest
  • Revit 2025: Toposolid Enhancements

Meet the Authors

avatar for
avatar for
avatar for
avatar for
avatar for
avatar for

Get Connected

CADnotes on FacebookCADnotes on InstagramCADnotes on TwitterCADnotes on YouTube

© 2009 – 2025 CADnotes · Feedback · Privacy Policy · Become an affiliate

wpDiscuz