Author Topic: COmplete commands within autolisp  (Read 2045 times)

0 Members and 1 Guest are viewing this topic.

TimAshby

  • Guest
COmplete commands within autolisp
« on: December 12, 2014, 03:19:36 PM »
Morning all!

I've needed to use a standard Acad command within a LISP routine a couple of times. I'm familiar with the idea of using (command "stuff"), (vl-cmdf "stuff") & (command-s "stuff"). I'm also aware that one can use (initcommandversion) to make things behave. However, commands don't seem to behave properly when actually used open-endedly within a LISP itself. For example, take the following code:

Code: [Select]
(defun  C:cts ( / )

  (princ "\nStart of test")
  (command "COPY")
  (princ "\nEnd of test")
  (princ)
  );defun

The idea being I want to copy whatever I want, as many times as I want, however I want. What actually happens is:

Code: [Select]
Command: cts
Start of testCOPY
Select objects:
End of test

Select objects: Specify opposite corner: 2 found

Select objects:
Specify base point or [Displacement/Multiple] <Displacement>:
Specify second point or [Array] <use first point as displacement>:
Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

So the code continues to run, seems to finish & THEN runs the COPY command. In this example, not the end of the world, in the middle of a serious LISP, a real nuisance.

Does anyone know of a way to make this work properly?

I appreciate there are work-arounds, most of which would lose some functionality of the command, or essentially involve re-writing the command itself... Not what I'm after!

Thanks in advance!

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: COmplete commands within autolisp
« Reply #1 on: December 12, 2014, 03:32:24 PM »
HTH
Code - Auto/Visual Lisp: [Select]
  1. (defun  C:cts ( / )
  2.   (princ "\nStart of test")
  3.   (command "COPY")
  4.   ;; wait for the command to end.
  5.   (while (eq (logand (getvar 'CMDACTIVE) 1) 1)
  6.    (command PAUSE) )
  7.   (princ "\nEnd of test")
  8.   (princ)
  9. );defun
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

TimAshby

  • Guest
Re: Complete commands within autolisp
« Reply #2 on: December 12, 2014, 03:59:58 PM »
Thanks John, awesome response time! That'll do me nicely when stuck in some real code. Presumably adding an (or (logand 2) would then allow me to use transparent commands?

Code: [Select]
    (defun  C:cts ( / )
     (princ "\nStart of test")
     (command "COPY")
     ;; wait for the command to end.
     (while
       (or
         (eq (logand (getvar 'CMDACTIVE) 1) 1)
         (eq (logand (getvar 'CMDACTIVE) 2) 2)
         )
      (command PAUSE) )
     (princ "\nEnd of test")
     (princ)
    );defun

The initial code with the (while) added seems to lock me down to single object selection - is there a sensible reason why this happens? (I can stick an (ssget) into the COPY & that solves the issue, I'm just curious / greedy at this point)

Thanks again.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: COmplete commands within autolisp
« Reply #3 on: December 12, 2014, 04:06:59 PM »
Tim, which build of AutoCAD are you using ??
I thought there were issues using command and PAUSE with AC2015 and onward. ( may be incorrect )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

TimAshby

  • Guest
Re: COmplete commands within autolisp
« Reply #4 on: December 16, 2014, 12:45:24 PM »
AC2013 - Not quite that up-to-date yet  :-)