Introduction
Setting the properties of an image layer (layer) is very important to improve the efficiency of your work in AutoCAD.
This article details how to set layer properties in AutoCAD using Excel VBA.
Layer property settings
Basic VBA Codes
First, here is some basic VBA code to set the properties of a picture layer in AutoCAD.
Sub SetLayerProperties()
Dim acadApp As Object
Dim acadDoc As Object
Dim layer As Object
'Retrieve the AutoCAD application
Set acadApp = GetObject(,"AutoCAD.Application")
Set acadDoc = acadApp.ActiveDocument
'Get the target layer
On Error Resume Next
Set Layer = acadDoc.Layers.Item("TargetLayerName")
On Error GoTo 0
'Handle case when the target layer does not exist
If layer Is Nothing Then
MsgBox "The target layer was not found."
Exit Sub
End If
'Set properties for the layer
layer.Color = acBlue 'Color
layer.LineType = "LineTypeName" 'Line type
layer.LineWeight = acLnWt030 'Line weight
layer.PlotStyleName = "PlotStyleName" 'Plot style
layer.Transparency = 0 'Transparency
layer.Description = "This layer contains important drawings." 'Description
End Sub
Detailed Description
Get the AutoCAD application using the GetObject function.
Get the current document using the ActiveDocument property.
Get the target image layer using the Layers.Item method.
Set the layer attributes using the Coler, LineType, lineWeight, and Description properties.
For the LineType property, enter the name of the line type used in the layer.
Property Details
Color settings
Color is set using the Color property.
Code | Color Name | Color Number |
---|---|---|
acRED | Red | 1 |
acYellow | Yellow | 2 |
acGreen | Green | 3 |
acCyan | Cyan | 4 |
acBlue | Blue | 5 |
acMagenta | Magenta | 6 |
acWhite | White | 7 |
Line type setting
The line type is set using the LineType property. Use the name of the linetype loaded in the drawing. To check the line type loaded in the drawing, open AutoCAD, type “LUNETYPE” in the command line, and press the Enter key. This dialog box allows you to check the linetype.
Line thickness setting
Line thickness is set using the LineWeight property.
linetype name | Line weight |
---|---|
acLnWt005 | 0.05mm |
acLnWt013 | 0.13mm |
acLnWt020 | 0.20mm |
acLnwt030 | 0.30mm |
acLnWt050 | 0.50mm |
acLnWt100 | 1.00mm |
Print Style Settings
The print style is set using the PlotStyleName property.
Use the name used for the print style table active in the drawing.
To check the print style table, open AutoCAD, type “PLOTSTYLE” in the command line and press Enter to display the “Select Print Style” dialog box. You can check it in this dialog box.
Transparency Settings
Transparency is set using the Transparency property.
The range of transparency should be set from 0 to 90.
Setting Description
Description is set using the Description property. This is used to add a note or description for a layer.
summary
Setting up the properties of a picture layer is a fundamental step in streamlining your AutoCAD work; with VBA, you can automate these operations and save time.

Did you know you can tell someone’s personality by how they manage layers?
Organized layers: Perfectionist.
Random numbers for layers: Adventurer.
Everything on Layer 0: Absolute chaos.
コメント