| Author |
Message |
Tim Skene
Guest
|
Posted:
Thu Jan 06, 2005 5:08 am Post subject:
While loop takes CPU resources |
|
|
I'm running another application from lisp and need to wait for it to create
a registry value, then do something according to the value.
Reading the value in a WHILE loop takes much CPU resources (99% in
task manager) and if you switch to another app and back to ACAD the screen
seems to freeze and things really slow down.
To see what I mean, run this loop on the command line and try switching to
another app and back.
(while (null test) (command))
Is there any way to loop without taking so much resources? I could pause
with a dialog or alert button to click, but that adds an unnecessary
and awkward looking step.
Thanks.
Tim Skene
|
|
| Back to top |
|
 |
Tony Tanzillo
Guest
|
Posted:
Thu Jan 06, 2005 10:07 am Post subject:
Re: While loop takes CPU resources |
|
|
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote
| Quote: | To see what I mean, run this loop on the command line and try switching to
another app and back.
(while (null test) (command))
Is there any way to loop without taking so much resources?
|
Try:
(while <condition>
(command "._DELAY" 1000) ; change millisecs to suit
)
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com |
|
| Back to top |
|
 |
Tim Skene
Guest
|
Posted:
Thu Jan 06, 2005 10:33 am Post subject:
Re: While loop takes CPU resources |
|
|
| Quote: | Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
|
Makes no difference. Whether I put a long, short or no delay in the loop, it
seems to be the overhead of the while loop that causes the problem.
--
Tim Skene
|
|
| Back to top |
|
 |
Alaspher
Guest
|
Posted:
Thu Jan 06, 2005 5:25 pm Post subject:
Re: While loop takes CPU resources |
|
|
may be anything like:
| Code: | (vlax-invoke-method
(vlax-get-or-create-object "wscript.shell")
"run"
(strcat "youapplication.exe\ " "externalfile.ext")
1
:vlax-true
) |
AutoCAD will wait while "youapplication" is active.
best regards! |
|
| Back to top |
|
 |
