Over 1.099.000 registered users (EN+CZ).
AutoCAD tips, Inventor tips, Revit tips, Civil tips, Fusion tips.
Try the new precise Engineering calculator.
New AutoCAD 2026 commands and variables.
Discussion forum
?CAD discussions, advices, exchange of experience

Please abide by the rules of this forum.
This is a peer-to-peer forum. The forum doesn't replace the official direct technical support provided by ARKANCE for its customers.
How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
|
Post Reply ![]() |
Page 12> |
Author | |
GaryM ![]() Newbie ![]() Joined: 20.Aug.2007 Location: South Africa Status: Offline Points: 16 |
![]() Posted: 20.Aug.2007 at 10:23 |
Hi
Looking for help on adding current layer names in you active drawings to a combo box? Let me explain what i would like to do. I designed a userform wich includes your basic layer operations turning ON & OFF, FREEZING, THAW etc, but know i would like to add a another function where you can delete a layer, but when you click the delete button it opens another userform where you can either pick a layer using a command button or select a layer in a combo box.
Know the question how would i code the form or combo box to go search for current layers in active drawing and list it in the combo box index.
I'm kinda rusty on my vba coding so any kind of help would be appreciated.
Cheers ![]() Edited by GaryM - 22.Aug.2007 at 15:58 |
|
Regards,
Gary Mansfield |
|
![]() |
|
Vladimir Michl ![]() Moderator Group ![]() Arkance Systems CZ Joined: 26.Jul.2007 Location: Czech Republic Using: Autodesk software Status: Offline Points: 2124 |
![]() |
You can look at the ThisDrawing.Layers collection and iterate through it.
|
|
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner |
|
![]() |
|
GaryM ![]() Newbie ![]() Joined: 20.Aug.2007 Location: South Africa Status: Offline Points: 16 |
![]() |
Thanks for the suggestion, but came right doing it another way... check it out!
Private Sub UserForm_Activate() Dim objLayers As AcadLayers Dim objLayer As AcadLayer 'search for layers in current drawing and add to combo box For Each objLayer In ThisDrawing.Layers frmDelLayer.cboLayerName.AddItem (objLayer.Name) Next End Sub |
|
Regards,
Gary Mansfield |
|
![]() |
|
Vladimir Michl ![]() Moderator Group ![]() Arkance Systems CZ Joined: 26.Jul.2007 Location: Czech Republic Using: Autodesk software Status: Offline Points: 2124 |
![]() |
Yes, this is the ThisDrawing.Layers iteration :-)
|
|
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner |
|
![]() |
|
GaryM ![]() Newbie ![]() Joined: 20.Aug.2007 Location: South Africa Status: Offline Points: 16 |
![]() |
HI
Now i'm struggling to delete a layer. How would i go about this... Here is the code i'm using. What i'm actually trying to do is that i want to select from the combo box a layer to delete. Here is the code i'm using; Private Sub cmdOk_Click() On Error Resume Next Dim strLayerName As String Dim objLayer As AcadLayer strLayerName = frmDelLayer.cboLayerName.Text Set objLayer = ThisDrawing.Layers(strLayerName) If objLayer Is Nothing Then MsgBox "Layer " & strLayerName & " not found" Exit Sub End If objLayer.Delete If Err Then MsgBox "Unable to delete layer: " & vbCr & Err.Description Else MsgBox "Layer '" & strLayerName & "' deleted" End If End Sub Giving me a error: "Object is referenced by other object(s)" Any ideas on what i'm doing wrong. |
|
Regards,
Gary Mansfield |
|
![]() |
|
Vladimir Michl ![]() Moderator Group ![]() Arkance Systems CZ Joined: 26.Jul.2007 Location: Czech Republic Using: Autodesk software Status: Offline Points: 2124 |
![]() |
The layer your are trying to delete is probably not empty (contains entities, is referenced from a block, etc.). You can only delete empty layers in this way.
|
|
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner |
|
![]() |
|
GaryM ![]() Newbie ![]() Joined: 20.Aug.2007 Location: South Africa Status: Offline Points: 16 |
![]() |
![]() Autocad gives you the LAYDEL command where you can delete layers with all entities etc. Is there anything similar i could do with vba? |
|
Regards,
Gary Mansfield |
|
![]() |
|
Vladimir Michl ![]() Moderator Group ![]() Arkance Systems CZ Joined: 26.Jul.2007 Location: Czech Republic Using: Autodesk software Status: Offline Points: 2124 |
![]() |
You can either write the code to remove all possible references to this layer or you can run LAYDEL from VBA (through SendCommand).
|
|
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner |
|
![]() |
|
GaryM ![]() Newbie ![]() Joined: 20.Aug.2007 Location: South Africa Status: Offline Points: 16 |
![]() |
How would i write the code to remove all possible references.
And the Sendcommand "LAYDEL" just activates the command does not actually delete the layer, you still l need to do the normal steps after the laydel command is entered. I want to delete from my delete layer form after selecting the layer from the combo box and clicking ok. |
|
Regards,
Gary Mansfield |
|
![]() |
|
Vladimir Michl ![]() Moderator Group ![]() Arkance Systems CZ Joined: 26.Jul.2007 Location: Czech Republic Using: Autodesk software Status: Offline Points: 2124 |
![]() |
The code would be quite complex - it would need to go through nested blocks, xrefs, etc.
Try to use LAYDEL - with all following options on the commandline - e.g.:
-LAYDEL Name mylayer
|
|
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner |
|
![]() |
Post Reply ![]() |
Page 12> |
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
This page was generated in 0,078 seconds.