.NET

Reply
Mentor
mfernandes
Posts: 206
Registered: ‎08-21-2007
Message 1 of 4 (388 Views)

selection filter on multiple layers

388 Views, 3 Replies
04-25-2012 11:35 PM

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?

 

 

*Expert Elite*
Alfred.NESWADBA
Posts: 9,207
Registered: ‎06-29-2007
Message 2 of 4 (387 Views)

Re: selection filter on multiple layers

04-25-2012 11:43 PM in reply to: mfernandes

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
-------------------------------------------------------------------------
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 4 (382 Views)

Re: selection filter on multiple layers

04-26-2012 12:40 AM 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
Mentor
mfernandes
Posts: 206
Registered: ‎08-21-2007
Message 4 of 4 (375 Views)

Re: selection filter on multiple layers

04-26-2012 12:53 AM in reply to: Alfred.NESWADBA

Thanks Alfred

I am working way too late into the night.

In this case I need to wipe the egg of my face.:smileyembarrassed:

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

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.