Change layer color when creating in vb

Posted on 2008-11-18
Last Modified: 2013-12-04

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.
Question by:melanel
    LVL 10

    Expert Comment

    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

    LVL 11

    Expert Comment

    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.
    LVL 10

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Our company has proprietary drawing files that we do not give to our customers for final documentation. Our customers now require that we give them these drawings. They understand that they are proprietary and do not require them to be in AutoCAD bu…
    The following article will describe how to add/edit a dimension style through AutoCAD VBA. AutoCAD VBA has its quirks and when it comes to dimensions and controlling how they look through VBA.  This is where AutoCAD can be vividly confusing. The…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now