Tony Tanzillo
Guest
|
Posted:
Thu Jan 06, 2005 6:20 pm Post subject:
Re: While loop takes CPU resources |
|
|
The point to the delay is to avoid doing what you're
doing in the while loop as frequently as its happening.
If you initiate an external process synchronously (e.g.,
where your LISP code did not continue until after the
external process is finished), AutoCAD would not
respond until your LISP code has resumed and does
something that causes AutoCAD to begin polling for
input, anyways.
So, the problem is not that AutoCAD becomes
bogged down while waiting for the external process,
the problem is that your are running the extarnal
process asynchronuosly (e.g., where your LISP code
does not wait for it to complete), to begin with.
I think you'll find that even if you run the external
process synchronously (e.g., your LISP code would
not continue until the external process completes,
which can be done using a DOSLIB function, I think),
you will still see this happen if the external process
takes any significant time to complete.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in message news:41dccd67_3@newsprd01...
| Quote: | Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay in the loop, it
seems to be the overhead of the while loop that causes the problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Eric Schneider
Guest
|
Posted:
Thu Jan 06, 2005 10:03 pm Post subject:
Re: While loop takes CPU resources |
|
|
Nice functions Tony. Is there a way to keep ACAD from grabbing focus every
second or so? It even grabs focus when (vla-put-windowstate
(vlax-get-acad-object) 2).
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd5abe_1@newsprd01...
| Quote: | Attached to this is a small ObjectARX library called
DoEvents.ARX.
Load it using (arxload "DoEvents.arx"). It will
define a LISP function called (DoEvents), which
is functionally equivalent to VBA's DoEvents() function.
Call the DoEvents function from the body of your
(while) loop and it should sove your problem.
There's a few caveats to this, mainly that it will
allow the user to switch documents, which is a no-no
when it comes to LISP, because that will suspend your
application until the document it runs in is made
active again. To address this, there are two other
functions to enable/disable document activation:
(EnableDocumentActivation)
(DisableDocumentActivation)
I suggest you call the latter before you start the
(while) loop in which you call DoEvents, and make
sure you call the former before your LISP calls any
API that polls for input.
So, you would basically have something like this:
(arxload "DoEvents.arx")
(defun C:TEST ()
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while <condition
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
PS: This is for AutoCAD 2004/2005 only
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in message
news:41dccd67_3@newsprd01...
Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay in the
loop, it
seems to be the overhead of the while loop that causes the problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Tony Tanzillo
Guest
|
Posted:
Thu Jan 06, 2005 10:37 pm Post subject:
Re: While loop takes CPU resources |
|
|
Eric - Not sure what you mean by 'grabbing focus'.
Is AutoCAD in the foreground, or is it bringing itself
into the foreground and taking focus from another app?
If so, what app?
Doesn't happen here using the sample test function I
posted (which does nothing in the (while) loop).
Perhaps there's something in your loop that's
doing it?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message news:41dd6f56$1_1@newsprd01...
| Quote: | Nice functions Tony. Is there a way to keep ACAD from grabbing focus every
second or so? It even grabs focus when (vla-put-windowstate
(vlax-get-acad-object) 2).
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd5abe_1@newsprd01...
Attached to this is a small ObjectARX library called
DoEvents.ARX.
Load it using (arxload "DoEvents.arx"). It will
define a LISP function called (DoEvents), which
is functionally equivalent to VBA's DoEvents() function.
Call the DoEvents function from the body of your
(while) loop and it should sove your problem.
There's a few caveats to this, mainly that it will
allow the user to switch documents, which is a no-no
when it comes to LISP, because that will suspend your
application until the document it runs in is made
active again. To address this, there are two other
functions to enable/disable document activation:
(EnableDocumentActivation)
(DisableDocumentActivation)
I suggest you call the latter before you start the
(while) loop in which you call DoEvents, and make
sure you call the former before your LISP calls any
API that polls for input.
So, you would basically have something like this:
(arxload "DoEvents.arx")
(defun C:TEST ()
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while <condition
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
PS: This is for AutoCAD 2004/2005 only
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in message
news:41dccd67_3@newsprd01...
Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay in the
loop, it
seems to be the overhead of the while loop that causes the problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Eric Schneider
Guest
|
Posted:
Thu Jan 06, 2005 10:54 pm Post subject:
Re: While loop takes CPU resources |
|
|
I'm not doing anything within the (slightly modified, see below) C:TEST
function either, just trying it out before I implement it. While in the
while loop (while the while, heh heh), if I switch focus to any other app,
like notepad, Outlook or Explorer, I don't have enough time to do anything
before it looses focus to ACAD.
Create a file named C:\b.txt, start the C:TEST function and try to rename it
to C:\a.txt.
(defun C:TEST (/ acad ws)
(setq acad (vlax-get-acad-object))
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
(setq ws (vla-get-windowstate acad))
(vla-put-windowstate acad 2)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while (not (findfile "C:/a.txt"));give it something to test
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(vla-put-windowstate acad ws)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7772_1@newsprd01...
| Quote: | Eric - Not sure what you mean by 'grabbing focus'.
Is AutoCAD in the foreground, or is it bringing itself
into the foreground and taking focus from another app?
If so, what app?
Doesn't happen here using the sample test function I
posted (which does nothing in the (while) loop).
Perhaps there's something in your loop that's
doing it?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message
news:41dd6f56$1_1@newsprd01...
Nice functions Tony. Is there a way to keep ACAD from grabbing focus
every
second or so? It even grabs focus when (vla-put-windowstate
(vlax-get-acad-object) 2).
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd5abe_1@newsprd01...
Attached to this is a small ObjectARX library called
DoEvents.ARX.
Load it using (arxload "DoEvents.arx"). It will
define a LISP function called (DoEvents), which
is functionally equivalent to VBA's DoEvents() function.
Call the DoEvents function from the body of your
(while) loop and it should sove your problem.
There's a few caveats to this, mainly that it will
allow the user to switch documents, which is a no-no
when it comes to LISP, because that will suspend your
application until the document it runs in is made
active again. To address this, there are two other
functions to enable/disable document activation:
(EnableDocumentActivation)
(DisableDocumentActivation)
I suggest you call the latter before you start the
(while) loop in which you call DoEvents, and make
sure you call the former before your LISP calls any
API that polls for input.
So, you would basically have something like this:
(arxload "DoEvents.arx")
(defun C:TEST ()
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while <condition
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
PS: This is for AutoCAD 2004/2005 only
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in message
news:41dccd67_3@newsprd01...
Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay in the
loop, it
seems to be the overhead of the while loop that causes the problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Tony Tanzillo
Guest
|
Posted:
Thu Jan 06, 2005 11:04 pm Post subject:
Re: While loop takes CPU resources |
|
|
Eric - Doesn't happen here (WinXP SP2).
Per chance, are you using some bozo (e.g. Win9x)
operating system?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message news:41dd7b56$1_1@newsprd01...
| Quote: | I'm not doing anything within the (slightly modified, see below) C:TEST
function either, just trying it out before I implement it. While in the
while loop (while the while, heh heh), if I switch focus to any other app,
like notepad, Outlook or Explorer, I don't have enough time to do anything
before it looses focus to ACAD.
Create a file named C:\b.txt, start the C:TEST function and try to rename it
to C:\a.txt.
(defun C:TEST (/ acad ws)
(setq acad (vlax-get-acad-object))
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
(setq ws (vla-get-windowstate acad))
(vla-put-windowstate acad 2)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while (not (findfile "C:/a.txt"));give it something to test
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(vla-put-windowstate acad ws)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7772_1@newsprd01...
Eric - Not sure what you mean by 'grabbing focus'.
Is AutoCAD in the foreground, or is it bringing itself
into the foreground and taking focus from another app?
If so, what app?
Doesn't happen here using the sample test function I
posted (which does nothing in the (while) loop).
Perhaps there's something in your loop that's
doing it?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message
news:41dd6f56$1_1@newsprd01...
Nice functions Tony. Is there a way to keep ACAD from grabbing focus
every
second or so? It even grabs focus when (vla-put-windowstate
(vlax-get-acad-object) 2).
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd5abe_1@newsprd01...
Attached to this is a small ObjectARX library called
DoEvents.ARX.
Load it using (arxload "DoEvents.arx"). It will
define a LISP function called (DoEvents), which
is functionally equivalent to VBA's DoEvents() function.
Call the DoEvents function from the body of your
(while) loop and it should sove your problem.
There's a few caveats to this, mainly that it will
allow the user to switch documents, which is a no-no
when it comes to LISP, because that will suspend your
application until the document it runs in is made
active again. To address this, there are two other
functions to enable/disable document activation:
(EnableDocumentActivation)
(DisableDocumentActivation)
I suggest you call the latter before you start the
(while) loop in which you call DoEvents, and make
sure you call the former before your LISP calls any
API that polls for input.
So, you would basically have something like this:
(arxload "DoEvents.arx")
(defun C:TEST ()
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while <condition
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
PS: This is for AutoCAD 2004/2005 only
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in message
news:41dccd67_3@newsprd01...
Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay in the
loop, it
seems to be the overhead of the while loop that causes the problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Eric Schneider
Guest
|
Posted:
Thu Jan 06, 2005 11:18 pm Post subject:
Re: While loop takes CPU resources |
|
|
W2kpro with all the latest, ACAD2005 with all the latest.
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7db8$1_2@newsprd01...
| Quote: | Eric - Doesn't happen here (WinXP SP2).
Per chance, are you using some bozo (e.g. Win9x)
operating system?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message
news:41dd7b56$1_1@newsprd01...
I'm not doing anything within the (slightly modified, see below) C:TEST
function either, just trying it out before I implement it. While in the
while loop (while the while, heh heh), if I switch focus to any other
app,
like notepad, Outlook or Explorer, I don't have enough time to do
anything
before it looses focus to ACAD.
Create a file named C:\b.txt, start the C:TEST function and try to
rename it
to C:\a.txt.
(defun C:TEST (/ acad ws)
(setq acad (vlax-get-acad-object))
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
(setq ws (vla-get-windowstate acad))
(vla-put-windowstate acad 2)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while (not (findfile "C:/a.txt"));give it something to test
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(vla-put-windowstate acad ws)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7772_1@newsprd01...
Eric - Not sure what you mean by 'grabbing focus'.
Is AutoCAD in the foreground, or is it bringing itself
into the foreground and taking focus from another app?
If so, what app?
Doesn't happen here using the sample test function I
posted (which does nothing in the (while) loop).
Perhaps there's something in your loop that's
doing it?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in
message
news:41dd6f56$1_1@newsprd01...
Nice functions Tony. Is there a way to keep ACAD from grabbing focus
every
second or so? It even grabs focus when (vla-put-windowstate
(vlax-get-acad-object) 2).
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd5abe_1@newsprd01...
Attached to this is a small ObjectARX library called
DoEvents.ARX.
Load it using (arxload "DoEvents.arx"). It will
define a LISP function called (DoEvents), which
is functionally equivalent to VBA's DoEvents() function.
Call the DoEvents function from the body of your
(while) loop and it should sove your problem.
There's a few caveats to this, mainly that it will
allow the user to switch documents, which is a no-no
when it comes to LISP, because that will suspend your
application until the document it runs in is made
active again. To address this, there are two other
functions to enable/disable document activation:
(EnableDocumentActivation)
(DisableDocumentActivation)
I suggest you call the latter before you start the
(while) loop in which you call DoEvents, and make
sure you call the former before your LISP calls any
API that polls for input.
So, you would basically have something like this:
(arxload "DoEvents.arx")
(defun C:TEST ()
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while <condition
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
PS: This is for AutoCAD 2004/2005 only
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in message
news:41dccd67_3@newsprd01...
Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay in
the
loop, it
seems to be the overhead of the while loop that causes the
problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Tony Tanzillo
Guest
|
Posted:
Thu Jan 06, 2005 11:33 pm Post subject:
Re: While loop takes CPU resources |
|
|
Is there any other applications open? If so what are they?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message news:41dd80f2$1_3@newsprd01...
| Quote: | W2kpro with all the latest, ACAD2005 with all the latest.
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7db8$1_2@newsprd01...
Eric - Doesn't happen here (WinXP SP2).
Per chance, are you using some bozo (e.g. Win9x)
operating system?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message
news:41dd7b56$1_1@newsprd01...
I'm not doing anything within the (slightly modified, see below) C:TEST
function either, just trying it out before I implement it. While in the
while loop (while the while, heh heh), if I switch focus to any other
app,
like notepad, Outlook or Explorer, I don't have enough time to do
anything
before it looses focus to ACAD.
Create a file named C:\b.txt, start the C:TEST function and try to
rename it
to C:\a.txt.
(defun C:TEST (/ acad ws)
(setq acad (vlax-get-acad-object))
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
(setq ws (vla-get-windowstate acad))
(vla-put-windowstate acad 2)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while (not (findfile "C:/a.txt"));give it something to test
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(vla-put-windowstate acad ws)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7772_1@newsprd01...
Eric - Not sure what you mean by 'grabbing focus'.
Is AutoCAD in the foreground, or is it bringing itself
into the foreground and taking focus from another app?
If so, what app?
Doesn't happen here using the sample test function I
posted (which does nothing in the (while) loop).
Perhaps there's something in your loop that's
doing it?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in
message
news:41dd6f56$1_1@newsprd01...
Nice functions Tony. Is there a way to keep ACAD from grabbing focus
every
second or so? It even grabs focus when (vla-put-windowstate
(vlax-get-acad-object) 2).
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd5abe_1@newsprd01...
Attached to this is a small ObjectARX library called
DoEvents.ARX.
Load it using (arxload "DoEvents.arx"). It will
define a LISP function called (DoEvents), which
is functionally equivalent to VBA's DoEvents() function.
Call the DoEvents function from the body of your
(while) loop and it should sove your problem.
There's a few caveats to this, mainly that it will
allow the user to switch documents, which is a no-no
when it comes to LISP, because that will suspend your
application until the document it runs in is made
active again. To address this, there are two other
functions to enable/disable document activation:
(EnableDocumentActivation)
(DisableDocumentActivation)
I suggest you call the latter before you start the
(while) loop in which you call DoEvents, and make
sure you call the former before your LISP calls any
API that polls for input.
So, you would basically have something like this:
(arxload "DoEvents.arx")
(defun C:TEST ()
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while <condition
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
PS: This is for AutoCAD 2004/2005 only
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in message
news:41dccd67_3@newsprd01...
Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay in
the
loop, it
seems to be the overhead of the while loop that causes the
problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Eric Schneider
Guest
|
Posted:
Fri Jan 07, 2005 12:02 am Post subject:
Re: While loop takes CPU resources |
|
|
Command: (dos_processes)
("smss.exe" "winlogon.exe" "services.exe" "lsass.exe" "svchost.exe"
"spoolsv.exe" "msdtc.exe" "ActionAgent.exe" "DellDmi.exe" "EventAgt.exe"
"DLT.exe" "svchost.exe" "Iap.exe" "mdm.exe" "nvsvc32.exe" "regsvc.exe"
"MSTask.exe" "Win32sl.exe" "WinMgmt.exe" "svchost.exe" "inetinfo.exe"
"svchost.exe" "Explorer.EXE" "jusched.exe" "PwsTray.exe" "TeaTimer.exe"
"ctfmon.exe" "Printkey2000.exe" "OUTLOOK.EXE" "msimn.exe" "POINT32.EXE"
"acad.exe" "AdskCleanup.0001" "AdskScSrv.exe" "WSCommCntr1.exe"
"wisptis.exe"
"pageant.exe" "putty.exe" "putty.exe" "winscp368.exe" "AcroTray.exe"
"putty.exe" "IEXPLORE.EXE" "IEXPLORE.EXE" "notepad.exe" "IEXPLORE.EXE")
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd8467$1_2@newsprd01...
| Quote: | Is there any other applications open? If so what are they?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message
news:41dd80f2$1_3@newsprd01...
W2kpro with all the latest, ACAD2005 with all the latest.
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7db8$1_2@newsprd01...
Eric - Doesn't happen here (WinXP SP2).
Per chance, are you using some bozo (e.g. Win9x)
operating system?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in
message
news:41dd7b56$1_1@newsprd01...
I'm not doing anything within the (slightly modified, see below)
C:TEST
function either, just trying it out before I implement it. While in
the
while loop (while the while, heh heh), if I switch focus to any other
app,
like notepad, Outlook or Explorer, I don't have enough time to do
anything
before it looses focus to ACAD.
Create a file named C:\b.txt, start the C:TEST function and try to
rename it
to C:\a.txt.
(defun C:TEST (/ acad ws)
(setq acad (vlax-get-acad-object))
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
(setq ws (vla-get-windowstate acad))
(vla-put-windowstate acad 2)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while (not (findfile "C:/a.txt"));give it something to test
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(vla-put-windowstate acad ws)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7772_1@newsprd01...
Eric - Not sure what you mean by 'grabbing focus'.
Is AutoCAD in the foreground, or is it bringing itself
into the foreground and taking focus from another app?
If so, what app?
Doesn't happen here using the sample test function I
posted (which does nothing in the (while) loop).
Perhaps there's something in your loop that's
doing it?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in
message
news:41dd6f56$1_1@newsprd01...
Nice functions Tony. Is there a way to keep ACAD from grabbing
focus
every
second or so? It even grabs focus when (vla-put-windowstate
(vlax-get-acad-object) 2).
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd5abe_1@newsprd01...
Attached to this is a small ObjectARX library called
DoEvents.ARX.
Load it using (arxload "DoEvents.arx"). It will
define a LISP function called (DoEvents), which
is functionally equivalent to VBA's DoEvents() function.
Call the DoEvents function from the body of your
(while) loop and it should sove your problem.
There's a few caveats to this, mainly that it will
allow the user to switch documents, which is a no-no
when it comes to LISP, because that will suspend your
application until the document it runs in is made
active again. To address this, there are two other
functions to enable/disable document activation:
(EnableDocumentActivation)
(DisableDocumentActivation)
I suggest you call the latter before you start the
(while) loop in which you call DoEvents, and make
sure you call the former before your LISP calls any
API that polls for input.
So, you would basically have something like this:
(arxload "DoEvents.arx")
(defun C:TEST ()
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while <condition
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
PS: This is for AutoCAD 2004/2005 only
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in message
news:41dccd67_3@newsprd01...
Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay in
the
loop, it
seems to be the overhead of the while loop that causes the
problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Tony Tanzillo
Guest
|
Posted:
Fri Jan 07, 2005 12:12 am Post subject:
Re: While loop takes CPU resources |
|
|
Sorry, no clue about why that's happening.
Perhaps someone else can try it, and see if
they get the same thing. I can't reproduce
it on WinXP with A2K5.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message news:41dd8b31$1_3@newsprd01...
| Quote: | Command: (dos_processes)
("smss.exe" "winlogon.exe" "services.exe" "lsass.exe" "svchost.exe"
"spoolsv.exe" "msdtc.exe" "ActionAgent.exe" "DellDmi.exe" "EventAgt.exe"
"DLT.exe" "svchost.exe" "Iap.exe" "mdm.exe" "nvsvc32.exe" "regsvc.exe"
"MSTask.exe" "Win32sl.exe" "WinMgmt.exe" "svchost.exe" "inetinfo.exe"
"svchost.exe" "Explorer.EXE" "jusched.exe" "PwsTray.exe" "TeaTimer.exe"
"ctfmon.exe" "Printkey2000.exe" "OUTLOOK.EXE" "msimn.exe" "POINT32.EXE"
"acad.exe" "AdskCleanup.0001" "AdskScSrv.exe" "WSCommCntr1.exe"
"wisptis.exe"
"pageant.exe" "putty.exe" "putty.exe" "winscp368.exe" "AcroTray.exe"
"putty.exe" "IEXPLORE.EXE" "IEXPLORE.EXE" "notepad.exe" "IEXPLORE.EXE")
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd8467$1_2@newsprd01...
Is there any other applications open? If so what are they?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message
news:41dd80f2$1_3@newsprd01...
W2kpro with all the latest, ACAD2005 with all the latest.
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7db8$1_2@newsprd01...
Eric - Doesn't happen here (WinXP SP2).
Per chance, are you using some bozo (e.g. Win9x)
operating system?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in
message
news:41dd7b56$1_1@newsprd01...
I'm not doing anything within the (slightly modified, see below)
C:TEST
function either, just trying it out before I implement it. While in
the
while loop (while the while, heh heh), if I switch focus to any other
app,
like notepad, Outlook or Explorer, I don't have enough time to do
anything
before it looses focus to ACAD.
Create a file named C:\b.txt, start the C:TEST function and try to
rename it
to C:\a.txt.
(defun C:TEST (/ acad ws)
(setq acad (vlax-get-acad-object))
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
(setq ws (vla-get-windowstate acad))
(vla-put-windowstate acad 2)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while (not (findfile "C:/a.txt"));give it something to test
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(vla-put-windowstate acad ws)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7772_1@newsprd01...
Eric - Not sure what you mean by 'grabbing focus'.
Is AutoCAD in the foreground, or is it bringing itself
into the foreground and taking focus from another app?
If so, what app?
Doesn't happen here using the sample test function I
posted (which does nothing in the (while) loop).
Perhaps there's something in your loop that's
doing it?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in
message
news:41dd6f56$1_1@newsprd01...
Nice functions Tony. Is there a way to keep ACAD from grabbing
focus
every
second or so? It even grabs focus when (vla-put-windowstate
(vlax-get-acad-object) 2).
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd5abe_1@newsprd01...
Attached to this is a small ObjectARX library called
DoEvents.ARX.
Load it using (arxload "DoEvents.arx"). It will
define a LISP function called (DoEvents), which
is functionally equivalent to VBA's DoEvents() function.
Call the DoEvents function from the body of your
(while) loop and it should sove your problem.
There's a few caveats to this, mainly that it will
allow the user to switch documents, which is a no-no
when it comes to LISP, because that will suspend your
application until the document it runs in is made
active again. To address this, there are two other
functions to enable/disable document activation:
(EnableDocumentActivation)
(DisableDocumentActivation)
I suggest you call the latter before you start the
(while) loop in which you call DoEvents, and make
sure you call the former before your LISP calls any
API that polls for input.
So, you would basically have something like this:
(arxload "DoEvents.arx")
(defun C:TEST ()
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while <condition
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
PS: This is for AutoCAD 2004/2005 only
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in message
news:41dccd67_3@newsprd01...
Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay in
the
loop, it
seems to be the overhead of the while loop that causes the
problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Eric Schneider
Guest
|
Posted:
Fri Jan 07, 2005 12:17 am Post subject:
Re: While loop takes CPU resources |
|
|
It's quite annoying. I don't think it's your code. AutoCAD gains focus
even when doing an autosave when I have another app in the foreground.
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd8da4_1@newsprd01...
| Quote: | Sorry, no clue about why that's happening.
Perhaps someone else can try it, and see if
they get the same thing. I can't reproduce
it on WinXP with A2K5.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in message
news:41dd8b31$1_3@newsprd01...
Command: (dos_processes)
("smss.exe" "winlogon.exe" "services.exe" "lsass.exe" "svchost.exe"
"spoolsv.exe" "msdtc.exe" "ActionAgent.exe" "DellDmi.exe" "EventAgt.exe"
"DLT.exe" "svchost.exe" "Iap.exe" "mdm.exe" "nvsvc32.exe" "regsvc.exe"
"MSTask.exe" "Win32sl.exe" "WinMgmt.exe" "svchost.exe" "inetinfo.exe"
"svchost.exe" "Explorer.EXE" "jusched.exe" "PwsTray.exe" "TeaTimer.exe"
"ctfmon.exe" "Printkey2000.exe" "OUTLOOK.EXE" "msimn.exe" "POINT32.EXE"
"acad.exe" "AdskCleanup.0001" "AdskScSrv.exe" "WSCommCntr1.exe"
"wisptis.exe"
"pageant.exe" "putty.exe" "putty.exe" "winscp368.exe" "AcroTray.exe"
"putty.exe" "IEXPLORE.EXE" "IEXPLORE.EXE" "notepad.exe" "IEXPLORE.EXE")
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd8467$1_2@newsprd01...
Is there any other applications open? If so what are they?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in
message
news:41dd80f2$1_3@newsprd01...
W2kpro with all the latest, ACAD2005 with all the latest.
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7db8$1_2@newsprd01...
Eric - Doesn't happen here (WinXP SP2).
Per chance, are you using some bozo (e.g. Win9x)
operating system?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in
message
news:41dd7b56$1_1@newsprd01...
I'm not doing anything within the (slightly modified, see below)
C:TEST
function either, just trying it out before I implement it. While
in
the
while loop (while the while, heh heh), if I switch focus to any
other
app,
like notepad, Outlook or Explorer, I don't have enough time to do
anything
before it looses focus to ACAD.
Create a file named C:\b.txt, start the C:TEST function and try to
rename it
to C:\a.txt.
(defun C:TEST (/ acad ws)
(setq acad (vlax-get-acad-object))
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
(setq ws (vla-get-windowstate acad))
(vla-put-windowstate acad 2)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while (not (findfile "C:/a.txt"));give it something to
test
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(vla-put-windowstate acad ws)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in message
news:41dd7772_1@newsprd01...
Eric - Not sure what you mean by 'grabbing focus'.
Is AutoCAD in the foreground, or is it bringing itself
into the foreground and taking focus from another app?
If so, what app?
Doesn't happen here using the sample test function I
posted (which does nothing in the (while) loop).
Perhaps there's something in your loop that's
doing it?
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Eric Schneider" <eschneider@spamfree.jensenprecast.com> wrote in
message
news:41dd6f56$1_1@newsprd01...
Nice functions Tony. Is there a way to keep ACAD from grabbing
focus
every
second or so? It even grabs focus when (vla-put-windowstate
(vlax-get-acad-object) 2).
Regards,
Eric S
"Tony Tanzillo" <tony.tanzillo@U_KNOW_WHERE.com> wrote in
message
news:41dd5abe_1@newsprd01...
Attached to this is a small ObjectARX library called
DoEvents.ARX.
Load it using (arxload "DoEvents.arx"). It will
define a LISP function called (DoEvents), which
is functionally equivalent to VBA's DoEvents() function.
Call the DoEvents function from the body of your
(while) loop and it should sove your problem.
There's a few caveats to this, mainly that it will
allow the user to switch documents, which is a no-no
when it comes to LISP, because that will suspend your
application until the document it runs in is made
active again. To address this, there are two other
functions to enable/disable document activation:
(EnableDocumentActivation)
(DisableDocumentActivation)
I suggest you call the latter before you start the
(while) loop in which you call DoEvents, and make
sure you call the former before your LISP calls any
API that polls for input.
So, you would basically have something like this:
(arxload "DoEvents.arx")
(defun C:TEST ()
;; This will prevent the user from
;; switching to a different document.
;; (improper use of this function can
;; be dangerous):
(DisableDocumentActivation)
;; This code is wrapped in an exception handler
;; to ensure the call to EnableDocumentActivation
;; that follows it, is reached. If it is not, there will
;; be problems:
(vl-catch-all-apply
'(lambda ()
(while <condition
;; Calling this function forces AutoCAD
;; to process its message queue:
(DoEvents)
;; Do whatever you need here
)
)
)
(EnableDocumentActivation) ;; Make sure you do this!!!
)
PS: This is for AutoCAD 2004/2005 only
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
"Tim Skene" <tim.skene@spamfree.multicimdotcom> wrote in
message
news:41dccd67_3@newsprd01...
Try:
(while <condition
(command "._DELAY" 1000) ; change millisecs to suit
)
Makes no difference. Whether I put a long, short or no delay
in
the
loop, it
seems to be the overhead of the while loop that causes the
problem.
--
Tim Skene
|
|
|
| Back to top |
|
 |
Tim Skene
Guest
|
Posted:
Fri Jan 07, 2005 12:44 am Post subject:
Re: While loop takes CPU resources |
|
|
Thanks for the replies everyone. I will check out the options, incl. Tony's
arx file.
I had thought of running a VBA app from the lisp to do what I need and then
return to lisp. The principle seems to work so far.
--
Tim Skene |
|
| Back to top |
|
 |
|
|
|
|