Fill listbox with layers

Fill listbox with layers

Anonymous
Not applicable
2,547 Views
8 Replies
Message 1 of 9

Fill listbox with layers

Anonymous
Not applicable

Hello , 

I'm looking for a solution for hours but i can't find

I am looking for a way to fill the listbox with all drawing layers. 

 

Excuse me for my English, this isn't my native language 

 

0 Likes
Accepted solutions (1)
2,548 Views
8 Replies
Replies (8)
Message 2 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

what is the question? Filling a listbox in a form or getting all layernames?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 9

Anonymous
Not applicable

Filling a listbox in a form.

 

My idea is this: When I click on the box, a drop-down menu or a list appears with all the names of the layers present in the drawing. That's why I want to use the box. Then I use the name of the layer chosen by the user to apply my code to this layer.

My probleme is that I can not fill the box, it remains empty.

it does not seem so complicated but I do not succeed. Do you have an idea how to proceed?

 

thank

0 Likes
Message 4 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I can not fill the box

There you find how to add items to a listbox >>>click<<<

If you show your code where you are we can discuss your lines and where exactly a conflict exists (might exist).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 5 of 9

Anonymous
Not applicable

Thank you for this link .

I will look in more detail at the content of the web page and keep you informed of the progress of my problem.  🙂

 

0 Likes
Message 6 of 9

Anonymous
Not applicable
Accepted solution

Yeah !! I have found !! 🙂

 

Code : 

Private Sub UserForm_Initialize()
Dim MyLayer As AcadLayer
Dim NomCalque As String
    For p = 0 To ThisDrawing.Layers.Count - 1
    NomCalque = ThisDrawing.Layers.Item(p).Name
    UserForm1.SelectCalque.AddItem NomCalque
    Next
End Sub

 In order for the listbox to be filled automatically when the UserForm is launched and not when you click on a button, you must place the code in Private Sub "Name of your UserForm"_ and the parameter "Initialize()".

0 Likes
Message 7 of 9

Anonymous
Not applicable
You could simplify your code a little:

Private Sub UserForm_Initialize()
Dim MyLayer As AcadLayer
For Each MyLayer in ThisDrawing.Layers
UserForm1.SelectCalque.AddItem MyLayer.Name
Next
End Sub


Or optimize it from the memory access point of view:

Private Sub UserForm_Initialize()
Dim MyLayer As AcadLayer
Dim MyLayers As AcadLayers
Set MyLayers = ThisDrawing.Layers
With UserForm1.SelectCalque
For Each MyLayer in MyLayers
.AddItem MyLayer.Name
Next
End With
End Sub

Although you should not notice any difference in actual processing time, you could adopt it as a good programming habit
Message 8 of 9

ASE-Rrenteria
Participant
Participant

Hello,

 

I have looked every which way and I have failed to find how to do this in c#. Example exists about adding a layer to a drawing, but it does not help me in filling a Listbox with the layer names of the current drawing. Could any of you guide  me?

 

Thank you so much.

0 Likes
Message 9 of 9

Ed__Jobe
Mentor
Mentor

The process is much different in C#. You should start a new question in the .NET forum. State if you are using a winform or a wpf form.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes