Community
Hi!
Can someone help me a bit?
2 questions.
I have a form with a combobox and a commandbutton.
I try it with this code but it’s not the right solution.
Private Sub CommandButton1_Click() Dim layer As AcadLayer 'check if all layers are locked If layer.Lock = False Then layer.Lock = True 'make the layer selected in the combobox current ThisDrawing.ActiveLayer = ThisDrawing.Layers.Item(ComboBox1.Text) End Sub Private Sub UserForm_Initialize() Dim layerColl As AcadLayers Dim layer As AcadLayer Dim LayList As String ' all layers locked For Each layer In ThisDrawing.Layers If layer.Lock = False Then layer.Lock = True End If Next 'fill combobox Set layerColl = ThisDrawing.Layers For Each layer In layerColl ComboBox1.AddItem layer.Name Next End Sub
2. When I choose the for next method to lock all layers (40 layers) it’s very slow.
Is there a solution for that?
Gr. Laszlo
The first question I answered my self. I turned te code into this:
Private Sub CommandButton1_Click() On Error Resume Next 'handle exceptions inline Dim objlayer As AcadLayer 'make the layer selected in the combobox current ThisDrawing.ActiveLayer = ThisDrawing.Layers.Item(ComboBox1.Text) For Each objlayer In ThisDrawing.Layers objlayer.LayerOn = False 'turn off all the layers Next objlayer Set objlayer = ThisDrawing.Layers.Item(ComboBox1.Text) If objlayer Is Nothing Then MsgBox "layer does not exist" Exit Sub 'exit if layer not found End If objlayer.LayerOn = True 'turn on the desired layer End Sub Private Sub UserForm_Initialize() Dim layerColl As AcadLayers Dim objlayer As AcadLayer 'fill combobox Set layerColl = ThisDrawing.Layers For Each objlayer In layerColl ComboBox1.AddItem objlayer.Name Next End Sub
It is working but,
My second question: Why is it so slowly to locked all layers? Is there a solution?
gr Laszlo
Is this what you mean?
Private Sub CommandButton1_Click() On Error Resume Next 'handle exceptions inline Dim objlayer As AcadLayer 'make the layer selected in the combobox current ThisDrawing.ActiveLayer = ThisDrawing.Layers.Item(ComboBox1.Text) For Each objlayer In ThisDrawing.Layers objlayer.LayerOn = False 'turn off all the layers Next objlayer Dim objLayers As AcadLayers Set objLayers = ThisDrawing.Layers For Each objlayer In objLayers objlayer.LayerOn = False 'turn off all the layers Next objlayer Set objlayer = ThisDrawing.Layers.Item(ComboBox1.Text) If objlayer Is Nothing Then MsgBox "layer does not exist" Exit Sub 'exit if layer not found End If objlayer.LayerOn = True 'turn on the desired layer End Sub Private Sub UserForm_Initialize() Dim layerColl As AcadLayers Dim objlayer As AcadLayer 'fill combobox Set layerColl = ThisDrawing.Layers For Each objlayer In layerColl ComboBox1.AddItem objlayer.Name Next End Sub
It still slow!
gr. László
Above wrong code sorry!
See this code it's still slow (For next is slow)
Private Sub CommandButton1_Click() On Error Resume Next 'handle exceptions inline Dim objlayer As AcadLayer Dim objLayers As AcadLayers Set objLayers = ThisDrawing.Layers For Each objlayer In objLayers objlayer.LayerOn = False 'turn off all the layers Next objlayer Set objlayer = ThisDrawing.Layers.Item(ComboBox1.Text) If objlayer Is Nothing Then MsgBox "layer does not exist" Exit Sub 'exit if layer not found End If objlayer.LayerOn = True 'turn on the desired layer End Sub Private Sub UserForm_Initialize() Dim layerColl As AcadLayers Dim objlayer As AcadLayer 'fill combobox Set layerColl = ThisDrawing.Layers For Each objlayer In layerColl ComboBox1.AddItem objlayer.Name Next End Sub
help?