Author Topic: Mulitple Best Fit Fillet  (Read 2673 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Mulitple Best Fit Fillet
« on: April 02, 2019, 09:55:13 AM »
Is it possible for a user to select a group of lines / polylines and perform a best fit fillet them?

Currently I have the following routine which allows to select 3 points and do a best fit curve / fillet. Works great.

I am wondering how to create a select set and then apply this command to it.

The scenario is this. I am working with basic rectangular shapes for curb islands. I would like to be able to click a window around the corners I would like to have fillet. Hope this kinda makes some sense.









Code: [Select]
;given three lines or polyline or arcs or any combination thereof, fits an arc tangent
;to all 3 and trims off excess.

(defun c:CRF ( / *error* adoc oldosmode pt1 pt2 pt3 cen ent1 ent2 ent3 )

  (vl-load-com)

  (defun *error* ( m )
    (if oldosmode
      (setvar "OSMODE" oldosmode)
    )
    (if adoc
      (vla-endundomark adoc)
    )
    (if m
      (prompt m)
    )
    (princ)
  )

  (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
  (setq oldosmode (getvar "OSMODE"))
  (setvar "OSMODE" 512)
  (initget 1)
  (setq pt1 (getpoint "\nPoint to first line: "))
  (initget 1)
  (setq pt2 (getpoint "\nPoint to second line: "))
  (initget 1)
  (setq pt3 (getpoint "\nPoint to third line: "))
  (vl-cmdf "_.CIRCLE" "_3P" "_tan" pt1 "_tan" pt2 "_tan" pt3)
  (setvar "OSMODE" 0)
  (setq cen (trans (cdr (assoc 10 (entget (entlast)))) (entlast) 1))
  (entdel (entlast))
  (setvar "LASTPOINT" cen)
  (setq
     pt1 (osnap pt1 "_per")
     pt2 (osnap pt2 "_per")
     pt3 (osnap pt3 "_per")
  )
  (setq
     ent1 (ssget pt1)
     ent2 (ssget pt2)
     ent3 (ssget pt3)
  )
  (cond
    ( (and (not (eq (ssname ent1 0) (ssname ent2 0))) (not (eq (ssname ent2 0) (ssname ent3 0))))
      (vl-cmdf "_.BREAK" ent1 pt1 (car (vl-sort (list (trans (vlax-curve-getstartpoint (ssname ent1 0)) 0 1) (trans (vlax-curve-getendpoint (ssname ent1 0)) 0 1)) (function (lambda ( a b ) (< (distance pt2 a) (distance pt2 b)))))))
      (vl-cmdf "_.BREAK" ent3 pt3 (car (vl-sort (list (trans (vlax-curve-getstartpoint (ssname ent3 0)) 0 1) (trans (vlax-curve-getendpoint (ssname ent3 0)) 0 1)) (function (lambda ( a b ) (< (distance pt2 a) (distance pt2 b)))))))
      (vl-cmdf "_.ERASE" ent2 "")
    )
    ( (or (not (eq (ssname ent1 0) (ssname ent2 0))) (not (eq (ssname ent2 0) (ssname ent3 0))))
      (vl-cmdf "_.BREAK" ent1 pt1 (car (vl-sort (list (trans (vlax-curve-getstartpoint (ssname ent1 0)) 0 1) (trans (vlax-curve-getendpoint (ssname ent1 0)) 0 1)) (function (lambda ( a b ) (< (distance pt2 a) (distance pt2 b)))))))
      (setq ent3 (ssget pt3))
      (vl-cmdf "_.BREAK" ent3 pt3 (car (vl-sort (list (trans (vlax-curve-getstartpoint (ssname ent3 0)) 0 1) (trans (vlax-curve-getendpoint (ssname ent3 0)) 0 1)) (function (lambda ( a b ) (< (distance pt2 a) (distance pt2 b)))))))
      (vl-cmdf "_.ERASE" (ssget pt2) "")
    )
    ( t
      (vl-cmdf "_.BREAK" ent1 pt1 pt2)
      (setq ent3 (ssget pt3))
      (vl-cmdf "_.BREAK" ent3 pt2 pt3)
    )
  )
  (vl-cmdf "_.ARC" pt1 pt2 pt3)
  (*error* nil)
)
Civil3D 2020

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Mulitple Best Fit Fillet
« Reply #1 on: April 02, 2019, 10:00:06 AM »
Not that I know anything...

looks like you need some from of proximity/maximum radius setting so that it would only fillet lines close
to each other so that it dint attempt to fillet together nearby islands
perhaps even a min/max radius
Be your Best


Michael Farrell
http://primeservicesglobal.com/

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: Mulitple Best Fit Fillet
« Reply #2 on: April 04, 2019, 01:13:17 AM »
If there is two parallel sides and square ends then you know the radius is 1/2 the end length. You can calculate the two tangent points and create an arc trimming the length deleting the middle if its a pline you can trim add and recreate. A four sided would be similar.

If you have non paralell 3 lines its a bit harder need to touch the middle line, basically only one solution, can be solved mathmatically need to find my land surveying book.

For a pline two paralell sides
Code: [Select]
; fillet parallel sided plines
; By Alan H April 2019

(defun do_3sides ( / pt1 pt2 pt3 pt4)
(setq pt1 (nth 0 co-ords))
(setq pt2 (nth 1 co-ords))
(setq pt3 (nth 2 co-ords))
(setq pt4 (nth 3 co-ords))
(setq ang1 (angle pt2 pt1))
(setq ang2 (angle pt3 pt4))
(setq rad (/ (distance pt2 pt3) 2.0))
(setq pt2 (polar pt2 ang1 rad))
(setq pt3 (polar pt3 ang2 rad))
(setq  oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq lay (cdr (assoc 8 (entget ent))))
(setq oldlay (getvar 'clayer))
(setvar 'clayer (cdr (assoc 8 (entget ent))))
(command "erase" ent "")
(command "pLINE" pt1 pt2 "a" "angle" 180 "radius" rad pt3 "L" pt4 "")
)


(defun c:test ( / ss dist radius)
(setq ss (ssget '((0 . "LWPOLYLINE"))))
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (- x 1))))
(if ss  (setq co-ords (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10))  (entget ent)))))
(if (> (length co-ords) 4)(progn (Alert "More than 3 sides\n\nnext version\n\nwill exit")(exit))
(do_3sides)
)
)
(setvar 'osmode  oldsnap)
(setvar 'oldlay oldlay)
(princ)
)
(c:test)
« Last Edit: April 06, 2019, 01:42:28 AM by BIGAL »
A man who never made a mistake never made anything

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Mulitple Best Fit Fillet
« Reply #3 on: April 04, 2019, 07:07:43 AM »
That is really what I was going after! But I am sure that I am not doing this right, I get an error:

Code: [Select]
Command: (LOAD "C:/Users/test/Desktop/Trim Islands.lsp")
Select objects: Specify opposite corner: 6 found
Select objects:
; error: bad argument type: 2D/3D point: nil


I found my error.

For this to work, the polylines need to be connected as one not individual polylines or lines.

Thank you again!!
« Last Edit: April 04, 2019, 09:33:22 AM by MSTG007 »
Civil3D 2020

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: Mulitple Best Fit Fillet
« Reply #4 on: April 05, 2019, 12:12:27 AM »
I should have pointed out needs to be plines to work, I will do the closed pline next another version is to do a nominated radius, will work inside-out so auto works out the changing radius I know we sometimes draw a kerb with 3 lines hence the as many approach. I also realised that a narrow closed pline may give incorrect answer depending on how the pline is drawn using the wrong side.
A man who never made a mistake never made anything

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Mulitple Best Fit Fillet
« Reply #5 on: April 05, 2019, 08:11:12 AM »
Totally understand where your coming from. Thank you again though.
Civil3D 2020

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: Mulitple Best Fit Fillet
« Reply #6 on: April 07, 2019, 02:19:04 AM »
You jump in and then realise Acad has already done it for you, fillet rad Polygon wil put a radius on all sides of a pline so a closed is easy.

Will redo to work out the radius or use a nominated radius on all. Including multiple offsets.

This is not perfect but closer for simple basic shapes.

Code: [Select]
; fillet multi sided plines
; By Alan H April 2019

(defun c:test ( / ss dist rad lst lst2 co-ords x  obj obj2 rads pt1 pt2 pt3 )
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq pt1 (getpoint "\nPick inside point"))
(setq pt2  (getpoint pt1 "\nPick outside point"))
(setq rad (getreal "\nEnter radius -ve for 1/2 2 pts"))

(setq ss (ssget  "F" (list pt2 pt1)'((0 . "LWPOLYLINE"))))
(setq lst '())
(repeat (setq x (sslength ss))
(setq lst (cons (ssname ss (setq x (- x 1))) lst))
)
(setq lst (reverse lst))

(setq obj (vlax-ename->vla-object  (nth 0 lst)))
(setq  pt3  (vlax-curve-getclosestpointto obj pt1))
(command  "line" pt1 (polar pt1 (angle pt1 pt3) (distance pt1 pt2)) "")
(setq obj2 (vlax-ename->vla-object (entlast)))

(setq x -1)
(setq  lst2 '())
(repeat(sslength ss)
(setq obj (vlax-ename->vla-object  (nth (setq x (+ x 1)) lst)))
(setq lst2   (cons (vlax-invoke obj 'intersectWith obj2 acextendnone) lst2))
)

(if (< rad 0)
(progn
(setq rad 10000000)
(setq co-ords'())
(if lst (setq co-ords (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (nth 0 lst))))))
(repeat  (- (setq x (length co-ords))1)
(setq pt1 (nth (setq x (- x 1)) co-ords))
(setq pt2 (nth (- x 1) co-ords))
(setq dist  (/ (distance  pt1 pt2) 2.0))
(if (< dist rad)(setq rad  dist ))
)
)
)
(setq rads '())
(setq rads  (cons rad rads))
(setq x 0)
(repeat  (- (sslength ss)1)
(setq rads  (cons (+ rad (distance (nth 0 lst2)(nth  (setq x(+ x  1))  lst2))) rads))
)
(setq rads (reverse rads))

(repeat  (setq x  (sslength ss))
(setvar 'filletrad  (nth (setq x (- x 1)) rads))
(command "fillet"  "P" (nth   x lst))
)

(vla-delete obj2)
(setvar 'osmode oldsnap)
(princ)
)
(c:test)

« Last Edit: April 08, 2019, 10:53:18 PM by BIGAL »
A man who never made a mistake never made anything

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Mulitple Best Fit Fillet
« Reply #7 on: April 08, 2019, 07:21:56 AM »
Thank you for this. lol there is a lot of clicking inside the polyline (polygon) then outside, which makes sense. Also from the first point to the second. But like you said, It does work ;)
Civil3D 2020

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: Mulitple Best Fit Fillet
« Reply #8 on: April 08, 2019, 06:53:41 PM »
The reason for the two points pick is where you want the radius to be a full 1/2 circle did the simple version 1 solution. The code  allows for a nominated radius which is very common in car park islands. I could add a find smallest side and use that radius but went down the path of one program fits all.

Your welcome to have a go at not using two picks it would involve the 1st code posted using the co-ords and checking the spacing between points. Added to the second code. Happy to help its the only way to learn.
A man who never made a mistake never made anything

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Mulitple Best Fit Fillet
« Reply #9 on: April 08, 2019, 09:45:04 PM »
Now, I get it. I’ll play around with idea and see what I can come up with!
Civil3D 2020

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: Mulitple Best Fit Fillet
« Reply #10 on: April 08, 2019, 10:52:36 PM »
 Look at post above code updated.
A man who never made a mistake never made anything

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Mulitple Best Fit Fillet
« Reply #11 on: April 09, 2019, 12:43:12 PM »
Hey, thank you for updating the code. It works really smoothly. Great job. :2funny:
Civil3D 2020