SendCommand working differently in VBA and DLL?

Discussion in 'AutoCAD' started by mgrigoriev, Mar 25, 2005.

  1. mgrigoriev

    mgrigoriev Guest

    Hi,

    I am posting a sample code that works differently in VBA and from a DLL. The code is supposed to offset 2 entities 10'. VBA does it without a error, DLL errors on GetEntity when picking the second object. The problem, I figured, is in ThisDrawing.SendCommand, which is not being sent to AutoCAD until the program is finished running. Why is that happening and what can be done about it?

    Thanks,
    Mike

    Sub Test(Application As Object)
    Set ThisDrawing = Application.ActiveDocument
    Set objUtil = ThisDrawing.Utility
    OffsetDistance = 10
    Dim returnObj As AcadObject

    For i = 0 To 1
    objUtil.GetEntity returnObj, basePnt, "Select an object"
    returnPnt = ThisDrawing.Utility.GetPoint(, "Specify direction: ")

    ThisDrawing.SendCommand "_offset "
    ThisDrawing.SendCommand OffsetDistance & " "
    ThisDrawing.SendCommand SendEntity(returnObj) & " "
    ThisDrawing.SendCommand returnPnt(0) & "," & returnPnt(1) & "," & returnPnt(2) & " " & " "
    Next i
    End Sub
     
    mgrigoriev, Mar 25, 2005
    #1
  2. No, there is no difference between the two other than the wait time. Both
    basically perform a "sendkeys" operation to AutoCAD's command processor at
    which point your "program" loses any contact with it - as far as visual
    basic is concerned, it has completed its task. Since vba is hosted by
    AutoCAD, the wait time is less than with a dll.

    What's scary is you wrote a dll for this. SendCommand <> programming! There
    are very, very few times you will ever need to use it if you want to write
    a program. For something as simple as this, stick to lisp or diesel.

    -- Mike
    ___________________________
    Mike Tuersley
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Mar 26, 2005
    #2
  3. Um, not exactly.

    DLL code can run in either the application or document
    context (depending on how its called), while VBA code
    generally runs in the application context if the code's
    exeuction was initiated by using VBARUN or vl-vbarun.

    On the other hand, if the thread of execution originates from
    Visual LISP code making a call to VLA-RUNMACRO, then the
    VBA code is running in the document context.

    A DLL whose ActiveX methods are invoked from Visual
    LISP, runs in the document context.

    SendCommand behaves differently depending on which
    execution context it runs in. To have the same behavior
    as VBA, the DLL code that calls SendCommand must be
    called from VBA, not LISP.
     
    Tony Tanzillo, Mar 26, 2005
    #3
  4. Thanks Tony, you are right. Since I never mix my environments, I never
    thought of it down to that level of detail.

    -- Mike
    ___________________________
    Mike Tuersley
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Mar 27, 2005
    #4
  5. mgrigoriev

    Dave Guest

    This is funny, as I use the sendcommand about 200 times in my code. It is
    actually what got me started in programming. I may a few things that could
    be updated, now that I know a bit better, but most of the stufff was not
    available, like aligining a 3D solid. etc., but I have to say, I have never
    had a timing issue yet and it runs pretty damn hard.

    Perhaps it is becasue I am calling the VB dll from vbarun (dvb file calling
    the module of the dll) as Tony said and he is calling it from lisp. I do not
    know and I do not understand it. That is what you get when you ar ein
    diapers. :) I have gotten quite a bit done in the last few months though.
    Everything works, so now is a good time to give the source to real coder and
    have run even better.


    --
    David Wishengrad
    President & CTO
    MillLister, Inc.
    Software for BOM, measuring, stretching, feature recognition, and
    controlling visibility of
    multiple 3D solids.
    Http://Construction3D.com
     
    Dave, Mar 29, 2005
    #5
  6. mgrigoriev

    mgrigoriev Guest

    What can be done to make SendCommand work when caling a DLL from LISP? Right now the SendCommand is not being sent to AutoCAD until the DLL code is finished running.
     
    mgrigoriev, Mar 29, 2005
    #6
  7. mgrigoriev

    Dave Guest

    I believe if you have your lisp call a dvb file that has class modules that
    call the vb dll it will be fine.

    I am not having to wait and run some more lisp at this point, so I could be
    wrong.

    --
    David Wishengrad
    President & CTO
    MillLister, Inc.
    Software for BOM, measuring, stretching, feature recognition, and
    controlling visibility of
    multiple 3D solids.
    Http://Construction3D.com
    Right now the SendCommand is not being sent to AutoCAD until the DLL code is
    finished running.
     
    Dave, Mar 29, 2005
    #7
  8. Nothing. Any code initiated by a call to an ActiveX method
    from LISP, will always run in the document context.

    The only option, would be to use vl-vbarun to call a VBA
    macro, that in-turn, calls SendCommand or an ActiveX
    method in a DLL that calls it, and I'm not entirely sure
    that this will work either.
     
    Tony Tanzillo, Mar 29, 2005
    #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.