Help with updating current Auto fillet lisp command

Help with updating current Auto fillet lisp command

bgraverholt
Advocate Advocate
827 Views
13 Replies
Message 1 of 14

Help with updating current Auto fillet lisp command

bgraverholt
Advocate
Advocate

Looking to update my auto fillet lisp command shown below

 

(defun c:r5 (/ ofr r e1)
  (setq ofr (getvar "filletrad"))
  (if (= r1 nil)
    (setq r1 10.0)
  )
  (princ "\n Bend radius < ")
  (princ r1)
  (princ " >?:")
  (setq r (getdist))
  (if (= r nil)
    (setq r r1)
  )
  (setq r1 r)
  (princ "\n Start polyline: ")
  (command "._pline")
  (while (= 1 (logand (getvar "CMDACTIVE") 1))
    (command PAUSE)
  )
  (setq e1 (entlast))
  (setvar "filletrad" r)
  (command "fillet" "p" e1)
  (setvar "filletrad" ofr)
  (princ)
)

 

 

But what I am looking to do on first run of the lisp to ask user for Fillet Radius. But to remember the that value when you run R5 the next time. But have an option to type R for arc radius to change it if you want a different arc radius. 

I have a similar command that does this with centered text but for the life of me cant figure out how to merge that code with the R5 command to get it to work... Below is the text command that request text height on first run and remembers it until you type H to change the text height. Basically need R5 lisp to work similar to this one below but not with text haha!

 

