• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 844
  • Last Modified:

Change layer color when creating in vb


I'm trying to change the color of a layer I just created and I can't.
This is how I'm creating the layer:

Dim lay As AcadLayer
Dim found As Boolean

found = False
For Each lay In dw.Layers
    If UCase(lay.Name) = UCase(lname) Then
        found = True
        Exit For
    End If
If Not found Then
    Set lay = dw.Layers.Add(lname)
    'change color here
End If

Can you help me with this? I tried with truecolor property but I have no idea how to do it.
Thank you.
  • 2
1 Solution
Try this:
If Not found Then
    Set lay = dw.Layers.Add(lname)
    With lay
    .color = acCyan 'or whatever you choose
    end With 
End If

Open in new window

Use of the Color property is not recommended. From the 2009 Developer Documentation....

"This property is obsolete and will be removed in a future version."

There's plenty of examples of setting the color using the TrueColor property in the developer documentation.
hey  melanel,
 if your are still using 2006 that code should still work.
 the documentation for 2008 has the same entry that darren mentioned and it looks like its been there for a while at least since 2006 or 2004 when they introduced truecolor. There is no telling when they will discontinue the property. I know that there are still obsolete features from older versions still there.
but thats no excuse to deliberately do something that is doomed or not recommended.  ;)
not sure what the dev documentation has in it but if it doesnt help you may want to look at this code also check this link that mey help you out:

I'll probably keep my old code untill I cant use it anymore just for grins ;)

good luck
Dim color As AcadAcCmColor
Set color = _
Call color.SetRGB(241, 162, 14)
entity.TrueColor = color

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now