Layers

Layers control colors, linetypes and lineweights. Everything is on a layer.

The layer collection and layer object conform to the general object structure. in fact it would be an interesting exercise to write a generic structure description where the collection and item names could be interchanged with other types of entities.

To set a reference to an existing class_object use the Item property of the collection. Use either the string name or the index number. All collections are zero-based. The count property of the collection is one-based. To add a new class_object, use the Add property of the collection. If you reference with Item to an object that does not exist, you will receive “Key not found” error. If you add a class_object that already exists, you get a reference to the existing object.

You can iterate through the collection with
For Each class_object in collection

Next
Or
For i= 0 to collection.count – 1
Set class_object = collection.Item(i)

Next

Dim objlayers As AcadLayers
Dim objlayer As AcadLayer
Set objlayers = acadDoc.Layers
Set objlayer = objlayers.Item(“ABC”) ‘error if does not exist
Set objlayer = objlayers.Item(1)
Set objlayer = objlayers.Add(“ABC”) ‘returns reference if already exists

The new layer needs to be current for new entities to adopt its property. The ActiveLayer property of the drawing object is used.
Acaddoc.ActiveLayer = acadDoc.Layers.Item(“ABC”)
Acaddoc.ActiveLayer = objlayer

Application – Documents – Document – Layers – Layer
http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-D9F62B4B-401E-4AE6-969F-3F7756819EB6
http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-14F28A52-81E5-4CD0-AA79-ADC09E91BB8C

The Layers collection contains all the Layer objects in the drawing.
Layers collection – AcadLayers
Methods – Add Item
Properties – Count

Layer object – AcadLayer
Method – Delete
Properties – Used, Name, LayerOn, Freeze, Lock, TrueColor, Linetype,
Lineweight, PlotStyleName, Plottable, Description

Sub testnewlayer()
Call newlayer("AAA", 1, acLnWt035)
End Sub

Sub newlayer(strname As String, intcolor As Integer, lineweight As Integer)
Call connect_acad

Dim objlayers As AcadLayers
Dim objlayer As AcadLayer
Set objlayers = acadDoc.Layers

Set objlayer = objlayers.Add(strname)
    objlayer.Color = intcolor
  'note color is not currently a listed item in documentation but still works
    objlayer.lineweight = lineweight
    'acadDoc.ActiveLayer = acadDoc.Layers.Item(strname)
     acadDoc.ActiveLayer = objlayer

'default values of a new layer
'objlayer.Used = True
'objlayer.Name = "ABC"
'objlayer.LayerOn = True
'objlayer.Freeze = False
'objlayer.Lock = False
'objlayer.Color = 7 'this is the old 255 color method no longer documented 
'debug.print objlayer.TrueColor returns- object doesnt support this property or method
'debug.print objlayer.Color returns an integer you can use to read or set color
'objlayer.LineType = "Continuous"
'objlayer.LineWeight = -3
'objlayer.PlotStyleName = "Color_7"
'objlayer.Plottable = True
'objlayer.Description = ""

End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s