(defun c:textmc (/ getht startpoint)
  (defun getht ()
    (initget 6); no 0, no negative
    (setq *tmcht ; global variable
      (cond
        ( (getdist ; [returns nil on Enter]
            (strcat
              "\nText Size <"
              (rtos (cond (*tmcht) (0.0625))); 1/16 initial default if not yet set
              ">: "
            ); strcat
          ); getdist
        ); User-input condition
        (*tmcht); Enter with prior value
        (0.0625); Enter on first use [initial default]
      ); cond
    ); setq
  ); defun -- getht
  (setvar 'textstyle "STANDARD")
  (while (not (member '(40 . 0.0) (tblsearch "style" (getvar 'textstyle))))
    (alert "Set a non-fixed-height Style current.")
    (initdia)
    (command "_.style")
  ); while
  (if (not *tmcht) (getht)); if no prior value
  (initget "Height")
  (while
    (=
      (setq startpoint
        (getpoint
          (strcat
            "Current height = "
            (rtos *tmcht)
            ". Enter Middle-Center Point or [Height]: "
          ); strcat
        ); getpoint
      ); setq
      "Height" ; [User chose H option]
    ); =
    (getht)
    (initget "Height"); for possible repeat H options
  ); while
  (command "_.dtext" "_mc" startpoint *tmcht "0")
  (setvar 'textstyle tsty); reset what was current before
  (princ); [so it doesn't put the reset Text Style name at the Command: line]
); defun -- textmc

 

0 Likes
Accepted solutions (1)
828 Views
13 Replies
Replies (13)
Message 2 of 14

Moshe-A
Mentor
Mentor

@bgraverholt  hi,

 

check this fix 😀

 

Moshe

 

(defun c:r5 (/ ofr r1 e1)
  (setvar "cmdecho" 0)
  (command "._undo" "_begin") 
  
  (setq r1 
     (cond
      ((getdist ; [returns nil on Enter]
         (strcat
            "\nBend radius <" (rtos (getvar "filletrad")) ">: "
          ); strcat
       ); getdist
      ); User-input condition
      (r1); Enter with prior value
      (10.0); Enter on first use [initial default]
     ); cond
  )
 
  (princ "\n Start polyline: ")
  (command "._pline")
  (while (= 1 (logand (getvar "CMDACTIVE") 1))
    (command PAUSE)
  )

  (setq e1 (entlast))
  (setvar "filletrad" r1)
  (command "fillet" "p" e1)
  
  (command "._undo" "_end") 
  (setvar "cmdecho" 1)
  (princ)

 

 

0 Likes
Message 3 of 14

Kent1Cooper
Consultant
Consultant

That TEXTMC routine looks like one of mine.  @Moshe-A 's suggestion needs you to set or confirm the radius every time you call the command, and also doesn't reset the outside-the-routine radius when done.  Here's a [minimally tested] modification that does what I think you're after, asking for a radius the first time, but after that, reporting what that radius setting is, but letting you just jump right into drawing the Polyline, unless you call for the option to change the radius, and resets the previous radius for regular Fillet commands.

 

(defun c:R5 (/ getfr ofr startpoint)
  (defun getfr ()
    (initget 6); no 0, no negative
    (setq *R5fr ; global variable
      (cond
        ( (getdist ; [returns nil on Enter]
            (strcat
              "\nBend Radius <"
              (rtos (cond (*R5fr) (10))); 10 initial default if not yet set
              ">: "
            ); strcat
          ); getdist
        ); User-input condition
        (*R5fr); Enter with prior value
        (10.0); Enter on first use [initial default]
      ); cond
    ); setq
  ); defun -- getfr
  (setq ofr (getvar 'filletrad))
  (if (not *R5fr) (getfr)); if no prior value
  (initget "Radius")
  (while
    (=
      (setq startpoint
        (getpoint
          (strcat
            "Current Bend Radius = "
            (rtos *R5fr)
            ". Start Polyline or [Radius]: "
          ); strcat
        ); getpoint
      ); setq
      "Radius" ; [User chose R option]
    ); =
    (getfr)
    (initget "Radius"); for possible repeat R options
  ); while
  (setvar 'filletrad *R5fr)
  (command-s "_.pline" startpoint)
  (command "_.fillet" "_polyline" (entlast))
  (setvar 'filletrad ofr); reset what was current before
  (princ)
); defun -- R5

 

[By the way, why R5?]

 

Kent Cooper, AIA
0 Likes
Message 4 of 14

bgraverholt
Advocate
Advocate

That's perfect! Thank you so much! 

0 Likes
Message 5 of 14

bgraverholt
Advocate
Advocate

After using it for a few days I have a couple questions. 

1. When trying to select a point on a line after referencing an end point the start point always goes to the nearest endpoint/midpoint. Is there a way to enable apparent intersection (I think thats the word I'm looking for)

2. If you click a starting point and don't like where its at you cant hit escape otherwise it will auto fillet the last line created. Is there a way to enable escape to cancel the command with out filleting?

Please see screen cast below for examples of both questions.
https://autode.sk/3TuPnVC

0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

For the first one, try making this change:

  (command-s "_.pline" "_non" startpoint)

Or you could have it just turn off Osnap, but I assume you might want that on for continuation of drawing the Polyline.

 

For the second, two changes:

(setq ofr (getvar 'filletrad) elast (entlast))

and

(if (not (eq (entlast) elast)) (command "_.fillet" "_polyline" (entlast)))

Kent Cooper, AIA
0 Likes
Message 7 of 14

Sea-Haven
Mentor
Mentor

I dont use initget anymore, just press ok if happy with current value or enter new.

 

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(if (= *R5fr nil)(setq *R5fr 5))
(setq *R5fr (atof (car (AH:getvalsm (list "Enter value " "Radius " 5 4 (rtos *R5fr 2 1) )))))

 

SeaHaven_0-1666656087194.png

 

0 Likes
Message 8 of 14

bgraverholt
Advocate
Advocate

Thanks for the reply back. I was able to complete the first change without any issues. However the second one I am not sure if I am changing the code in the correct spot since it breaks it. The error reads 

bgraverholt_0-1666811579405.png

The 2 lines of code I replaced were these 2. (not the radius line)

bgraverholt_1-1666811661327.png

 

Is that what I should have done?
Just noticed your question from your original post about why R5? No particular reason just a simple way of activating the command. Its technically R4 instead of 5 just changed it for testing purposes lol 

0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant

The two changes suggested at the end of Message 6 are in different places, not for adjacent lines.

Kent Cooper, AIA
0 Likes
Message 10 of 14

bgraverholt
Advocate
Advocate

Sorry I guess I am not sure what lines of the code need changed for the last part of that message.  

0 Likes
Message 11 of 14

Kent1Cooper
Consultant
Consultant

The black parts are present in the earlier code; the blue parts are to be added.

Kent Cooper, AIA
0 Likes
Message 12 of 14

bgraverholt
Advocate
Advocate

Got the blue parts replaced and it worked. One last request/question. Is there a way so that after you draw the PLINE and you hit escape it will not fillet the line either? It only fillets on hitting enter? Got someone complaining that escape will filet the line haha... 

0 Likes
Message 13 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

@bgraverholt wrote:

.... Is there a way so that after you draw the PLINE and you hit escape it will not fillet the line either? It only fillets on hitting enter? Got someone complaining that escape will filet the line haha... 


The problem is that the (command-s) function lets you continue in the command until it is completed, then lets the routine go on to the next thing.  In the case of being in a PLINE command, ESCape is a legitimate way to end it, just as much as Enter/space, so that happens and it goes on.  ESCape doesn't crash the overall routine, but merely ends the PLINE command.

 

You can get around that by not using (command-s), but just (command), followed by the allow-user-input-until-the-command-is-done approach that looks at the CMDACTIVE System Variable:

....

  (setvar 'filletrad *R5fr)
  (command "_.pline" startpoint)
; instead of (command-s)

  (while (> (getvar 'cmdactive) 0) (command pause))
  (command "_.fillet" "_polyline" (entlast))

....

In that approach, ESCape will stop the whole routine, not just the PLINE command, and it won't go on to Fillet.  You'll get an error message about cancelling the command, but the Polyline you've been drawing will stop there, without being Filleted.  But it also means that the Fillet radius setting before you started will not be restored, so if you want that, *error* handling should be added to ensure it gets reset.

Kent Cooper, AIA
0 Likes
Message 14 of 14

bgraverholt
Advocate
Advocate

Perfect! Thank you so much for you help on this!

0 Likes