Author Topic: Erase segments from polyline  (Read 15265 times)

0 Members and 1 Guest are viewing this topic.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Erase segments from polyline
« Reply #15 on: October 18, 2012, 09:42:32 AM »
Great thanks for your time and explantion - it´s clear now "why"

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Erase segments from polyline
« Reply #16 on: October 18, 2012, 09:46:29 AM »
Great thanks for your time and explantion - it´s clear now "why"

Excellent, you're welcome.  :-)

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Erase segments from polyline
« Reply #17 on: November 02, 2012, 01:39:30 PM »
Completly another trick to erase segments in a Polyline is to press CTRL and than click on the segment

Regards Dirk

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Erase segments from polyline
« Reply #18 on: November 02, 2012, 04:00:28 PM »
Completly another trick to erase segments in a Polyline is to press CTRL and than click on the segment

This doesn't appear to work in 2010  :?

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Erase segments from polyline
« Reply #19 on: November 02, 2012, 05:37:03 PM »
Works in 2013  8-)  Pretty cool.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Roger W

  • Guest
Re: Erase segments from polyline
« Reply #20 on: October 16, 2013, 08:00:01 AM »
Thanks a million this works perfectly for all types of polylines.

Is it a bug i vl-function that I don´t get right segment

Its not a bug with the vlax-curve-* functions, try the following instead:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:delsegbreak ( / l p )
  2.     (if
  3.         (and
  4.             (setq l (entsel "\nSelect Polyline: "))
  5.             (wcmatch (cdr (assoc 0 (entget (car l)))) "*POLYLINE")
  6.         )
  7.         (progn
  8.             (setq p
  9.                 (fix
  10.                     (vlax-curve-getparamatpoint (car l)
  11.                         (vlax-curve-getclosestpointtoprojection
  12.                             (car l)
  13.                             (trans (cadr l) 1 0)
  14.                            '(0.0 0.0 1.0)
  15.                         )
  16.                     )
  17.                 )
  18.             )
  19.             (command "_.break" l "_F"
  20.                 "_non" (trans (vlax-curve-getpointatparam (car l)     p ) 0 1)
  21.                 "_non" (trans (vlax-curve-getpointatparam (car l) (1+ p)) 0 1)
  22.             )
  23.         )
  24.     )
  25.     (princ)
  26. )

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Erase segments from polyline
« Reply #21 on: October 16, 2013, 08:22:25 AM »
Thanks a million this works perfectly for all types of polylines.

You're most welcome Roger!  :-)

Bhull1985

  • Guest
Re: Erase segments from polyline
« Reply #22 on: October 21, 2013, 07:50:42 AM »
A few months ago I attempted to tackle some of this type of code, through no small assistance of the others in this forum namely hmsilva lee mac and a few others over at the autodesk forums. After much testing and deliberation this is the portion of code we've decided on and have used successfully since then:

Code: [Select]
(if (setq insertpt1 (getpoint "\nPick Insertion Point: "))
(progn
  (if (and (setq ntsel (nentselp insertpt1))
   (= (length ntsel) 2)
   (setq name (car ntsel))
   (wcmatch (cdr (assoc 0 (entget name)))"LINE,LWPOLYLINE")
   );; and

Additionally, and this may or may not be useful for the OP but I want to show how the (vlax-curve-getpointatparam) function was used in addition to the break command. I am not sure if this has already been looked at , or would not work- just wanted to share in case it may be found to be useful.

Code: [Select]
(if (eq (vla-get-ObjectName obj) "AcDbPolyline")
     (setq p3 insertpt1
   p2 (angle insertpt1  (vlax-curve-getpointatparam obj  (fix (vlax-curve-getparamatpoint obj insertpt1)))))
     (setq p3 insertpt1
      p2 (angle (vlax-curve-getStartpoint obj) (vlax-curve-getEndPoint obj)))
)
(command "break" name (polar p3 p2 a2) (polar p3 p2 a3))



The reasons that the portions of code are the way they are is because of the conditions in which we require the program to work properly. If one user wishes to insert their fittings onto blank space before connecting them together in-line, they can. At the same time if another user wishes to draw a routing line and place all of their fittings onto that line, then the prog will do so. It will then trim out any lines that remain under the fittings. Speaking of lines, most of the time we use lwpolylines but wanted to ensure this code would work for any typical condition that we may use: lwpolylines, lines, blank space.
Hope that helps a little if you were still looking for a method....as I did not see the functions being used here explained by Lee i'm wondering where they'd fit in with his get-closest-point-to diagram..... :)

skkkk

  • Guest
Re: Erase segments from polyline
« Reply #23 on: August 21, 2014, 09:42:06 AM »
This is another variant (based on Lee Mac's code). I've added: cycle with cancelling by Enter, handling misses, undo by step, prompts.
Code: [Select]
(defun c:DELSEGS ( / *error* en flag p)
(vl-load-com)
(defun *error* (msg)   
(if oldCMDECHO (setvar "CMDECHO" oldCMDECHO))
(princ msg)
(princ)
) ;defun *error*
(setq en T flag 0 oldCMDECHO (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(while en
(initget "u")
(setq en (entsel "\nSelect segment <complete>: "))
(cond
  ( (= en "u")
(if (> flag 0)
(progn
(vl-cmdf "_u")
(princ "1 segment were recovered")
(setq flag (1- flag) en T)
)
(princ "All removed segments was recovered.")
)
  )
  ( (and (null en) (= (getvar "ERRNO") 7))
(setq en T)
  )
  ( (null en)
(princ (strcat "\nFunction is completed. "
(if (> flag 0) (strcat "Segments removed: " (vl-princ-to-string flag)) "")
)
)
  )
  ( (not (wcmatch (cdr (assoc 0 (entget (car en)))) "*POLYLINE"))
(princ "\nIt's not a polyline.")
(setq en T)
  )
  ( t
(setq p
(fix
(vlax-curve-getParamAtPoint (car en)
(vlax-curve-getClosestPointToProjection
(car en)
(trans (cadr en) 1 0)
'(0.0 0.0 1.0)
)
)
)
)
(command "_.break" en "_F"
"_non" (trans (vlax-curve-getPointAtParam (car en)     p ) 0 1)
"_non" (trans (vlax-curve-getPointAtParam (car en) (1+ p)) 0 1)
)
(setq flag (1+ flag))
  )
)
)
(setvar "CMDECHO" oldCMDECHO)
(princ)
)
« Last Edit: August 21, 2014, 04:39:29 PM by skkkk »