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 Sub
gr. Laszlo
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Thank you Hallex for patient.
Its still slow but maybe an other way than you mean.
The problem is the for...next:
For Each objlayer In objlayers
objlayer.Lock = True 'lock all the layers
Next objlayer.
I have 40 layers.
Maybe I have to use the sendcommand method for that?
ps. I changed "turn off" in "lock = true" too
Have a nice christmas!
Option Explicit Private Sub CommandButton1_Click() On Error Resume Next 'handle exceptions inline Dim objlayers As AcadLayers Dim objlayer As AcadLayer Set objlayers = ThisDrawing.Layers 'make the layer selected in the combobox current ThisDrawing.ActiveLayer = objlayers.Item(ComboBox1.Text) For Each objlayer In objlayers objlayer.Lock = True 'lock all the layers Next objlayer Set objlayer = objlayers.Item(ComboBox1.Text) If objlayer Is Nothing Then MsgBox "layer does not exist" Exit Sub 'exit if layer not found End If objlayer.Lock = False 'unlock the desired layer MsgBox "Done" 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
Are you using AutoCAD x64?
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
@Anonymous wrote:
Yes I do.....
???
Then read: http://adndevblog.typepad.com/autocad/2012/05/64-bit-vba-performance-issue.html
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Can't find what you're looking for? Ask the community or share your knowledge.