Message 1 of 7
Not applicable
12-22-2012
10:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Why is the for next so slow?
I have a form with combobox filled up with 40 layers. The layers are from the layermanager.
The form has a command button too.
When I run this code. It's very slow to lock all layers.
Is there a solution for that?
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 Subgr. Laszlo
Solved! Go to Solution.

