Author Topic: Remove Chamfers from Polylines  (Read 1085 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Remove Chamfers from Polylines
« on: March 31, 2022, 05:46:32 PM »
I honestly am not sure where to start on this one, let's say I have a polyline with chamfers, I want to remove the chamfers, essentially restoring the polyline to what it was before using the chamfer command. I have thought about simply saving extended data to the entity of what the original vertexes were, but the problem with that approach would be if the polyline has been modified after adding the chamfers, then you would also loose those edits.

I am thinking I would have to specify a maximum chamfer size to remove, but beyond that, I am at a loss.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2149
  • class keyThumper<T>:ILazy<T>
Re: Remove Chamfers from Polylines
« Reply #1 on: March 31, 2022, 08:54:11 PM »
Perhaps ( unless you have hundreds )

CHAMFER command
set trim mode to TRIM
set distance to 0, 0

select 2 segments to join.
. . . The segments join at their imaginary inter' and the chamfer is removed.

//---
Or use the FILLET command with TRIM mode and no radius , selecting the segments.

// -- even if you have multiple segments, this will still be pretty fast.
« Last Edit: March 31, 2022, 08:57:41 PM by kdub »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Remove Chamfers from Polylines
« Reply #2 on: April 01, 2022, 11:48:25 AM »
Ok, let me reword this, I want to select multiple polylines that may have hundreds of chamfers all at once and have it remove the chamfers automatically. Similar to what it would do with the fillet command and setting a radius of 0 and doing fillet polyline. I have made a routine that handles the fillets.

mhupp

  • Bull Frog
  • Posts: 250
Re: Remove Chamfers from Polylines
« Reply #3 on: April 01, 2022, 12:55:30 PM »
assumes your chamfers are the smallest segments in the polyline.

Code - Auto/Visual Lisp: [Select]
  1. ;;----------------------------------------------------------------------------;;
  2. ;; REMOVE CHAMFERS
  3. (defun C:foo (/ SS SS1 d objs fo)
  4.   (setq SS1 (ssadd))
  5.   (setq d (getdist (strcat "\nChamfer Distance: ")))
  6.   (if (setq SS (ssget '((0 . "*POLYLINE") (70 . 1))))
  7.     (progn
  8.       (setq LastEnt (entlast))
  9.       (foreach poly (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
  10.         (setq objs (vlax-invoke (vlax-ename->vla-object poly) 'explode)
  11.               fo (vlax-vla-object->ename (car objs))
  12.         )
  13.         (entdel poly)
  14.         (foreach line objs
  15.           (if (and (eq (vla-get-entityname line) "AcDbLine") (<= (vlax-get line 'Length) d))
  16.             (progn
  17.               (vla-delete line)
  18.               (setq objs (vl-remove line objs))
  19.             )
  20.           )
  21.         )
  22.         (setvar 'filletrad 0)
  23.         (while (> (length objs) 1)
  24.           (setq leg1 (vlax-vla-object->ename (car objs)))
  25.           (setq leg2 (vlax-vla-object->ename (cadr objs)))
  26.           (vl-cmdf "_.fillet" leg1 leg2)
  27.           (setq objs (cdr objs))
  28.         )
  29.         (vl-cmdf "_.fillet" leg2 fo)
  30.       )
  31.     )
  32.   )
  33.   (if (setq en (entnext LastEnt))
  34.     (while en
  35.       (ssadd en SS1)
  36.       (setq en (entnext en))
  37.     )
  38.   )
  39.   (vl-cmdf "_.Join" SS1 "")
  40.   (princ)
  41. )
« Last Edit: April 01, 2022, 12:58:34 PM by mhupp »

ribarm

  • Gator
  • Posts: 3306
  • Marko Ribar, architect
Re: Remove Chamfers from Polylines
« Reply #4 on: April 01, 2022, 02:53:05 PM »
Code - Auto/Visual Lisp: [Select]
  1. ;;-------------------------------------------------------------------------------------;;
  2. ;; REMOVE CHAMFERS - Dedicated topic : http://www.theswamp.org/index.php?topic=57476.0 ;;
  3. ;;-------------------------------------------------------------------------------------;;
  4. ;; Orginal routine by : @mhupp ; Mod. by : @ribarm ; DATE : 01.April.2022.             ;;
  5. ;;-------------------------------------------------------------------------------------;;
  6.  
  7. (defun C:rem_chamfers ( / *error* fillrad cmde d SS polys LastEnt objs fo leg1 leg2 SS1 en )
  8.  
  9.  
  10.   (defun *error* ( m )
  11.     (if command-s (command-s "_.UNDO" "_E") (vl-cmdf "_.UNDO" "_E"))
  12.     (if cmde (setvar 'cmdecho cmde))
  13.     (if fillrad (setvar 'filletrad fillrad))
  14.     (if m (prompt m))
  15.     (princ)
  16.   )
  17.  
  18.   (setq fillrad (getvar 'filletrad))
  19.   (setvar 'filletrad 0)
  20.   (setq cmde (getvar 'cmdecho))
  21.   (setvar 'cmdecho 0)
  22.   (if (= 8 (logand 8 (getvar 'undoctl)))
  23.     (vl-cmdf "_.UNDO" "_E")
  24.   )
  25.   (vl-cmdf "_.UNDO" "_G")
  26.   (if
  27.     (and
  28.       (not (initget 6))
  29.       (setq d (getdist "\nChamfer Distance : "))
  30.       (if (setq SS (ssget "_:L" '((0 . "*POLYLINE")))) ;; this is different - added "_:L" to (ssget) and removed (70 . 1) from filtering ;;
  31.         (setq polys
  32.           (vl-remove-if-not
  33.             (function
  34.               (lambda ( pol / endpar pars )
  35.                 (setq endpar (vlax-curve-getendparam pol))
  36.                 (<
  37.                   1
  38.                   (length
  39.                     (vl-remove nil
  40.                       (mapcar
  41.                         (function
  42.                           (lambda ( par )
  43.                             (equal
  44.                               (distance (vlax-curve-getpointatparam pol par) (vlax-curve-getpointatparam pol (1- par)))
  45.                               (- (vlax-curve-getdistatparam pol par) (vlax-curve-getdistatparam pol (1- par)))
  46.                               1e-6 ;; fuzz - mod. to suit (tolerance for checking of existance of straight segment in reference checking polyline - pol) ;;
  47.                             )
  48.                           )
  49.                         )
  50.                         (repeat (1- (setq endpar (1+ (fix endpar)))
  51.                           (setq pars (append pars (list (setq endpar (1- endpar)))))
  52.                         )
  53.                       )
  54.                     )
  55.                   )
  56.                 ) ;; there were more than 1 straight segment detected in reference checking polyline - pol ;;
  57.               )
  58.             )
  59.             (vl-remove-if (function listp)
  60.               (mapcar (function cadr)
  61.                 (ssnamex SS)
  62.               )
  63.             )
  64.           )
  65.         )
  66.       )
  67.     )
  68.     (foreach poly polys
  69.       (setq LastEnt (entlast))
  70.       (setq objs (vlax-invoke (vlax-ename->vla-object poly) 'explode)
  71.             fo (vlax-vla-object->ename (car objs))
  72.       )
  73.       (entdel poly)
  74.       (foreach seg objs
  75.         (cond
  76.           ( (and (= (vla-get-entityname seg) "AcDbLine") (<= (vlax-get seg 'Length) d))
  77.             (vla-delete seg)
  78.             (setq objs (vl-remove seg objs))
  79.           )
  80.           ( (= (vla-get-entityname seg) "AcDbArc") ;; this is different - removing possible ARC occurences (not all segments are straight) ;;
  81.             (vla-delete seg)
  82.             (setq objs (vl-remove seg objs))
  83.           )
  84.         )
  85.       )
  86.       (while (> (length objs) 1)
  87.         (setq leg1 (vlax-vla-object->ename (car objs)))
  88.         (setq leg2 (vlax-vla-object->ename (cadr objs)))
  89.         (vl-cmdf "_.FILLET" leg1 leg2)
  90.         (setq objs (cdr objs))
  91.       )
  92.       (vl-cmdf "_.FILLET" leg2 fo)
  93.       (setq SS1 (ssadd))
  94.       (if (setq en (entnext LastEnt))
  95.         (while en
  96.           (ssadd en SS1)
  97.           (setq en (entnext en))
  98.         )
  99.       )
  100.       (initcommandversion) ;; perhaps this should be included - JOIN command is known for some poor operational processing ;;
  101.       (vl-cmdf "_.JOIN" SS1 "")
  102.     )
  103.   )
  104.   (*error* nil)
  105. )
  106.  

HTH. M.R.
« Last Edit: April 02, 2022, 01:52:23 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

BIGAL

  • Swamp Rat
  • Posts: 1429
  • 40 + years of using Autocad
Re: Remove Chamfers from Polylines
« Reply #5 on: April 01, 2022, 07:48:31 PM »
I notice in both the code posted "explode" creeping in and not sure why if you have a pline with a short length then can find that segment so fillet segment-1 and segment+1, I do appreciate that Ribarm has taken into consideration that the segment may be an arc so would need to skip.

Will have a think about it. Can not do right now.
A man who never made a mistake never made anything