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

Show All the Layer's name In the ListBox

7 REPLIES 7
Reply
Message 1 of 8
gilseorin
346 Views, 7 Replies

Show All the Layer's name In the ListBox

Hi, everyone.
I need some help. Plz,check my code and advise me.
Thanks in advance.

Public Sub ShowAllLayerList()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Try
If ps Is Nothing Then
ps = New Autodesk.AutoCAD.Windows.PaletteSet("GilSeoRin")
Dim myForm As Modelessform = New Modelessform()
ps.Add("GilSeoRin", myForm)
ps.MinimumSize = New System.Drawing.Size(300, 300)
ps.Visible = True
End If

Dim curdb As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Dim lt As LayerTable = CType((tm.GetObject(curdb.LayerTableId, OpenMode.ForRead)), LayerTable)
For Each id As Object In lt

Dim ltr As LayerTableRecord = (CType(tm.GetObject(id, OpenMode.ForWrite), LayerTableRecord))
lt.UpgradeOpen()
Me.LayerList.Items.Add(ltr.Name)
Next
myT.Commit()
myT.Dispose()

Catch ex As System.Exception
ed.WriteMessage("Error Creating Palette: " + ex.Message)

End Try
End Sub
7 REPLIES 7
Message 2 of 8
NathTay
in reply to: gilseorin

At a quick glance. What is "lt.UpgradeOpen()" for. You should check the IsErased property of the LayerTableRecord. You are opening the LayerTableRecord for write when you only need for read.

Regards - Nathan
Message 3 of 8
gilseorin
in reply to: gilseorin

Thanks for the reply.
I rewrote my code as you advised.
No change,not yet. More advise,plz.
Message 4 of 8
gilseorin
in reply to: gilseorin

Public Sub ShowAllLayerList()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Try
If ps Is Nothing Then
ps = New Autodesk.AutoCAD.Windows.PaletteSet("GilSeoRin")
Dim myForm As Modelessform = New Modelessform()
ps.Add("GilSeoRin", myForm)
ps.MinimumSize = New System.Drawing.Size(300, 300)
ps.Visible = True
End If

Dim curdb As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Dim lt As LayerTable = CType((tm.GetObject(curdb.LayerTableId, OpenMode.ForRead, False, True)), LayerTable)
For Each id As Object In lt

Dim ltr As LayerTableRecord = (CType(tm.GetObject(id, OpenMode.ForRead, False, True), LayerTableRecord))
Me.FromLayerList.Items.Add(ltr.Name)
Me.ToLayerList.Items.Add(ltr.Name)
Next
myT.Commit()
myT.Dispose()

Catch ex As System.Exception
ed.WriteMessage("Error Creating Palette: " + ex.Message)

End Try
End Sub
Message 5 of 8
NathTay
in reply to: gilseorin

Untested.

Public Sub ShowAllLayerList()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Try
If ps Is Nothing Then
ps = New Autodesk.AutoCAD.Windows.PaletteSet("GilSeoRin")
Dim myForm As Modelessform = New Modelessform()
ps.Add("GilSeoRin", myForm)
ps.MinimumSize = New System.Drawing.Size(300, 300)
ps.Visible = True
End If

Dim curdb As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Dim lt As LayerTable = CType((tm.GetObject(curdb.LayerTableId, OpenMode.ForRead, False, True)), LayerTable)
Dim id As ObjectId
For Each id In lt
If Not id.IsErased Then
Dim ltr As LayerTableRecord = (CType(tm.GetObject(id, OpenMode.ForRead, False, True), LayerTableRecord))
Me.FromLayerList.Items.Add(ltr.Name)
Me.ToLayerList.Items.Add(ltr.Name)
End If
Next
myT.Commit()
myT.Dispose()

Catch ex As System.Exception
ed.WriteMessage("Error Creating Palette: " + ex.Message)

End Try
End Sub

If you get an error what is it?

Regards - Nathan
Message 6 of 8
gilseorin
in reply to: gilseorin

No error from first time.
Only could not be seen the list of all the layer at all.
I can't guess the reason at all.
I attatched the file contained whole code.

I am vs 2005,and autocad 2007 user.
Thanks.
Message 7 of 8
caddie75
in reply to: gilseorin

Hi,

Guess that You can't change controls this way....It's a UserControl and inside the CommandMethode you're trying to change values...

Try this: Add a button on You're UserControl and put the code to populate the listbox in it's click event...this works....

...to automatically let this happen You could put the code of creating layernames in the New-event or Load event of the UserControl.....

To update the Panel I guess You'll have to use events/reactors..

A Caddie
Message 8 of 8
gilseorin
in reply to: gilseorin

Your're right.
It works very well.
Thank you so much.
Happy day!

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