20 | 09 | 2017

Last Commands Toolbar

Most AutoCad users have all commands programmed as shortkeys on the keyboard. But for some people is still the pressing the button method easier and the only routined way of using AutoCad. For this we created a peace of code that will allow you to create a toolbar that will be updated with the last 10 entered commands. Add this code to your template or to the startup of AutoCad to see how it functions.

Last Command Toolbar

"Impression of the Last Command toolbar"

Private Sub AcadDocument_BeginCommand(ByVal Commandname As String)

'*** Code from VisibleVisual.com ********

'Run the code every time a command is activated
GetButtonImage Commandname

End Sub

Function GetButtonImage(ByVal Commandname As String) As String

'Cycle through all toolbars and search for the button with the same ID
'When the ID is found the Button details are passed on

Dim Button As AcadToolbarItem
Dim Toolbar0 As AcadToolbar
Dim MenuGroup0 As AcadMenuGroup
Dim SmallButtonName As String
Dim LargeButtonName As String

For i = 0 To ThisDrawing.Application.MenuGroups.Count - 1

Set MenuGroup0 = ThisDrawing.Application.MenuGroups.Item(i)
    For j = 0 To MenuGroup0.Toolbars.Count - 1
    Set Toolbar0 = MenuGroup0.Toolbars.Item(j)

        For Each Button In Toolbar0
                If StrConv(Button.TagString, vbUpperCase) = "ID_" & StrConv(Commandname, vbUpperCase) Then
                Button.GetBitmaps SmallButtonName, LargeButtonName
                GetButtonImage = SmallButtonName
                CreateToolbar GetButtonImage, Commandname
                Exit Function
                End If
        Next Button

    Next j
Next i

'If there is no icon then continue and use the AutoCad default blank icon
CreateToolbar Commandname, Commandname

Exit Function

End Function


Sub CreateToolbar(ByVal BitmapName As String, Command As String)

    Dim currMenuGroup As AcadMenuGroup
    Dim newToolBar As AcadToolbar, newToolBarButton As AcadToolbarItem
    Dim openMacro As String
    Dim NameofButton As String
    On Error GoTo Errorhandler
    ' Use MenuGroups property to obtain reference to main AutoCAD menu
    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item("ACAD")
    ToolBarname = "LatestCommands"
    ButtonAmnt = 10 ' Change the number to show more or less buttons on the toolbar
    On Error Resume Next
    'Check if the Toolbar exists if so then delete it first before creating it
    Set newToolBar = currMenuGroup.Toolbars.Item(ToolBarname)

    If Err Then
        Set newToolBar = currMenuGroup.Toolbars.Add(ToolBarname)
        newToolBar.Dock acToolbarRight 'Position of the toolbar
    End If
    newToolBar.Visible = True
    If newToolBar.Count > ButtonAmnt - 1 Then
        NameofButton = newToolBar.Item(0).Name
        Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1, _ NameofButton, Command, Command & " ", False)
A         Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1, _ "CMDBUTTON" & newToolBar.Count,         Command, Command & " ", False)
    End If
    newToolBarButton.SetBitmaps BitmapName, BitmapName
Exit Sub
End Sub

Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles