Turning on layers with VBA

Turning on layers with VBA

Anonymous
Not applicable
1,151 Views
3 Replies
Message 1 of 4

Turning on layers with VBA

Anonymous
Not applicable

I have written VBA code in AutoCad that will open a certain drawing for the user, but I want it to turn on certain layers based on used input.  Let's say for this example I want to turn on the layer named "Walls".  How would I go about this?  The layer is off when the document is opened.  I'm sure this is a simple couple lines of code but I just can't seem to figure it out. 

 

thanks in advance! 

0 Likes
1,152 Views
3 Replies
Replies (3)
Message 2 of 4

timothy_crouse
Collaborator
Collaborator

I think you may have better answer results by posting thing question in the customization forum.

 

Best Regards

-Tim C.

Message 3 of 4

Anonymous
Not applicable

To turn a layer off (assuming the name is known and exists in the file):


With ThisDrawing.Layers("Walls")
.layeron = False
End With

To turn the layer on:


With ThisDrawing.Layers("Walls")
.layeron = True
End With

To make the "Walls" layer current:

 

ThisDrawing.ActiveLayer = ThisDrawing.Layers("Walls")

 

If you need to have the layer name be a "user-input" variable, that gets a bit more complicated, but can be done.

 

Hope this helps

0 Likes
Message 4 of 4

lena.talkhina
Alumni
Alumni

Hello @Anonymous  !

Great to see you here on VBA Forum.

Did you find a solution?
If yes, please click on the "Accept as Solution" button as then also other community users can easily find and benefit from the information.
If not please don't hesitate to give an update here in your topic so all members know what ́s the progression on your question is and what might be helpful to achieve what you ́re looking for. 🙂

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

0 Likes