.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

selection filter on multiple layers

6 REPLIES 6
Reply
Message 1 of 7
mfernandes
2210 Views, 6 Replies

selection filter on multiple layers

to select object on a single layer

Dim strLayer as string = "road"
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, strLayer), 2)

 how do you select all objects on multiple layers

Dim strLayer as string = "road,sidewalks"
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, strLayer), 2)

 the above does not work. any suggestions how do you select all objects on multiple layers?

 

 

6 REPLIES 6
Message 2 of 7

Hi,

 

what is the question or what is not clear? To select all objects on layer "road" and all objects on layer "sidewalks" you can use the statement you showed in the second code-snippet.

 

Or do I misinterpret your question?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 7
Hallex
in reply to: mfernandes

Try this code, tested on A2009

        <CommandMethod("multlayers", CommandFlags.UsePickSet And CommandFlags.Redraw)> _
        Public Sub SortManyLayers()

            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim db As Database = doc.Database

            Dim ed As Editor = doc.Editor

            Dim height As Double = 0.2

            Dim color As Integer = 256

            Dim tid As ObjectId = ObjectId.Null

            Dim ar As New ArrayList()

            Dim tr As Transaction = db.TransactionManager.StartTransaction()

            Using tr

                Try
                    Dim pso As PromptSelectionOptions = New PromptSelectionOptions

                    pso.MessageForRemoval = vbLf + "Select circles only"

                    pso.MessageForAdding = vbLf + "Select circles"

                    Dim tv As TypedValue() = New TypedValue() {New TypedValue(0, "circle"), New TypedValue(8, "0,BORDER-A,BORDER-B,BORDER-E1")}

                    Dim flt As New SelectionFilter(tv)

                    Dim res As PromptSelectionResult

                    res = ed.GetSelection(pso, flt)

                    If res.Status <> PromptStatus.OK Then
                        Return
                    End If

                    Dim sset As SelectionSet = res.Value

                    Dim n As Integer = 0

                    For Each obj As SelectedObject In sset

                        Dim dbobj As DBObject = tr.GetObject(obj.ObjectId, OpenMode.ForRead)

                        Dim circ As Circle = TryCast(dbobj, Circle)

                        If circ IsNot Nothing Then

                            'If n = 0 Then

                            Dim pt As Point3d = circ.Center

                            Dim cid As ObjectId = circ.ObjectId

                            Dim kp As New KeyValuePair(Of ObjectId, Point3d)(cid, pt)

                            ar.Add(kp)

                            'End If
                        End If
                    Next

                    ed.WriteMessage(vbLf & "Count Circles = " + ar.Count.ToString())

                    tr.Commit()


                Catch ex As System.Exception

                    ed.WriteMessage(ex.ToString)
                Finally
                    For Each kp As KeyValuePair(Of ObjectId, Point3d) In ar
                        ed.WriteMessage(vbLf + "ObjectID: {0}" + vbTab + "Center Point: {1}", kp.Key, kp.Value)
                    Next

                End Try

            End Using

        End Sub

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 7

Thanks Alfred

I am working way too late into the night.

In this case I need to wipe the egg of my face.Smiley Embarassed

I had an error in  my code in regards to my layer name, spelling. UG!!!!!!.....sorry.

 

so yes "Road,Sidewalks" will select all objects on layer Roads and objects on layer Sidewalks.

 

thanks

 

Message 5 of 7
BKSpurgeon
in reply to: mfernandes

HI 

 

I"m not expert, but i'm not sure that it will. how will autocad know that the comma acts as an OR operator (||)

 

Kean W has answered your exact question in a comment in the post below:

 

http://through-the-interface.typepad.com/through_the_interface/2008/05/finding-all-the.html

 

gluckand i hope this helps.

 

rgds

 

BK

Message 6 of 7
SENL1362
in reply to: BKSpurgeon

The "," is an illegal (layer) name character. Try creating a new layer using the input "a,b". It will create two layers: a and b.
Also the "|" is an illegal character, it's reserved to separate the current drawing layername with the Xref layername.

 

illegal layer characters.png

Both methodes

1. Name1, name2

2. OR Name1, Name2, ...

 

can be used to select items from several layers.

 

 

Message 7 of 7
_gile
in reply to: BKSpurgeon

Hi,

 

All string value in selection filter TypedValueS as DxfCode.LayerName (8), DxfCode.Start (0), DxfCode.BlockName (2), and so on, can use wildcard patterns.

 

Have a look at the help docs:

http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-3C1A759C-BB88-41A7-B1DE-697C493C92C8



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost