Jump to content

What is the code that I can add to allow any LISP to repeat the command?


vernonlee

Recommended Posts

What is the code that I can add to allow any LISP to repeat the command & stop only after I press ESC or something?

 

Below is a sample LISP for reference.

 

Thanks

 

(defun c:bb ( / oldos ent1 p1)
 (setq
oldos (getvar "osmode"))
(setq ent1 (entsel "\nSelect object to
break...    "))
(setq p1 (getpoint "\nPoint at which to
break...    "))
(setvar "osmode" 0)
(command
"break" ent1 "f" p1 "@" "")
(setvar "osmode" oldos)
(princ
"\nBreak at Done")
 (princ)
);end defun c:ba ()

Link to comment
Share on other sites

(defun c:bb (/ oldos ent1 p1)
 (setq oldos (getvar "osmode"))
 (while (and (setq ent1 (entsel "\nSelect object to break...    "))
             (setq p1 (getpoint "\nPoint at which to break...    "))
        )
   (setvar "osmode" 0)
   (command "break" ent1 "f" p1 "@" "")
   (setvar "osmode" oldos)
   (princ "\nBreak at Done")
 )
 (princ)
);end defun c:ba ()

 

HTH

Henrique

Link to comment
Share on other sites

Maybe :

 

[b][color=BLACK]([/color][/b]defun c:bb [b][color=FUCHSIA]([/color][/b] / oldos ent1 p1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq oldos [b][color=NAVY]([/color][/b]getvar [color=#2f4f4f]"osmode"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq ent1 [b][color=MAROON]([/color][/b]entsel [color=#2f4f4f]"\nSelect object to break...    "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]initget 1[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq p1 [b][color=MAROON]([/color][/b]getpoint [color=#2f4f4f]"\nPoint at which to break...    "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setvar [color=#2f4f4f]"osmode"[/color] 0[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]command [color=#2f4f4f]"_.BREAK"[/color] ent1 [color=#2f4f4f]"_f"[/color] p1 [color=#2f4f4f]"@"[/color] [color=#2f4f4f]""[/color][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setvar [color=#2f4f4f]"osmode"[/color] oldos[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nBreak at Done"[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

-David

Link to comment
Share on other sites

Thanks Henrique & David.

 

I will look at them & see what is the extra code you use to repeat the command.

 

I can just use it to also to apply to other LISP as well following the same location of where you place the code?

 

Thanks

Link to comment
Share on other sites

Use a While check for pick object (while (entsel) ....) if you pick blank screen it will exit same for esc & I often check for (/= ans Nil) this press

Link to comment
Share on other sites

Comparing the code, I see that the additional code is this:-

 

(while (initget 1))

(defun c:BB ( / oldos ent1 p1)
 (setq oldos (getvar "osmode"))
 [color=red][b](while[/b][/color] (setq ent1 (entsel "\nSelect object to break...    "))
        [color=red][b](initget 1)[/b][/color]
        (setq p1 (getpoint "\nPoint at which to break...    "))
        (setvar "osmode" 0)
        (command "_.BREAK" ent1 "_f" p1 "@" "")
        (setvar "osmode" oldos))
 (princ "\nBreak at Done")
 (princ)[color=red][b])[/b][/color]

Link to comment
Share on other sites

You could probably do away with osmode settings with:

 

(command "_.BREAK" ent1 "_non" p1 "_non" p1)

 

Hi David, what does this code do?

 

EDIT

 

I replace as suggested & now there is a gap at every break line? :?

Link to comment
Share on other sites

Hi vernonlee,

 

probably David's suggestion was just just to do away with osmode, using the object snap mode "_NONE" inside the command call, instead of store OSMODE, set OSMODE and restore OSMODE

(command "_.BREAK" ent1 "_f" "_NONE" p1 "_NONE" "@" "")

And in the 'while' function, you must test a function, in David's code, the test function was

(setq ent1 (entsel "\nSelect object to break...    "))

the 'initget' was just to force the user to enter a point at 'getpoint' function, the flag 1 is to 'Prevents the user from responding to the request by entering only Enter'

In the code I have post, I did use two functions to test inside the 'while' function,

(and (setq ent1 (entsel "\nSelect object to break...    "))
             (setq p1 (getpoint "\nPoint at which to break...    "))
        )

to allow the user to exit the loop in any of the functions.

Without setting OSMODE, your code might be something like this

(defun c:bb (/ ent1 p1)
 (while (and (setq ent1 (entsel "\nSelect object to break...    "))
             (setq p1 (getpoint "\nPoint at which to break...    "))
        )
   (command "_.BREAK" ent1 "_f" "_NONE" p1 "_NONE" "@" "")
   (princ "\nBreak at Done")
 )
 (princ)
);end defun c:ba ()

Henrique

Link to comment
Share on other sites

What is the code to put if i want it to snap to INT & END?

 

(command "_.BREAK" ent1 "_f" "[b]_NONE[/b]" p1 "[b]_NONE[/b]" "@" "")

Link to comment
Share on other sites

You're welcome, vernonlee

Glad I could help...

 

What is the code to put if i want it to snap to INT & END?

 

(command "_.BREAK" ent1 "_f" "[b]_NONE[/b]" p1 "[b]_NONE[/b]" "@" "")

 

>> Read this

 

Henrique

Link to comment
Share on other sites

Thanks for the guide. Will try it when back after the long weekend

Happy Easter.

 

 

Happy Easter, vernonlee!

 

 

Henrique

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...