Consulting

Results 1 to 6 of 6

Thread: Create ACAD command to run VBA routine

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Posts
    11
    Location

    Create ACAD command to run VBA routine

    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.

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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

  3. #3
    VBAX Regular
    Joined
    Mar 2005
    Posts
    11
    Location
    Yeah. I'd like to be able to just type a command or shortcut at the AutoCAD command line to run a VBA routine.

  4. #4
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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".

    [VBA]

    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


    [/VBA]

    Happy Coding

  5. #5
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    MikeS, if this is Solved, you mark it as such. By going to the Thread Tools --> Mark Thread Solved --> Perform Action.


  6. #6
    VBAX Regular
    Joined
    Nov 2005
    Posts
    10
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •