LISP - Fillet Radius too large

LISP - Fillet Radius too large

hamza_itani
Enthusiast Enthusiast
334 Views
2 Replies
Message 1 of 3

LISP - Fillet Radius too large

hamza_itani
Enthusiast
Enthusiast

@Kent1Cooper 

Can you please add an option in the lisp to allow user to use the maximum radius instead of just asking for a specific one?

This is the code I have:

 

;;;  FilletMax.LSP [command name: FM]
;;;  To FILLET lines and/or lwpolyline line segments, notifying User of MAXimum possible
;;;  radius, and asking User to specify a radius (offering current default), before Filleting.
;;;  [If a LWPolyline has another segment in the direction beyond the intended filleted end of
;;;  the selected segment, and the other object is a Line, can sometimes fail or have unexpected
;;;  results, depending on geometry and/or whether the segment beyond is a line or arc,
;;;  because Fillet has limitations on what it can do in those situations.]
;;;  Kent Cooper, last edited 21 April 2016

(defun C:FM (/ *error* fmreset entselect isArcSeg doc cmde ofm ent1sel ent2sel ent1
  ent1 pick1 pick2 data1 data2 type1 type2 start1 end1 start2 end2 int farend1
  farend2 leg1 leg2 ang1 ang2 halfang tanang rmax rad)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (fmreset)
  ); defun - *error*

  (defun fmreset ()
    (setvar 'osmode osm)
    (setvar 'cmdecho cmde)
    (vla-endundomark doc)
  ); defun - fmreset

  (defun entselect (/ ent etype)
    (while
      (not
        (and
          (setq
            ent (entsel "\nSelect Line or LWPolyline line segment for Fillet: ")
            etype (if ent (cdr (assoc 0 (entget (car ent)))))
          ); setq
          (wcmatch etype "LWPOLYLINE,LINE")
        ); and
      ); not
      (prompt "\nNothing selected, or not a Line or LWPolyline --")
    ); while
    ent
  ); defun - entselect

  (defun isArcSeg (pickpoint / aper isArc)
    (setq aper (getvar 'aperture))
    (setvar 'aperture (getvar 'pickbox))
    (setq isArc (osnap pickpoint "_center"))
    (setvar 'aperture aper)
    isArc
  ); defun - isArcSeg

  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (setq cmde (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (setq osm (getvar 'osmode))
  (setvar 'osmode 0)

  (setq
    ent1sel (entselect)
    ent2sel (entselect)
    ent1 (car ent1sel)
    ent2 (car ent2sel)
    pick1 (osnap (cadr ent1sel) "_nea")
    pick2 (osnap (cadr ent2sel) "_nea")
    data1 (entget ent1)
    data2 (entget ent2)
    type1 (cdr (assoc 0 data1))
    type2 (cdr (assoc 0 data2))
  ); setq
  (if (or (isArcSeg pick1) (isArcSeg pick2))
    (progn
      (alert "Polyline picked on Arc segment: invalid.")
      (fmreset)
      (quit)
    ); progn
  ); if

  (if (= type1 "LINE")
    (setq start1 (cdr (assoc 10 data1)) end1 (cdr (assoc 11 data1)))
    (setq ; else - preceding and following polyline vertices
      start1
        (vlax-curve-getPointAtParam
          ent1
          (fix (vlax-curve-getParamAtPoint ent1 pick1))
        )
      end1
        (vlax-curve-getPointAtParam
          ent1
          (1+ (fix (vlax-curve-getParamAtPoint ent1 pick1)))
        )
    ); setq
  ); if - ends of first object
  (if (= type2 "LINE")
    (setq start2 (cdr (assoc 10 data2)) end2 (cdr (assoc 11 data2)))
    (setq ; else - preceding and following polyline vertices
      start2
        (vlax-curve-getPointAtParam
          ent2
          (fix (vlax-curve-getParamAtPoint ent2 pick2))
        )
      end2
        (vlax-curve-getPointAtParam
          ent2
          (1+ (fix (vlax-curve-getParamAtPoint ent2 pick2)))
        )
    ); setq
  ); if - ends of second object

  (setq
    int (inters start1 end1 start2 end2 nil); intersection of filleted objects [actual or apparent]
    farend1 (if (equal (angle pick1 int) (angle pick1 start1) 0.001) end1 start1)
    farend2 (if (equal (angle pick2 int) (angle pick2 start2) 0.001) end2 start2)
    leg1 (distance int farend1)
    leg2 (distance int farend2)
    ang1 (angle int farend1)
    ang2 (angle int farend2)
    halfang
      (if (< (abs (- ang1 ang2)) pi)
        (/ (abs (- ang1 ang2)) 2)
        (/ (- (* pi 2) (abs (- ang1 ang2))) 2)
      ); if
    tanang (/ (sin halfang) (cos halfang))
    rmax (min (* leg1 tanang) (* leg2 tanang))
    rad
      (cond
        ((getdist
          (strcat
            "Maximum fillet radius is "
            (rtos rmax)
            ".  Specify fillet radius <"
            (rtos (getvar 'filletrad))
            ">: "
          ); strcat
        )); getdist & first condition
        (T (getvar 'filletrad)); user hit Enter
      ); cond & rad
  ); setq

  (command "_.fillet" "_radius" rad "_.fillet" pick1 pick2)

  (fmreset)
  (princ)
); defun - FM

(vl-load-com)
(prompt "\nType FM to Fillet lines/polylines with notification of Maximum radius.")

 

@hamza_itani - moderation edited title for clarity. 

 

0 Likes
Accepted solutions (1)
335 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

Untested, but try:

....

rmax (min (* leg1 tanang) (* leg2 tanang)) ;;; keep up to here
rad ;;;;; get rid of all of this
  (cond
    ((getdist
      (strcat
        "Maximum fillet radius is "
        (rtos rmax)
        ". Specify fillet radius <"
        (rtos (getvar 'filletrad))
        ">: "
      ); strcat
    )); getdist & first condition
    (T (getvar 'filletrad)); user hit Enter
  ); cond & rad
); setq  ;;; keep this

(command "_.fillet" "_radius" rmax "_.fillet" pick1 pick2) ;;; change rad to rmax

 

Kent Cooper, AIA
0 Likes
Message 3 of 3

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

Untested, but try:

....


Tested now, and it worked.  BUT be aware:  If used on two Lines, it leaves the shorter one there, as a zero-length Line at the end of the resulting new Arc.  [Maybe it could be made to delete that.]  That may not be a problem for you, but when used on adjacent line segments in a Polyline, it leaves a zero-length segment at the far end of the shorter segment, which can be problematic in certain operations, particularly with some AutoLisp routines used on that Polyline.

Kent Cooper, AIA