Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
andit
Posts: 31
Registered: ‎08-31-2005
Message 1 of 8 (542 Views)

Repeating Break at Single Point

542 Views, 7 Replies
11-07-2011 04:06 PM

Hi All,

 

I'm creating the following macro:- (defun C:BK () (command "_BREAK" PAUSE "_F" PAUSE "@" )(princ)) to add to a shortcut key lisp file and then I want it to repeat... How do I make it repeat?

 

I want it to do the same as this:- *^C^C_break \_f \@ but as a shortcut key in a lisp format.

 

Cheers,

Andy

 

*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 2 of 8 (535 Views)

Re: Repeating Break at Single Point

11-07-2011 06:37 PM in reply to: andit

andit wrote:

.... 

I'm creating the following macro:- (defun C:BK () (command "_BREAK" PAUSE "_F" PAUSE "@" )(princ)) to add to a shortcut key lisp file and then I want it to repeat... How do I make it repeat?

.... 


One simple way:

 

(defun C:BK ()

  (while T

    (command "_BREAK" PAUSE "_F" PAUSE "@")

  )

)

 

You could add error handling so you wouldn't see the "error: Function cancelled" message when you hit Escape to stop it.

Kent Cooper
Active Contributor
andit
Posts: 31
Registered: ‎08-31-2005
Message 3 of 8 (529 Views)

Re: Repeating Break at Single Point

11-07-2011 08:57 PM in reply to: Kent1Cooper

Thankyou Kent that what I was looking for, may I ask how the "(while T" works to repeat the command?

 

Cheers,

Andy

*Expert Elite*
Lee_Mac
Posts: 1,179
Registered: ‎12-29-2009
Message 4 of 8 (519 Views)

Re: Repeating Break at Single Point

11-08-2011 03:40 AM in reply to: Kent1Cooper

Kent1Cooper wrote:
One simple way:
...
You could add error handling so you wouldn't see the "error: Function cancelled" message when you hit Escape to stop it.

Or:

 

(defun c:bk nil
    (while (vl-cmdf "_.break" pause "_F" pause "@")) (princ)
)
(vl-load-com)

 

So that no error handler is required.

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 5 of 8 (511 Views)

Re: Repeating Break at Single Point

11-08-2011 05:02 AM in reply to: andit

andit wrote:

Thankyou Kent that what I was looking for, may I ask how the "(while T" works to repeat the command?

....


See (while) in the AutoLISP Reference.  As long as the 'testexpr' argument doesn't evaluate to nil, it keeps doing what is asked for after that.  T is the symbol for True, and never evaluates to nil [unless you commit the crime of using it for a variable name and overriding that].  It could be anything that doesn't, such as

 

(while 1 (command ....

Kent Cooper
Mentor
stevor
Posts: 854
Registered: ‎12-26-2005
Message 6 of 8 (509 Views)

Re: Repeating Break at Single Point

11-08-2011 05:03 AM in reply to: andit

Also, you can use one GETPOINT, with or without object snaps, to assign both of the break points.

 

S
*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 7 of 8 (506 Views)

Re: Repeating Break at Single Point

11-08-2011 05:11 AM in reply to: Lee_Mac

Lee_Mac wrote:
....

Or:

 

....

(while (vl-cmdf "_.break" pause "_F" pause "@"))

....

So that no error handler is required.


I don't think it would have occurred to me to use a (while) function without any what-to-do-then expression(s) after the test expression, but sure enough, they are optional.

Kent Cooper
Valued Mentor
alanjt_
Posts: 480
Registered: ‎08-25-2008
Message 8 of 8 (499 Views)

Re: Repeating Break at Single Point

11-08-2011 06:04 AM in reply to: Kent1Cooper

I've been using this for quite some time, you could just replace the if with while...

 

(defun c:BA (/ e p)
  ;; Break Object @ Point
  ;; Alan J. Thompson, 03.26.09 / 08.23.10
  (setvar 'errno 0)
  (if (while (and (not e) (/= 52 (getvar 'errno))) (setq e (entsel "\nSelect object to break: ")))
    (progn (setq p (cond ((getpoint "\nSpecify point to break @ <Selection Point>: "))
                         ((osnap (cadr e) "_near"))
                   )
           )
           (vl-cmdf "_.break" e "_F" "_non" p "_non" p)
    )
  )
  (princ)
)

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.