Modifying the layers toolbar pulldown

Posted on 2005-04-12
Last Modified: 2012-05-05
In AutoCAD 2005, has anyone tried to or have had success with modifying the layers toolbar pulldown that displays the layers?
What I would like to be able to do is to display the layer descriptions instead of layer names in that pulldown.
If this is not possible, any ideas on a workaround?

For example, for our newbies, it would be easier for them to draw if they saw this in the pulldown
HVAC Piping (Cold)
Plumbing Riser (Waste)
Underground Utilities (Waste lines)

instead of this
Question by:haikle
    LVL 10

    Accepted Solution

    hey haikle,
    I dont think this can be done. I looked into creating some controls like that one time and it looked very difficult. I think they use objectarx for that so they are hard coded.  
    you could probably create a userform that would list the discriptions,  or make buttons that changed to specific layers when they wanted to draw specific things. Or create your own layer dropdown if you know how to use the objectarx sdk.
    LVL 5

    Author Comment

    Thanks norrin_radd

    I've never taken the plunge into objectarx.
    Looks like more work than I have time for.

    I currently have a VBA userform with the descriptions in a listbox but it's "bulky" and screen drawing area is a premium.
    I have a button on the form that reduces the userform size when not in use so that only the dropdown listbox and a "restore" button is visible.
    However, even when reduced in size, the form has a big title bar and can't be docked like a real dropdown toolbar.

    Too bad there's no way to make anything from VBA that is dockable.
    You gave an idea though.
    I'm going to play with toolbar button manipulations and see if I can make something workable.

    LVL 10

    Expert Comment

    <I'm going to play with toolbar button manipulations...>

    you could use that method in billpowell's post about getting variables from a button to run the select case routine for example
    to draw a hvac line on the right layer, hypothetic code ex:

    HVAC Piping (Cold) button:

    ^C^C(setvar "USERI1" 1) -vbarun;acad.dvb!module.routine


    Public Sub utilityline()

    Dim utility As String
    Dim CHANGELAY As AcadLayer
    Dim ZERORLAY As AcadLayer
    ThisDrawing.ActiveLinetype = ThisDrawing. _

    On Error Resume Next    ' trap any load errors
        ThisDrawing.Linetypes.Load "*", "linetype file"
    utility = ThisDrawing.GetVariable("USERI1")

    Select Case utility

    Case 1
    Set CHANGELAY = ThisDrawing.Layers.Add("M-HVAC-RSC")
    CHANGELAY.Color = acMagenta
    CHANGELAY.Linetype = "hvac"
    ThisDrawing.ActiveLayer = CHANGELAY
    ThisDrawing.SendCommand ("PL ")

    case 2
    thats part of some that I use modified to something you might could work with. just to share an idea with you.

    note if the layer is already there the .add line doesnt come up with any errors, but it will change the properties of that layer.
    I had that zerolay variable in there because I was thinking about setting 0 lay back as current after the routine was ran but never got around to figuring that out.
    LVL 5

    Author Comment

    I've written some simple codes to add a 'Layers' pulldown menu. There are two routines: UpdateLyrsPulldown and UnloadLyrsPulldown. The UpdateLyrsPulldown routine creates a 'Layers' pulldown menu, then reads all the layers in the current drawing and populates the pulldown with the layer names and descriptions. The user can select a layer from the pulldown and that layer is made active. The top two menu items are *Refresh* and *Remove 'Layers' pulldown*. The *Refresh* item refreshes the list of layers. The *Remove 'Layers' pulldown* item does just that; removes the pulldown.

    There are several ways to implement this. I chose to provide a button on an existing form. I have the UpdateLyrsPulldown routine assigned to a button on a layers utilities VBA form. You could also arrange to have the codes run upon acad startup.

    This is the best alternative I could come up with for the time being.

    I couldn't get buttons to do what I wanted but your suggestion did make me think of pulldown menus. Thanks.

    Public Sub UpdateLyrsPulldown()
    Dim currMenuGroup As AcadMenuGroup
    Dim mbTS_Layers As AcadMenuBar
    Dim LayersMenu As AcadPopupMenu
    Dim ct As Integer
    Dim i As Integer
    Dim x As Integer
    Dim strMacro As String
    Dim MenuItemName As String
    Dim ItemName As String

    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
    On Error GoTo errhandler

    'Try to insert a menu item 'Layers'
        Set LayersMenu = ThisDrawing.Application.MenuBar.Item("Layers")
        LayersMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.count + 1)
    'Delete all items from the 'Layers' menu
        ct = LayersMenu.count
        For i = ct - 1 To 0 Step -1
        Next i

    'Add 1st item to 'Layers' menu
    LayersMenu.AddMenuItem 0, "*Refresh*", "-vbarun UpdateLyrsPulldown "

    'Add 2nd item to 'Layers' menu
    LayersMenu.AddMenuItem 1, "*Remove 'Layers' pulldown*", "-vbarun UnloadLyrsPulldown "

    'Now add layer descriptions to 'Layers' menu
    With ThisDrawing.Layers

        For i = 0 To .count
            ItemName = .Item(i).Name 'Get layer name
            'ignore if name has "|". It is a ref
            If InStr(1, ItemName, "|", vbTextCompare) = 0 Then
                'Format layer name and description
                MenuItemName = "[" & Format(ItemName, ">") & "]  " & .Item(i).Description
                'Define macro string
                strMacro = Chr(3) & Chr(3) & Chr(95) & "-layer s " & ItemName & "  "
                'Add item
                LayersMenu.AddMenuItem i + 2, MenuItemName, strMacro
            End If
        Next i
    End With

    Exit Sub
        If Err.Number = -2145320939 Then   'Layers menu not defined
            Set LayersMenu = currMenuGroup.Menus.Add("Layers")
            Resume Next
        ElseIf Err.Number = -2147024809 Then   'Layers menu already inserted
            Resume Next
        End If

    End Sub

    Public Sub UnloadLyrsPulldown()
    Dim currMenuGroup As AcadMenuGroup
    Dim mbTS_Layers As AcadMenuBar
    Dim LayersMenu As AcadPopupMenu

    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)

    Set LayersMenu = ThisDrawing.Application.MenuBar.Item("Layers")

    End Sub
    LVL 10

    Expert Comment

    thats a pretty cool idea, I never even really thought about using layer descriptions before, I'll have to put it on my list of things to look into to.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    If, like me, you find yourself repeatedly and tediously joining many segments (lines, arcs) in other people's drawings back into polylines that can be used more effectively in Computer Aided Machining and Laser Cutting, then this article is for you!…
    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…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 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

    14 Experts available now in Live!

    Get 1:1 Help Now