Loading VBA from toolbar 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. RDAY

    Anne Brown Guest

    RDAY -

    In addition to any replies you might receive or have already
    received, you may find more information or responses by posting
    future VBA related questions in the following discussion group:

    Web browser: http://discussion.autodesk.com/forum.jspa?forumID=33
    Newsreader:
    news://discussion.autodesk.com/autodesk.autocad.customization.vba
     
    Anne Brown, Jan 20, 2005
    #2
  3. Hi,

    The best way is to remove the Load command from the Toolbar.

    Replace it with something along the lines of:

    (vl-vbarun "Filename.dvb!MacroName);

    If the File is not on your AutoCAD path, then you will need to add the
    directory data to FileName

    the vl-vbarun command loads the file if necessary and simply runs it if
    already loaded.
    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Jan 20, 2005
    #3
  4. RDAY

    RDAY Guest

    Thanks Laurie,

    For some reaseon ACADE doesn't like the "vl" part.

    Now I have this as my button macro :
    C^C^P(command "-vbarun" "PanelGrid.dvb!PanelGrid")
    I disabled my lisp code a this works without giving me the message box when I open new/other drawings, but I get this in the command line:
    Command: C
    Command: -vbarun
    Macro name: PanelGrid.dvb!PanelGrid Regenerating model.
    Command:
    Command: nil

    Is ther a way to turn off the command line echo?
     
    RDAY, Jan 21, 2005
    #4
  5. Hi,

    Are you sure you didn't make a typing error?

    If you care to search through my posts to these NG's you will find much more
    detail on dealing with VBA functions.

    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Jan 21, 2005
    #5
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.