LISP/VBA communication

Discussion in 'AutoCAD' started by Gordon Price, Aug 25, 2004.

  1. Gordon Price

    Gordon Price Guest

    Back in the day (R2002) I was working on a tool that would allow some LISP
    in a menu macro to pass some data to a VBA app. Specifically, I was going to
    have the LISP dump a value to the BlackBoard, then call the VBA routine. The
    VBA would then look in the BlackBoard for the passed data.
    So, with R2005 now out, I am looking to get back to that project, and I am
    wondering if the BlackBoard is still the way to go, or is there now a better
    way to pass a value from LISP to VBA?
    What I DON'T want to do is the kludge I had before, of a bunch of different
    VBA stubs for each possible 'passed' value, and menu macros that just
    launched the VBA stubs. Seems rather inelegant, as well as a pain to
    maintain and expand on.

    Best,
    Gordon
     
    Gordon Price, Aug 25, 2004
    #1
  2. Gordon Price

    Gordon Price Guest

    I tend to try to avoid an approach where some other customization can break
    mine. With the blackboard I can name the 'variable' and not have to worry.
    The other approach might be to use Xdata on layer 0 for the same reason. It
    REALLY is a bummer that you can't call a VBA routine and pass an argument
    from Lisp. Major wishlist item for me.

    Best,
    Gordon
     
    Gordon Price, Aug 27, 2004
    #2
  3. Gordon Price

    Gordon Price Guest

    Ed, thanks for the class module. I will definitely take a look. From the
    grammer in your e:mail, it sounds like the module allows VBA to talk to
    Lisp, rather than the other way around. Does it work both ways? The goal
    here is to get the effect of calling a VBA routine from a manu macro with an
    argument being passed to the VBA.

    Best,
    Gordon
     
    Gordon Price, Aug 27, 2004
    #3
  4. Gordon Price

    Ed Jobe Guest

    No, vba has to be the controller. But you could set a var in lisp, call the
    macro and have it check the var. Another method I use, is to create a
    function that accepts an arg and create multiple wrappers for it. For
    example, I have a macro that creates new dwgs from a template with the
    template as an arg. Like: NewDwg(template As String). To create multiple
    types of dwgs, I have a wrapper command for each type of template, i.e.
    Sub CivilDwg ()
    NewDwg "civil.dwt"
    End Sub
     
    Ed Jobe, Aug 27, 2004
    #4
  5. Gordon Price

    Gordon Price Guest


    That is the stub approach I have been using, but I am setting 'annotation
    scale' so I have a bunch of stubs. Adding both a new stub and a new menu
    line is a pain. If I could pass an argument to VBA, I just add the item to
    the menu and I am done. As for the var you mention, I assume you mean USER1
    or the like? I tend to avoid them as anyone can use them, and thus apps
    break. If I could name an actual variable and set it in Lisp, then access
    that in VBA I would love it, but my understanding is that Lisp variables and
    VBA variables are seperate beasts, no way to go back and forth. I REALLY
    wish you could pass an argument between the two. Gotta bug those wishlist
    people about it ;)

    Best,
    Gordon
     
    Gordon Price, Aug 27, 2004
    #5
  6. Gordon Price

    Ed Jobe Guest

    No, I meant a global lisp var, i.e. (setq vbavar "string to get from vba").
    Then run a public macro that doesn't have args, but it automatically checks
    the lisp namespace for the symbol (vbavar) and acts on it. I havn't tried
    it, but it should work just like having args. Come to think of it, you
    should be able to the same thing all in vba using -VBARUN. Create a Public
    var in your vba project and set it with -VBARUN. Here's what I've tested so
    far.

    With:
    Sub lisptest()
    'retrieve a value from a lisp quoted symbol
    'intended as a workaround for macros with arguments.
    Dim vl As New VLAX
    Dim LispVar As Variant
    LispVar = vl.EvalLispExpression("(setq LispVar LispVar)")
    MsgBox LispVar
    Set vl = Nothing
    End Sub

    Then:
    (setq LispVar "MyTemplate.dwt")
    (command "-vbarun" "lisptest")
     
    Ed Jobe, Aug 27, 2004
    #6
  7. Gordon Price

    Ed Jobe Guest

    I meant vbastmt not vbarun. I'm not sure exactly how you would do it at the
    moment, since vbastmt runs in the context of ThisDrawing.
     
    Ed Jobe, Aug 27, 2004
    #7
  8. Gordon Price

    Ed Jobe Guest

    Just thought of one downside to running a macro with "arguments", you won't
    be able to repeat it with ENTER. But if you write wrappers like I mentioned
    before, you can.
     
    Ed Jobe, Aug 27, 2004
    #8
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.