| Run Macro From Toolbar Button |
|
|
|
| Tutorials | |||
|
When creating macro's you can create shortcut buttons to get access from a toolbar. But before you are able to do so a module has to be created within the macro where the button can be assigned to. MANUAL OPTION Right click a button and select Customize. This wil show the image as below.
To run a macro when hitting the button fill in the Macro option. The string entered should be something like below. ^C^C_-vbarun;FILENAME.dvb!MODULNAME.SUBNAME FILENAME is the name of the project DVB file MODULNAME is the name of a module SUBNAME is the name of the subroutine in the Module, the routine that will be run (see sample below). AUTOMATIC OPTION
Add the folowing code to a module and run the Sub ToolbarButtonMain Sub ToolbarButtonMain()
'****************************************
'*** Code from VisibleVisual.com ********
'****************************************
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
' Create the new toolbar
Dim newToolBar As AcadToolbar
Set newToolBar = currMenuGroup.Toolbars.Add("TestToolbar")
' Add a button to the new toolbar
Dim newButton1 As AcadToolbarItem, newButton2 As AcadToolbarItem
Dim openMacro As String
' Assign the macro string the VB equivalent of "ESC ESC _open "
openMacro = "-VBARUN " & "SampleCmd1" & " " ' add a space to enmnu item to emulate the ENTER key]'
Set newButton1 = newToolBar.AddToolbarButton("", "NewButton1", "Sample Macro 1", openMacro)
Set newButton2 = newToolBar.AddToolbarButton("", "NewButton2", "Sample Macro 2", openMacro)
' Display the toolbar
newToolBar.Visible = True
End Sub
Sub SampleCmd1()
Dim tmpLayer As AcadLayer
Set tmpLayer = ThisDrawing.Layers.Item("0")
ThisDrawing.ActiveLayer = tmpLayer
ThisDrawing.SendCommand "Line "
End Sub
Sub SampleCmd2()
Dim tmpLayer As AcadLayer
Set tmpLayer = ThisDrawing.Layers.Item("0")
ThisDrawing.ActiveLayer = tmpLayer
ThisDrawing.SendCommand "Circle "
End Sub
|





Comments
RSS feed for comments to this post