26 | 02 | 2017

Create AutoCad Toolbar

Use the code below to create a AutoCad Toolbar from VB or VBA

'--------------------------------------------------------------
Sub CreateVBAToolBar()
'--------------------------------------------------------------

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

Dim ObjToolbrs As AcadToolbars
Dim ObjToolbr As AcadToolbar
Dim ObjToolbrItem As AcadToolbarItem
Dim ToolBarname As String
Dim BMPlocation As String

ToolBarname = "VisibleVisual" 'Set Toolbar Name
BMPlocation = ".\" 'Set buttonimage location


Set ObjToolbrs = ThisDrawing.Application.MenuGroups.Item(0).Toolbars

'CREATE TOOLBAR

On Error Resume Next
'Check if the Toolbar exists if so then delete it first before creating it
Set ObjToolbr = ObjToolbrs.Add(ToolBarname)
If Err Then
Set ObjToolbr = ObjToolbrs.Item(ToolBarname)
ObjToolbr.Delete
Set ObjToolbr = ObjToolbrs.Add(ToolBarname)
End If

'CREATE TOOLBAR BUTTON

'Sample of Circle Button
Set ObjToolbrItem = ObjToolbr.AddToolbarButton(0, "Circle", "Add Circle", "Circle ")
Call ObjToolbrItem.SetBitmaps("Circle.BMP", BMPlocation & "Circle.BMP")

'Sample of Line Button
Set ObjToolbrItem = ObjToolbr.AddToolbarButton(0, "Line", "Add Line", "Line ")
Call ObjToolbrItem.SetBitmaps(BMPlocation & "Line.BMP", BMPlocation & "Line.BMP")

'Description for your own defined button
Set ObjToolbrItem = ObjToolbr.AddToolbarButton(0, "Add Button", "Add Button Description", "Add Button command")
Call ObjToolbrItem.SetBitmaps(BMPlocation & "buttonimage2.bmp", BMPlocation & "buttonimage3.BMP")

'To run a VBA project from the button macro add ("-vbarun" & vbcr & "Projectname.dvb!Modulename") as macro name

'Set the location of the toolbar acToolbarDockLeft, acToolbarDockRight , acToolbarDockTop , acToolbarDockFloating
ObjToolbr.Dock acToolbarDockRight

End Sub
Login

Sign up now and upload your code to the website.

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