Jump to content

Lisp for fillet radius.


broncos15

Recommended Posts

I currently have a lisp routine that will put the radius of fillet at what the user inputs for the command. For example f0 is:

 

 

 (defun c:f0 () 
 (setvar "FilletRad" 0)
 (command "Fillet")
  (princ)
)

I am wondering if there is a way to write a code so that for any input (ie f325.2) it would do fillet of a radius 325.2. Currently it is only defined from 0 to 50 at intervals of 5, but I have to define each function separately because of how it is written.

Edited by broncos15
Link to comment
Share on other sites

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • BIGAL

    10

  • Lee Mac

    10

  • broncos15

    8

  • zaphod

    1

You would somehow have to error trap the command line and pull apart the missing command. Then run the F R rad. The other alternative is that you use say F25 draw the fillet and there are some lisps out there pick fillet and enter 325.5 all done.

This may be usefull a nice routine

(DEFUN C:DYF (/ *ERROR* _PNT AT:GETSEL VL OV ENT PLST ELST GR SP)
 ;; DYNAMIC FILLET
 ;; ALAN J. THOMPSON, 03.07.11 / 03.09.11

 (VL-LOAD-COM)

 (DEFUN *ERROR* (MSG)
   (REDRAW)
   (AND VL (MAPCAR (FUNCTION SETVAR) VL OV))
   (AND ELST (MAPCAR (FUNCTION REDRAW) ELST '(4 4)))
   (IF (AND MSG (NOT (WCMATCH (STRCASE MSG) "*BREAK*,*CANCEL*,*QUIT*,")))
     (PRINC (STRCAT "\NERROR: " MSG))
   )
 )

 (DEFUN _PNT (P) (TRANS (LIST (CAR P) (CADR P)) 0 1))

 (DEFUN AT:GETSEL (METH MSG FNC / ENT)
   ;; METH - SELECTION METHOD (ENTSEL, NENTSEL, NENTSELP)
   ;; MSG - MESSAGE TO DISPLAY (NIL FOR DEFAULT)
   ;; FNC - OPTIONAL FUNCTION TO APPLY TO SELECTED OBJECT
   ;; EX: (AT:GETSEL ENTSEL "\NSELECT ARC: " (LAMBDA (X) (EQ (CDR (ASSOC 0 (ENTGET (CAR X)))) "ARC")))
   ;; ALAN J. THOMPSON, 05.25.10
   (SETVAR 'ERRNO 0)
   (WHILE
     (PROGN (SETQ ENT (METH (COND (MSG)
                                  ("\NSELECT OBJECT: ")
                            )
                      )
            )
            (COND ((EQ (GETVAR 'ERRNO) 7) (PRINC "\NMISSED, TRY AGAIN."))
                  ((EQ (TYPE (CAR ENT)) 'ENAME)
                   (IF (AND FNC (NOT (FNC ENT)))
                     (PRINC "\NINVALID OBJECT!")
                   )
                  )
            )
     )
   )
   ENT
 )

 (IF (SETQ ENT
            (CAR
              (AT:GETSEL
                ENTSEL
                "\NSELECT ARC: "
                (LAMBDA (X)
                  (IF (EQ "ARC" (CDR (ASSOC 0 (ENTGET (CAR X)))))
                    (VL-EVERY (FUNCTION (LAMBDA (P / SS)
                                          (IF (SETQ SS (SSGET "_C" P P '((0 . "LINE"))))
                                            (SETQ ELST (CONS (SSNAME SS 0) ELST))
                                          )
                                        )
                              )
                              (SETQ PLST (LIST (_PNT (VLAX-CURVE-GETSTARTPOINT (CAR X)))
                                               (_PNT (VLAX-CURVE-GETENDPOINT (CAR X)))
                                         )
                              )
                    )
                  )
                )
              )
            )
     )
   (PROGN
     (SETQ OV (MAPCAR (FUNCTION GETVAR) (SETQ VL '("CMDECHO" "FILLETRAD"))))
     (WHILE
       (PROGN
         (SETQ GR (GRREAD T 15 0))
         (COND
           ((EQ 5 (CAR GR))
            (REDRAW)
            (GRDRAW (SETQ SP (TRANS (VLAX-CURVE-GETSTARTPOINT ENT) 0 1)) (CADR GR) 1 -1)
            (PRINC
              (STRCAT "\RFILLET RADIUS: "
                      (RTOS (SETVAR 'FILLETRAD (DISTANCE SP (CADR GR))))
                      "      "
              )
            )
            (IF (VL-CMDF "_.FILLET" (LIST (CAR ELST) (CAR PLST)) (LIST (CADR ELST) (CADR PLST)))
              (PROGN (ENTDEL ENT) (SETQ ENT (ENTLAST)))
              T
            )
           )
         )
       )
     )
   )
 )
 (*ERROR* NIL)
 (PRINC)
)

Link to comment
Share on other sites

Lee my question is though like the post I type F1123.45 it knows its a "unknown command" no lisps ! But can somehow strip the 1123.45 and continue on running the fillet command, as I mentioned before I don't know how you could handle the top level Autocad error trap. Do you have any ideas. Would open up a pandoras box of shortcuts.

Link to comment
Share on other sites

Lee my question is though like the post I type F1123.45 it knows its a "unknown command" no lisps ! But can somehow strip the 1123.45 and continue on running the fillet command, as I mentioned before I don't know how you could handle the top level Autocad error trap. Do you have any ideas. Would open up a pandoras box of shortcuts.

 

Hi Al, as noted in my linked post on the other forum, my code converts the decimal point in fillet radius values such as 1123.45 to create custom command such as F1123-45.

Link to comment
Share on other sites

Lee thank you so much for the help! Your posts and website have been so helpful for me learning how to write lisp and visual lisp programs.

Link to comment
Share on other sites

Lee thank you so much for the help! Your posts and website have been so helpful for me learning how to write lisp and visual lisp programs.

 

You're most welcome!

Link to comment
Share on other sites

  • 1 month later...

A bit more. Lee need your help this is close. It jumps to the defun but just does not do the "Fillet" command any help would be appreciated.

 

; A command line fillet with the desired radius without pressing the R option.
; By Alan H October 2015
; Enter any number after F say F4.5 this will return a Unknown command which is trapped and checked 
; to see if the first character is a F and the radius then follows.
; F is checked as a Fabsdf would give an error as it has no number following the F.

(vl-load-com)

(defun filletfunction (objReactor Errorstr)  
(setq ahval (car Errorstr))

(if (= (strcase (substr ahval 1 1)) "F")
 (progn
 (setq rad (atof (substr ahval 2)))
   (if (> rad 0.0) ; returns 0.0 if alpha character 
     (progn
     (setvar "Filletrad" rad)    
     (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "Fillet " )
     )
     (princ "No radius")
   )
 )  
) 
)

; Starts here

(setq Reactor-Put (vlr-command-reactor nil '((:vlr-unknownCommand . filletfunction))))

Edited by BIGAL
Link to comment
Share on other sites

Thanks Lee I dont use reactors, I knew it would require some method of stopping the call back and then running a command bit more homework.

 

The code above now works for the range 0+ only problem is that a f0.45 the decimal point is interpreted as a dot in a list so screws up the radius input.

 

Lee any ideas.

Edited by BIGAL
Link to comment
Share on other sites

The code above now works for the range 0+ only problem is that a f0.45 the decimal point is interpreted as a dot in a list so screws up the radius input.

 

Lee any ideas.

 

Since the point is a command modifier (to instruct AutoCAD to use the standard definition of a command), AutoCAD will only read input following this character (or following any command modifiers which follow it).

 

Therefore, since this restriction cannot be avoided, as an alternative, I would suggest that the user enters "F4-5" to mean "F4.5", or "F0-45"/"F-45" to mean "F0.45".

 

I would suggest the following code:

(   (lambda nil
       (vl-load-com)
       (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
           (if (= "fillet-reactor" (vlr-data obj))
               (vlr-remove obj)
           )
       )
       (vlr-command-reactor "fillet-reactor" '((:vlr-unknowncommand . fillet-reactor-callback)))
   )
)
(defun fillet-reactor-callback ( obj com / rad )
   (if
       (and
           (setq com (vl-string-translate "-" "." (strcase (car com))))
           (wcmatch com "~*[~F.0-9]*")
           (wcmatch com "F*")
           (wcmatch com "~F*F*")
           (wcmatch com "~*.*.*")
           (setq rad (distof (substr com 2) 2))
           (<= 0.0 rad)
       )
       (progn
           (setvar 'filletrad rad)
           (vla-sendcommand fillet-reactor-acdoc "_.fillet ")
       )
   )
   (princ)
)
(or fillet-reactor-acdoc
   (setq fillet-reactor-acdoc (vla-get-activedocument (vlax-get-acad-object)))
)
(princ)

Link to comment
Share on other sites

Since the point is a command modifier (to instruct AutoCAD to use the standard definition of a command), AutoCAD will only read input following this character (or following any command modifiers which follow it).

 

Therefore, since this restriction cannot be avoided, as an alternative, I would suggest that the user enters "F4-5" to mean "F4.5", or "F0-45"/"F-45" to mean "F0.45".

 

I would suggest the following code:

(   (lambda nil
       (vl-load-com)
       (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
           (if (= "fillet-reactor" (vlr-data obj))
               (vlr-remove obj)
           )
       )
       (vlr-command-reactor "fillet-reactor" '((:vlr-unknowncommand . fillet-reactor-callback)))
   )
)
(defun fillet-reactor-callback ( obj com / rad )
   (if
       (and
           (setq com (vl-string-translate "-" "." (strcase (car com))))
           (wcmatch com "~*[~F.0-9]*")
           (wcmatch com "F*")
           (wcmatch com "~F*F*")
           (wcmatch com "~*.*.*")
           (setq rad (distof (substr com 2) 2))
           (<= 0.0 rad)
       )
       (progn
           (setvar 'filletrad rad)
           (vla-sendcommand fillet-reactor-acdoc "_.fillet ")
       )
   )
   (princ)
)
(or fillet-reactor-acdoc
   (setq fillet-reactor-acdoc (vla-get-activedocument (vlax-get-acad-object)))
)
(princ)

Lee, thank you so much for this code. It is a cool use of reactors, and really helpful for someone new at coding them to look at.
Link to comment
Share on other sites

Lee, thank you so much for this code. It is a cool use of reactors, and really helpful for someone new at coding them to look at.

 

You're very welcome broncos - though, all credit to BIGAL for the idea of using a reactor triggered on the unknowncommand event; in contrast, a previous approach I've followed is to predefine a set of custom fillet commands, as demonstrated here.

 

Glad it helps!

 

Lee

Link to comment
Share on other sites

Thank you Lee I had also thought last night that the way to go was F0-6 for 0.6 radius, it would be just getting used to input this way, it would have required a bit more checking for the "-"

 

Your code is as usual a bit more elegant than mine.

 

Hmmm Offset.

 

Oh yeah C22

Edited by BIGAL
Link to comment
Share on other sites

BigAl and Lee, I am sure that one of you could help me with this. I made modifications to Lee's code so that it would work with offset. Everything works correctly, however, I am unsure of how to not have the user hit enter when they invoke the command. For example right now, o62 invokes the offset at a distance at 62, but the user still has to hit enter before selecting the object. I can't think of how to add in the typical user input "" for enter because the command is invoked from visual lisp.

((lambda nil
  (vl-load-com)
  (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
    (if (= "offset-reactor" (vlr-data obj))
      (vlr-remove obj)
    )
  )
  (vlr-command-reactor
    "offset-reactor"
    '((:vlr-unknowncommand . offset-reactor-callback))
  )
)
)
(defun offset-reactor-callback (obj com / dist)
 (if
   (and
     (setq com (vl-string-translate "-" "." (strcase (car com))))
     (wcmatch com "~*[~O.0-9]*")
     (wcmatch com "O*")
     (wcmatch com "~O*O*")
     (wcmatch com "~*.*.*")
     (setq dist (distof (substr com 2) 2))
     (<= 0.0 dist)
   )
    (progn
      (setvar 'offsetdist dist)
      (vla-sendcommand offset-reactor-acdoc "_.offset ")
    )
 )
 (princ)
)
(or offset-reactor-acdoc
   (setq offset-reactor-acdoc
   (vla-get-activedocument (vlax-get-acad-object))
   )
)
(princ)

Link to comment
Share on other sites

Change:

"_.offset "

to:

"_.offset  "

:)

Wow, that was an easy fix haha. Thanks for the help Lee. So for visual lisp commands, does an extra space take the place of "" used in autolisp?

Link to comment
Share on other sites

Wow, that was an easy fix haha. Thanks for the help Lee.

 

You were pretty close :D

 

So for visual lisp commands, does an extra space take the place of "" used in autolisp?

 

Not in general - the sendcommand method is performing an operation similar to the user manually typing the supplied string argument at the command-line (similar to how Scripts (.scr) operate), therefore spaces or carriage returns can be used for ENTER.

Link to comment
Share on other sites

You were pretty close :D

 

 

 

Not in general - the sendcommand method is performing an operation similar to the user manually typing the supplied string argument at the command-line (similar to how Scripts (.scr) operate), therefore spaces or carriage returns can be used for ENTER.

That makes sense, I was wondering why it was like how you have enter for a script file. Thanks again for the information and the help with it, I appreciate it.
Link to comment
Share on other sites

That makes sense, I was wondering why it was like how you have enter for a script file. Thanks again for the information and the help with it, I appreciate it.

 

You're welcome broncos, happy to help.

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...