TheSwamp

Code Red => .NET => Topic started by: FELIX on September 14, 2012, 08:52:07 PM

Title: List Layers LISTBOX
Post by: FELIX on September 14, 2012, 08:52:07 PM
how to list the layers in the drawing to be displayed in a LISTBOX?
Title: Re: List Layers LISTBOX
Post by: BlackBox on September 15, 2012, 01:08:34 AM
Perhaps this thread will be of use:

http://www.theswamp.org/index.php?topic=42148.0
Title: Re: List Layers LISTBOX
Post by: fixo on September 15, 2012, 08: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'~
Title: Re: List Layers LISTBOX
Post by: FELIX on September 18, 2012, 09: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.
Title: Re: List Layers LISTBOX
Post by: fixo on September 19, 2012, 01:15:21 AM
You're welcome,
Glad I could help
Happy coding,

Oleg