AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Filtering Layers.

Ever wondered how to filter your drawing for specific layers?
Well here's how. This application will filter your drawing for a specific layer using the criteria that you will provide from within a sub-routine.
First of all the Function. Open a new module and add this coding : 

Option Explicit

Public Function LayerSelection(strLayerName As String, strSSName) _
As AcadSelectionSet
Dim ssObjects As AcadSelectionSet
Dim intCode(0) As Integer
Dim varData(0) As Variant
Dim objCheck As AcadSelectionSet
'declare variables

intCode(0) = 8
'set variable for the dxf code for layer

varData(0) = strLayerName
'set variable for the layer name

Set ssObjects = ThisDrawing.SelectionSets.Add(strSSName)
'create a selection eset

ssObjects.Select acSelectionSetAll, , , intCode, varData
'select all entities on the specified layer

Set LayerSelection = ssObjects
'create a reference to the selection

End Function 

Now add the sub-routine to run the function to the same module : 
Public Sub FilterLayer()
Dim ssLayrObj As AcadSelectionSet
'declare variables

Set ssLayrObj = LayerSelection("0", "vbdset")
'get the entities on the layer "0"

Dim obj As Object

For Each obj In ssLayrObj
'for each of the entities

obj.Highlight True
'highlight them

Next

ThisDrawing.SelectionSets.Item("vbdset").Delete
'delete the selection set

End Sub 

Run the macro "FilterLayer". All the entities on Layer 0 should be highlighted.
Now you've got them, you can do anything you like with them.
But that, I will leave to your imagination....... 
I would just like to thank Randall Raath for allowing me to 'steal' this.
(Saved me a lot of typing!!!!). 
If you would like to download the source code for this Application/s, then click Here
 
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright © 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website