Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Mentor
richie.hodgson
Posts: 223
Registered: ‎11-05-2008
Message 1 of 5 (573 Views)

Need to reduce a poliline with multiple vertices to a single polyline

573 Views, 4 Replies
06-07-2012 02:16 PM

Hi

 

I would like to take all the vertices out of a multiple-vertices polyline so that it reduces to just its start and end points, can this be done?

Richie
Distinguished Mentor
_Tharwat
Posts: 642
Registered: ‎07-02-2010
Message 2 of 5 (572 Views)

Re: Need to reduce a poliline with multiple vertices to a single polyline

06-07-2012 02:47 PM in reply to: richie.hodgson

This..... ?

 

(defun c:Test (/ ss i sn l p)
  (if (setq ss (ssget "_:L" '((0 . "*POLYLINE"))))
    (repeat (setq i (sslength ss))
      (setq sn (ssname ss (setq i (1- i))))
      (setq
        l (vl-remove-if-not
            (function
              (lambda (x) (member (car x) '(0 100 8 70 90 410 210)))
            )
            (entget sn)
          )
      )
      (setq p (vl-remove-if-not
                (function (lambda (x) (eq (car x) 10)))
                (entget sn)
              )
      )
      (entmakex (append l (list (car p) (last p))))
      (entdel sn)
    )
  )
  (princ)
)

 

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Mentor
richie.hodgson
Posts: 223
Registered: ‎11-05-2008
Message 3 of 5 (568 Views)

Re: Need to reduce a poliline with multiple vertices to a single polyline

06-07-2012 02:51 PM in reply to: richie.hodgson

Perfect thanks

Richie
Distinguished Mentor
_Tharwat
Posts: 642
Registered: ‎07-02-2010
Message 4 of 5 (566 Views)

Re: Need to reduce a poliline with multiple vertices to a single polyline

06-07-2012 02:53 PM in reply to: richie.hodgson

richie.hodgson wrote:

Perfect thanks



You're welcome .

____________________________________________________
Get learn and learn and practice , to become experienced guy .
*Expert Elite*
Kent1Cooper
Posts: 5,872
Registered: ‎09-13-2004
Message 5 of 5 (551 Views)

Re: Need to reduce a poliline with multiple vertices to a single polyline

06-07-2012 06:59 PM in reply to: richie.hodgson

richie.hodgson wrote:

.... 

I would like to take all the vertices out of a multiple-vertices polyline so that it reduces to just its start and end points, ....


Another way, straightening the Polyline from start to end, if 'ename' is the entity name of the Polyline:

 

(command "_.pedit" ename "_e" "_s")
(repeat (1- (cdr (assoc 90 (entget ename))))
  (command "")
); repeat
(command "_g" "_x" "")

 

And another, that depends on the fact that if not given 40/41/42 values for widths and bulge after vertex locations, it will assume zero for all of them:

 

(setq edata (entget ename))
(entmake
  (append
    (vl-remove-if '(lambda (x) (member (car x) '(10 40 41 42))) edata); all except vertices/widths/bulges
    (list (assoc 10 edata)); first vertex
    (list (assoc 10 (reverse edata))); last vertex
  )
)
(entdel ename)

 

And another:

 

(command
  "_.pline"
  (vlax-curve-getStartPoint ename)
  (vlax-curve-getEndPoint ename)
  ""
  "_.matchprop" ename "_last" ""
  "_.erase" ename ""
)

Kent Cooper
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.