PDA

View Full Version : Create ACAD command to run VBA routine



MikeS
04-08-2005, 06:56 AM
Is there a way to create a command in AutoCAD that will run a VBA routine? I know there is the command VBARUN, but I would like to be able to run a VBA routine, and then simply right click to run it again. Thanks.

Tommy
04-08-2005, 11:03 AM
So what you are asking is if there is a way to run a vba command from the context menu?


I will have to get back on this. More than likely there is :)

MikeS
04-08-2005, 11:07 AM
Yeah. I'd like to be able to just type a command or shortcut at the AutoCAD command line to run a VBA routine.

Tommy
04-10-2005, 05:25 PM
As you can tell I butchered the help file some :). If you have popupmenus enabled the first item on the menu will be the vba macro that is in the Macro property. If the project is not loaded it will load, then executes. otherwise it executes macro. The popup name I used was "Try This" the macro was "HiYa".



Private Sub AcadDocument_BeginShortcutMenuDefault(ShortcutMenu As AutoCAD.IAcadPopupMenu)
' This example intercepts a shortcut menu start while you are in the default mode.
'
'MsgBox "You have just initiated a shortcut menu in default mode!"
Dim I As Integer
Dim MakeIt As Boolean
For I = ShortcutMenu.Count - 1 To 0 Step -1
If ShortcutMenu.Item(I).Caption = "Try This" Then
'ShortcutMenu.Item(I).Delete
'MakeIt = True
MakeIt = False
Else
MakeIt = True
End If
Next
If MakeIt Then
'ShortcutMenu.addMenuItem 0, "Try This", "-vbarun ""C:/Program Files/AutoCAD 2000i/Sample/VBA/tryforpopup.dvb""!ACADProject.ThisDrawing.HiYa "
ShortcutMenu.addMenuItem 0, "Try This", "-vbarun ACADProject.ThisDrawing.HiYa "
' syntax "-vbarun ""filelocation""!projectname.module.sub "
'if macro is loaded when this project is load ACADProject.ThisDrawing.HiYa is all tht is required
End If
End Sub
Private Sub AcadDocument_EndShortcutMenu(ShortcutMenu As IAcadPopupMenu)
'shortcutmenu.
' clean up so it is not left over
Dim I As Integer
For I = ShortcutMenu.Count - 1 To 0 Step -1
If ShortcutMenu.Item(I).Caption = "Try This" Then
ShortcutMenu.Item(I).Delete
End If
Next
End Sub




Happy Coding :thumb

Tommy
04-12-2005, 04:22 PM
MikeS, if this is Solved, you mark it as such. By going to the Thread Tools --> Mark Thread Solved --> Perform Action.

:)

zenwest
11-01-2005, 03:59 PM
You can also create a lisp file with a command defined as a function called from the keyboard after the lisp file is opened- you can then run a command string from lisp, to send autocad commands in batches, -vbarun could be the command. To make sure no dialog impede the process, set you filedia sysvar to 0, and experiment with it.