Home AutoCad VB Run Macro From Toolbar Button
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Run Macro From Toolbar Button PDF Print E-mail
User Rating: / 0
PoorBest 
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.

buttonmacro

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).

Show/Hidden vbnet code

View source
Sub SUBNAME()
 
 
 
	MsgBox "Succes, the macro will now run from the button"
 
 
 
	End Sub



AUTOMATIC OPTION

 

Add the folowing code to a module and run the Sub ToolbarButtonMain

Show/Hidden vbnet code

View source
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   

 
0 #3 Guest 2011-02-11 13:44
Once you get a good idea, you should make it as your value inspiration. Here you will find that everyone will learn something more or less from this blog, just dig into it!
Quote
 
 
0 #2 Guest 2010-11-04 21:38
muy buena
Quote
 
 
0 #1 Guest 2010-10-11 05:55
hellos.....Very good
Quote
 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade