Running VBA code from tool bar button

Discussion in 'AutoCAD' started by RDAY, Jan 20, 2005.

  1. RDAY

    RDAY Guest

    I have a block of an enclosure back panel that I have divided up into a grid. I use the grid for laying out my components. I placed the lines of the grid in their own layer so I can turn them on or off as needed. Now the fun part. I have hashed together some VBA code that will toggle the layer and there by the grid on and off. I have a toolbar button to run this code. This seems to work but each time I open a new drawing I get a message box informing me that the project is already loaded.

    According to the doc in the acad2005.lsp file this should only load at start up. Any ideas?


    Thanks for you help.

    Button code:
    ^C^C-vbarun PanelGrid

    VBA code:
    Sub PanelGrid()

    Dim layerObj As AcadLayer
    Set layer = ThisDrawing.Layers.Add("PANELGRID")

    If layerObj.LayerOn = True Then
    layerObj.LayerOn = False
    Else: layerObj.LayerOn = True
    End If
    ThisDrawing.Regen acActiveViewport
    End Sub


    Lisp I placed in “acad2005.lspâ€:
    (defun S::STARTUP()
    (command "_VBALOAD" "PanelGrid.dvb")
    )
     
    RDAY, Jan 20, 2005
    #1
  2. ACADLSPASDOC System Variable

    Type: Integer
    Saved in: Registry
    Initial value: 0

    Controls whether AutoCAD loads the acad.lsp file into every drawing or just the first drawing opened in an AutoCAD session.

    0 Loads acad.lsp into just the first drawing opened in an AutoCAD session

    1 Loads acad.lsp into every drawing opened
     
    Nathan Taylor, Jan 20, 2005
    #2
  3. RDAY

    Oberer Guest

    you could also add the dvb to your startup suite, or define the command via lisp to check for the load, then run the macro:

    (if it's already loaded, you don't see a thing:) )
    'LayoutLayerStateManager
    (defun c:LM ()
    (vl-vbaload "G:/WARE/vb/Layout Layer Manager.dvb")
    (vl-vbarun "LayoutLayerStateManager")
    )
     
    Oberer, Jan 21, 2005
    #3
  4. RDAY

    Matt W Guest

    And here's my $0.02.

    ^P^C^C_-vbarun BatchPlot.dvb!modMain.Main;

    Loads our batch plotting program, provided it resides in one of the search
    paths.
     
    Matt W, Jan 21, 2005
    #4
  5. RDAY

    RDAY Guest

    I removed the code from the .lsp file and this is what I have now as my button macro.

    C^C^P(command "-vbarun" "PanelGrid.dvb!PanelGrid")

    This works but I get this each time I run it.

    Command: C
    Command: -vbarun
    Macro name: PanelGrid.dvb!PanelGrid Regenerating model.
    Command:
    Command: nil

    Is there any way to turn off the command line echo whenI run this?

    Thanks for all the help.
     
    RDAY, Jan 24, 2005
    #5
  6. Command "CMDECHO" 0 ?
     
    Paul Richardson, Jan 24, 2005
    #6
  7. ^C^C, for two Cancels, instead of C^C
     
    James Belshan, Jan 24, 2005
    #7
  8. RDAY

    RDAY Guest

    James,
    That takes care of everything but the :nil.
    I can live with that.

    Thanks to all who have offered help.
     
    RDAY, Jan 25, 2005
    #8
  9. RDAY

    Juha Guest

    Would a (princ) help the nil?

    ^C^C^P(command "-vbarun" "PanelGrid.dvb!PanelGrid") (princ)
     
    Juha, Jan 27, 2005
    #9
  10. RDAY

    arcticad Guest

    (VL-VBALOAD (findfile (strcat "c:\myprogram\program.dvb")))
    You can use this code to load the program. and it won't give you an error message if you call it twice.
     
    arcticad, Mar 16, 2005
    #10
  11. RDAY

    Tim Arheit Guest

    I just use the following on the tool bar
    ^C^C-vbarun c:/myprogram/myprogram.dvb!mymodule.myfunction

    It will load the program if necessary and call the specified function.
    It won't generate any error if you call it twice. (Note the forward
    slash '/', you have to do it this way to make it work).

    -Tim
     
    Tim Arheit, Mar 17, 2005
    #11
  12. RDAY

    Edward Bagby Guest

    I usually make a command in my startup lisp file and then add the command
    name to the button. this way the user can use the button, the keyboard
    command, and can use [enter] to activate the command multiple times.

    here is an example I have in my lisp file

    ; C:InvRenameDrawing
    ; Rename drawing in database and all records with the drawing name
    (defun c:InvRenameDrawing ()
    (vl-vbaload "//Ssx_server/cadd_std/Macros/FieldApp.dvb")
    (vl-vbarun "InvestigationApp.modMain.ChangeDrawingName")
    (princ)
    )
     
    Edward Bagby, Mar 23, 2005
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.