how to call acad from std. exe?

Discussion in 'AutoCAD' started by Mark Propst, Jul 14, 2003.

  1. Mark Propst

    Mark Propst Guest

    Hi all,
    I have a vba dvb I've been calling from acad with a lisp routine via
    vla-runmacro or vl-vbarun
    I want to change it to a stand alone .exe

    in addition to changing all ThisDrawing references I need to somehow connect
    to acad.
    but since I'll be calling the exe from within acad (I presume by using
    (Startapp) ???) I'm confused about how to connect to acad. I obviously
    don't need the usual "on error resume next getobject if err then create
    object" that I would use if I was starting the exe from outside of acad. so
    what's the proper way to refer to the instance of acad that is calling the
    app?
    I know this is a stupid question but hey, that's my specialty!
    :)
    Mark
     
    Mark Propst, Jul 14, 2003
    #1
  2. You'll need to create an ActiveX executable with one publicly creatable
    class. That class should have a property that will accept a reference to
    an AcadApplication object.

    Using VisualLISP, create an instance of the class and set its
    application property passing the return value of (vlax-get-acad-object).

    I know that sounds like a lot of effort but it's the only reliable way
    to attach to the proper instance of AutoCAD. VB's GetObject is
    insufficient for scenarios involving multiple running instances of
    AutoCAD.
     
    Frank Oquendo, Jul 14, 2003
    #2
  3. Mark Propst

    Ed Jobe Guest

    Hi Mark,
    Perhaps it would be easier to answer your question if you stated what you
    are trying to accomplish. But on the side, some things you stated are
    inconsistent. You stated you wanted a stand alone program, but then you
    sound as if you still want it to run in the same process as the current
    session of acad. BTW, (startapp) is like using the Shell function, once you
    start the app, acad has no control over it.
     
    Ed Jobe, Jul 14, 2003
    #3
  4. Mark Propst

    Mark Propst Guest

    Thanks Frank,
    I'll try that.
    Mark
     
    Mark Propst, Jul 14, 2003
    #4
  5. Mark Propst

    Ed Jobe Guest

    I just wanted the app to be an .exe so it was compiled so the code wasn't
    You could also compile to dll. The main difference is that the exe will be
    an out-of-process server and the dll will be running in acad's process which
    is usually faster. You could use Frank's approach for both. As for calling
    the dll, the lisp ng has had some discussions recently on how to do this.
     
    Ed Jobe, Jul 14, 2003
    #5
  6. Mark Propst

    Mark Propst Guest

    Hi Ed,

    I need a little clarification

    is that *any* exe? ie both a standard Exe and an Activex exe would be out
    of process?
    that's what I would prefer
    you mean I can create Either and activex.exe or an activex.dll and make the
    classes etc that frank mentioned and it would work the same?
    but the exe would be out of process where the dll would be in process???
    yes, I was playing with that a bit last week with limited success. I'll
    have to try again if I get this conversion working.

    Thanks again for your info.
    Mark
     
    Mark Propst, Jul 14, 2003
    #6
  7. Any executable will be out-of-process. However, you can minimize the
    performance hit by compiling all code that will be interacting with
    AutoCAD into a DLL. Once you've conencted to AutoCAD, you can load the
    DLL into AutoCAD's process space by using GetInterfaceObject. Then
    manipulate the created object from within your executable.
    That's correct.
     
    Frank Oquendo, Jul 14, 2003
    #7
  8. Not at all... A client can be written in any language that supports
    ActiveX, including VisualLISP.

    But if you already know VB and are new to LISP, I'd suggest sticking to
    what you know if you have any sort of deadline on this project.
     
    Frank Oquendo, Jul 15, 2003
    #8
  9. Mark Propst

    Mark Propst Guest

    so in this sentence:
    "... you can't just code a DLL because you'll still need a client
    application to make use of it."
    the word "client" refers to something different than just calling a dll from
    lisp?
    as in this pseudocode idea of how to call a dll from lisp
    (defun InvokeDll(dllName dllMethod / ac res res2)
    (setq ac (vlax-get-acad-object))
    (setq res(vla-GetInterfaceObject ac dllname))
    (setq res2 (vlax-invoke-method res dllMethod))
    (vlax-release-object res)
    (vlax-release-object ac)
    res2
    )
    that function (just pseudocode) probably wouldn't work, it's just my way of
    trying to figure out how to call a dll from lisp pasted together from a few
    recent posts. I haven't tried it yet.
    like I say it's more like pseudocode...i'm not sure what I need to change
    yet to make it work as a callable function.
    but is that what you mean by "client" or is it something different?
     
    Mark Propst, Jul 15, 2003
    #9
  10. Mark Propst

    Mark Propst Guest

    i *do* realize that much, that's what I meant.
    why would it be not desirable?

    but I can't call the vba dvb without using a lisp function to call it,
    that's what I meant in the sentence above.
    is that not correct?
    so ultimately the lisp is the calling client, is it not?
    a lisp client calling a vba client, calling a dll server????
    or just eliminate the middle man and have the lisp call the dll with invoke
    method
    or am i missing something yet again (yeah, I know, I'm missing a whole lot
    of somethings)

    hmm, I don't remember that!

    Thanks again,
    Mark
     
    Mark Propst, Jul 15, 2003
    #10
  11. Mark Propst

    wivory Guest

    Hi Mark,
      
    How did you get on with this? I was away last week and it's taken me until today (Thursday!!) to catch up on all my emails and the discussion group postings and still try and fit some real work in somewhere ;-) so I'm sorry I'm only getting to see your question now.
      
    I can see Ed and Frank have provided you with a lot of info and maybe you've achieved what you were trying to accomplish by now. My interest is due to the fact that we were spurred by the same requirement, ie I wrote a dvb in VBA and then wanted to protect the source code. I dropped the code into a standalone VB exe but the performance was abysmal (as has been alluded) so instead we ported it to an ActiveX DLL. After some experimentation the result was fairly successful. It's initiated from a button in AutoCAD and doesn't require any lisp.
      
    Let me know if you want more details posted.
      
    Regards
      
    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Jul 24, 2003
    #11
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.