SendCommand working differently in VBA and DLL?
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
SendCommand working differently in VBA and DLL?

 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
mgrigoriev
Guest





Posted: Sat Mar 26, 2005 2:43 am    Post subject: SendCommand working differently in VBA and DLL? Reply with quote

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

Back to top
juno
Guest





Posted: Sat Mar 26, 2005 2:54 am    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

why are you using SendCommand. Try using copy
Back to top
Jeff Mishler
Guest





Posted: Sat Mar 26, 2005 3:00 am    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

......or the Offset method.....

--
Jeff
check out www.cadvault.com
"juno" <nospam@address.withheld> wrote in message
news:19639049.1111787687019.JavaMail.jive@jiveforum1.autodesk.com...
> why are you using SendCommand. Try using copy

Back to top
mgrigoriev
Guest





Posted: Sat Mar 26, 2005 3:19 am    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

I noticed that SendCommand is being held somewhere, because if you stop the routine right after the last send command line, it will be sent to AutoCAD, and the offseted object is drawn.
Back to top
Mike Tuersley
Guest





Posted: Sat Mar 26, 2005 10:02 am    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

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...
Back to top
Tony Tanzillo
Guest





Posted: Sat Mar 26, 2005 9:06 pm    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

"Mike Tuersley" <mtuersley_NOT_@rand.com> wrote

Quote:
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. That's not
necessarily true.

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.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
Back to top
Mike Tuersley
Guest





Posted: Sun Mar 27, 2005 9:52 am    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

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...
Back to top
Dave
Guest





Posted: Tue Mar 29, 2005 4:54 am    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

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
"Mike Tuersley" <mtuersley_NOT_@rand.com> wrote in message
news:maun2r1bb1i0$.n8c7cnp6mrc2.dlg@40tude.net...
Quote:
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...
Back to top
mgrigoriev
Guest





Posted: Wed Mar 30, 2005 12:13 am    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

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.
Back to top
Dave
Guest





Posted: Wed Mar 30, 2005 2:44 am    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

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
"mgrigoriev" <nospam@address.withheld> wrote in message
news:6919057.1112123654081.JavaMail.jive@jiveforum1.autodesk.com...
Quote:
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.
Back to top
Tony Tanzillo
Guest





Posted: Wed Mar 30, 2005 3:47 am    Post subject: Re: SendCommand working differently in VBA and DLL? Reply with quote

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.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com

"mgrigoriev" <nospam@address.withheld> wrote in message
news:6919057.1112123654081.JavaMail.jive@jiveforum1.autodesk.com...
Quote:
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.
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB