VLisp->VBA How to pass parameters

Discussion in 'AutoCAD' started by Roel Westhoff [W4], Jan 22, 2005.

  1. Hi all,

    Looked all over the place but did not find solution. Maybe overlooked the obvious

    I want to use procedure/functions created in VBA in a VLISP environment (smoothing out the transition away from VLISP). There is a command -vbarun [macro] but this is not sufficient. I want to use the created procedures/functions in vlisp including the necessary parameters
    example: -vbarun [macro][parameters]

    Is this possible?

    Roel Westhoff
    Netherlands
     
    Roel Westhoff [W4], Jan 22, 2005
    #1
  2. Roel Westhoff [W4]

    Jürg Menzi Guest

    Hi Roel

    You can't call a VBA macro with arguments from LISP.
    You've to build an interface to 'transport' the values from/to...
    - Single values by system vars USERI1-5 USERR1-5, USERS1-5
    - For complex informations use dictionaries

    Cheers
     
    Jürg Menzi, Jan 22, 2005
    #2
  3. Roel Westhoff [W4]

    Jürg Menzi Guest

    Hi Roel

    This sample shows you how to do it with system vars:
    Code:
    ;
    ; == Function MeMsgBox
    ; Displays the VBA MsgBox.
    ; Arguments [Type]:
    ;   Msg = Message [STR]
    ;   Flg = Flag [INT] *)
    ;   Tit = Title [STR]
    ; Return [Type]:
    ;   > Return value [INT] *)
    ; Notes:
    ;   *) Details see VBA help, for LISP use the 'vlax-' prefix.
    ;
    (defun MeMsgBox (Msg Flg Tit)
    (setvar "USERS1" Msg)
    (setvar "USERS2" Tit)
    (setvar "USERI1" Flg)
    (vl-vbarun "YourVba.dvb!MacroFunctions.ShowMsgBox")
    (getvar "USERI1")
    )
    
    ' VBA Macro (in modul 'MacroFunctions')
    '
    Sub ShowMsgBox()
    
    Dim MsgStr As String
    Dim TitStr As String
    Dim MsgFlg As Integer
    
    With ThisDrawing
    MsgStr = .GetVariable("USERS1")
    TitStr = .GetVariable("USERS2")
    MsgFlg = .GetVariable("USERI1")
    .SetVariable "USERI1", MsgBox(MsgStr, MsgFlg, TitStr)
    End with
    
    End Sub
    
    Sample:
    (MeMsgBox "This is a test." (+ vlax-vbOKOnly vlax-vbInformation) "Testtitle")

    Cheers
     
    Jürg Menzi, Jan 22, 2005
    #3
  4. Jurg,

    Thx for the info. It will do the job i want to do but it looks a bit odd to
    work that way.
    I remember another development enviroment way back in time to get things
    going the same way. I'm talking 1980's

    Roel
     
    Roel Westhoff [W4], Jan 22, 2005
    #4
  5. Roel Westhoff [W4]

    Jürg Menzi Guest

    Hi Roel
    Unfortunately yes, LISP and VBA are two worlds...
    Writing to a text file... hehe...¦-)

    Cheers
     
    Jürg Menzi, Jan 22, 2005
    #5
  6. wait a minute!
    why not compile to a dll and call the procedure from the dll?
    I say this because I am in the process of writing dll's for this exact reason.

    I have never created a dll from VBA, just VB, so am not sure if VBA makes dll's.
    Am I dreaming about using VBA or is it possible?

    Not sure why I would use VBA though, VB is better IMHO for in process dll's.

    "Roel Westhoff [W4]" <>
    |>Hi all,
    |>
    |>Looked all over the place but did not find solution. Maybe overlooked the obvious
    |>
    |>I want to use procedure/functions created in VBA in a VLISP environment (smoothing out the transition away from VLISP). There is a command -vbarun [macro] but this is not sufficient. I want to use the created procedures/functions in vlisp including the necessary parameters
    |>example: -vbarun [macro][parameters]
    |>
    |>Is this possible?
    |>
    |>Roel Westhoff
    |>Netherlands

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Jan 24, 2005
    #6
  7. Hi James,

    You're right. You can't make a DLL (or an EXE) with VBA.

    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Jan 24, 2005
    #7
  8. Laurie,
    Could you comment on how convenient it is to use a mix of lisp and dll's?
    I use ObjectDCL but am always watching out for non-3rd party ways of doing things.
    I also want to make dll's for things besides dialogs.
    I am curious if crashes are an issue or if you have to do a ton of error checking so the object created from the dll
    does not accidentally get orphaned and left hanging around.
    Is ARD written in C?


    "Laurie Comerford" <laurie.comerford at I hate Spam.com.au>
    |>Hi James,
    |>
    |>You're right. You can't make a DLL (or an EXE) with VBA.

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Jan 24, 2005
    #8
  9. Hi James,

    When I moved from Lisp to VB/VBA, Lisp did not have any of the Visual Lisp
    functionality. Hence, I have no idea how to use DLLs in lisp.

    I see code here where it is obviously being used. It looks so arcane, that
    I'm really glad I made the change to VBA when I did.

    I really cannot understand anyone attempting to write a large program in
    Lisp. The tools to stay in front of Autodesk simply aren't there - or are
    too complex and hard to debug. All the utitility programs which you might
    write in Lisp have already been written a thousand times and usually can be
    found free on the web.

    VBA is very good at destroying objects once you move away from the
    environment where they were defined and left over memory usage does not
    create a problem in practice, other than for Selection Sets. I resolve that
    by deleting (with "on error resume next") any selection set I wish to use
    and then recreating it.

    I do use lisp to call my VBA functions and have often posted samples from
    CADApps MNL files as to how I do this. Come-on .NET which will remove this
    requirement.

    ARD is essentially written in VBA, with the standard features, speed
    optimisation, security DLLs (we use FlexLM to make it easy for CAD Managers
    to deal with installation and licensing) etc. originally written in VB6, but
    now mostly compiled from C++. I haven't specifically measured, but the
    total size of all the DLL files is about a third that of the DVB file.

    The worst issue with VBA in the vertical products like Land Desktop is that
    they are sensitive to the DLLs and you need to be VERY carefull when
    creating the installations that you have the right files.

    We created a version of ARD to run on AutoCAD and it was a joy as the R2004
    and R2005 versions are identical. Totally mucks up the need for our file
    naming convention. :)

    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Jan 24, 2005
    #9
  10. Hi Laurie,
    Its funny you mention about writing large programs in lisp.
    I am guessing I have the record because I have a road design prog that is like 40,000 lines of code split into 35 files
    or so.
    Its actually very easy to debug.
    You just have to structure things and avoid global variables.
    Also, forget normal dcl, Object DCL is the only way to go.
    Once you have that, you have a ton of power because lisp is superior at getting user info.
    I have several user input routines that VBA cannot do.
    Anyway, the only glitches I run into are the LDT API objects not being released correctly.
    So I wrote my own alignments and profiles and everything except surfaces.
    We are trying to decide if Civil3D is any good for us in the future because Autodesk does not understand that a dynamic
    design requires dynamic annotation. I dont mean stuff that updates, but stuff that moves around. They are not even
    close to dealing with this idea and their model actually works against them right now. I could go on and on.
    They should have asked how engineers think and then made a program, instead they are offering super slick corridor and
    surface utils, with a complicated interface. It will be years before they come up with something simple enough for
    subdivision designers.
    I have my eyes on your prog and get a kick out of seeing many similar things.
    There is a big market for a non Civil3D design prog that is simple to use.
    later

    "Laurie Comerford" <laurie.comerford at I hate Spam.com.au>
    |>Hi James,
    |>
    |>When I moved from Lisp to VB/VBA, Lisp did not have any of the Visual Lisp
    |>functionality. Hence, I have no idea how to use DLLs in lisp.
    |>
    |>I see code here where it is obviously being used. It looks so arcane, that
    |>I'm really glad I made the change to VBA when I did.
    |>
    |>I really cannot understand anyone attempting to write a large program in
    |>Lisp.
    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Jan 25, 2005
    #10
  11. Yes.... One of my applications g-labeling for all the geometry calculations for a Civil/Survey work ... all the code was made with Autolisp/Visual Lisp.

    And another simple application to calculate subdivisions of polylines... even those made with curves segments.

    Many things can be done using Visual Lisp now and before.... very easy...!


    Regards,
    Luis Esquivel
    http://www.draftteam.com
     
    Luis Esquivel, Jan 25, 2005
    #11
  12. the line "I have my eyes on your prog and get a kick out of seeing many similar things." should have been:
    "I have my eyes on your prog and get a kick out of seeing many similar things between your and my programs."

    I didnt mean to imply that Civil3D and ARD were both difficult to use tools, only the Civil3D (so far...).

    Adesk knows this though, I just wish their marketing was different. Its like they are trying to convince themselves
    that they are further along than they are. Hopefully they will catch up to their marketing soon.

    James Maeding <jmaeding at hunsaker dot com>
    |>Hi Laurie,
    |>Its funny you mention about writing large programs in lisp.
    |>I am guessing I have the record because I have a road design prog that is like 40,000 lines of code split into 35 files
    |>or so.
    |>Its actually very easy to debug.
    |>You just have to structure things and avoid global variables.
    |>Also, forget normal dcl, Object DCL is the only way to go.
    |>Once you have that, you have a ton of power because lisp is superior at getting user info.
    |>I have several user input routines that VBA cannot do.
    |>Anyway, the only glitches I run into are the LDT API objects not being released correctly.
    |>So I wrote my own alignments and profiles and everything except surfaces.
    |>We are trying to decide if Civil3D is any good for us in the future because Autodesk does not understand that a dynamic
    |>design requires dynamic annotation. I dont mean stuff that updates, but stuff that moves around. They are not even
    |>close to dealing with this idea and their model actually works against them right now. I could go on and on.
    |>They should have asked how engineers think and then made a program, instead they are offering super slick corridor and
    |>surface utils, with a complicated interface. It will be years before they come up with something simple enough for
    |>subdivision designers.
    |>I have my eyes on your prog and get a kick out of seeing many similar things.
    |>There is a big market for a non Civil3D design prog that is simple to use.
    |>later
    |>
    |>"Laurie Comerford" <laurie.comerford at I hate Spam.com.au>
    |>|>Hi James,
    |>|>
    |>|>When I moved from Lisp to VB/VBA, Lisp did not have any of the Visual Lisp
    |>|>functionality. Hence, I have no idea how to use DLLs in lisp.
    |>|>
    |>|>I see code here where it is obviously being used. It looks so arcane, that
    |>|>I'm really glad I made the change to VBA when I did.
    |>|>
    |>|>I really cannot understand anyone attempting to write a large program in
    |>|>Lisp.
    |>James Maeding
    |>jmaeding at hunsaker dot com
    |>Civil Engineer/Programmer

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Jan 27, 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.