Author Topic: List Layers LISTBOX  (Read 640 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Newt
  • Posts: 40
List Layers LISTBOX
« on: September 14, 2012, 07:52:07 pm »
how to list the layers in the drawing to be displayed in a LISTBOX?
OK.

BlackBox

  • Gator
  • Posts: 2775
Re: List Layers LISTBOX
« Reply #1 on: September 15, 2012, 12:08:34 am »
Perhaps this thread will be of use:

http://www.theswamp.org/index.php?topic=42148.0
"Potential has a shelf life." - Margaret Atwood

fixo

  • Swamp Rat
  • Posts: 856
  • My location is not in the Hitleropa
Re: List Layers LISTBOX
« Reply #2 on: September 15, 2012, 07:51:20 am »
Try this code snip from my old code

Code: [Select]
     Public Class Form1

    Private listOfLayers As New List(Of String)
    ''-----------------------------------------------''

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim docs As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
        Dim doc As Document = docs.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Using tr As Transaction = doc.TransactionManager.StartTransaction
            Dim lt As LayerTable = DirectCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead, False), LayerTable)
            For Each lid As ObjectId In lt

                Dim ltr As LayerTableRecord = tr.GetObject(lid, OpenMode.ForRead)
                If lid.IsValid Then
                    listOfLayers.Add(ltr.Name)
                End If
            Next
            tr.Commit()
        End Using
        Me.lstLayers.DataSource = listOfLayers
    End Sub

I've used modeless form, so change to your suit, say
avoid to load xreferenced layers etc

~'J'~
\\\"Always drink upstream from the herd."\\\ - Will Rogers, was died in 1935 plane crash

--> Donate to TheSwamp <--

FELIX

  • Newt
  • Posts: 40
Re: List Layers LISTBOX
« Reply #3 on: September 18, 2012, 08:37:25 pm »
Fixed (Oleg) thank me for having collaborated once again. When you want to know the wonderful city (Rio de Janeiro-BR) I have great pleasure to welcome you in my apartment.
 OK.
OK.

fixo

  • Swamp Rat
  • Posts: 856
  • My location is not in the Hitleropa
Re: List Layers LISTBOX
« Reply #4 on: September 19, 2012, 12:15:21 am »
You're welcome,
Glad I could help
Happy coding,

Oleg
\\\"Always drink upstream from the herd."\\\ - Will Rogers, was died in 1935 plane crash

--> Donate to TheSwamp <--