Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Repeating Break at Single Point

10 REPLIES 10
Reply
Message 1 of 11
andit
2599 Views, 10 Replies

Repeating Break at Single Point

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

 

10 REPLIES 10
Message 2 of 11
Kent1Cooper
in reply to: andit


@Anonymous 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, AIA
Message 3 of 11
andit
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

Message 4 of 11
Lee_Mac
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.

Message 5 of 11
Kent1Cooper
in reply to: andit


@Anonymous 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, AIA
Message 6 of 11
stevor
in reply to: andit

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

 

S
Message 7 of 11
Kent1Cooper
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, AIA
Message 8 of 11
alanjt_
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)
)

 

Message 9 of 11
240149
in reply to: Lee_Mac

 Hi, your lisp has been pretty useful for me but, How do you stop it? it seems like I am in an infinite loop I can't get out of. 

Message 10 of 11
240149
in reply to: 240149

solved, just escape a lot of times. 

Message 11 of 11
john.uhden
in reply to: alanjt_

I like your use of "errno."  But your selection may be an unbreakable object such as text.

 

Here's a version I wrote a while back.  It presumes that anything that is offsetable can be broken...

 

(defun C:BreakAt ( / *error* cmdecho E Obj P)
;; Created (12-05-06) by John F. Uhden
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (or *doc* (setq *doc* (vla-get-ActiveDocument *acad*)))
  (defun *error* (error)
    (if (= (type cmdecho) 'INT)(setvar "cmdecho" cmdecho))
    (sssetfirst)
    (vla-endundomark *doc*)
    (cond
      ((not error))
      ((wcmatch (strcase error) "*QUIT*,*CANCEL*"))
      (1 (princ (strcat "\nERROR: " error)))
    )
    (princ)
  )
  (vla-endundomark *doc*)
  (vla-startundomark *doc*)
  (setq cmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (command "_.expert" (getvar "expert"))
  (and
    (setq E (car (entsel "\nPick object to break: ")))
    (sssetfirst nil (ssadd E))
    (setq Obj (vlax-ename->vla-object E))
    (or
      (vlax-method-applicable-p Obj 'Offset)
      (prompt "\nCan not break this object")
    )
    (setq P (getpoint "\nSelect break point: "))
    (setq P (vlax-curve-getclosestpointto Obj P))
    (command "_.break" E P "@")
  )
  (*error* nil)
)
(defun c:BA ()(C:BreakAt))

John F. Uhden

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost