id pline, 2 adjoining segments and vertices

Discussion in 'AutoCAD' started by spykat, Jan 8, 2005.

  1. spykat

    spykat Guest

    I need a little help with this one because I don't have the time to do it my self.

    I need to be able to pick a segment of a lwpolyline and get the end points of that segment and the end points of the first segment on each side of the first segment. Thank for any help you can give me.
     
    spykat, Jan 8, 2005
    #1
  2. spykat

    Jeff Mishler Guest

    Here's a little function that returns a 4 element list. If the selected
    object is not a LWPLINE then all 4 wil be nil. If the first segment is
    selected, the first item will be nil. If the selected segment is also the
    last segemnt, then the 4th item will be nil. The endpoints of the selected
    segment will be the 2nd & 3rd items.

    (defun get_segment_ends (/ end1 end2 end3 end4 ent obj paramend parampt pt1)
    (and (setq ent (entsel "\nSelect polyline: "))
    (eq "LWPOLYLINE" (cdr (assoc 0 (entget (car ent)))))
    (setq obj (vlax-ename->vla-object (car ent)))
    (setq pt1 (vlax-curve-getclosestpointto obj (cadr ent)))
    (setq parampt (fix (vlax-curve-getparamatpoint obj pt1)))
    (setq paramend (fix (vlax-curve-getendparam obj)))
    (if (> parampt 0)
    (setq end1 (vlax-curve-getpointatparam obj (1- parampt)))
    t
    )
    (setq end2 (vlax-curve-getpointatparam obj parampt)
    end3 (vlax-curve-getpointatparam obj (1+ parampt))
    )
    (if (< (1+ parampt) paramend)
    (setq end4 (vlax-curve-getpointatparam obj (+ 2 parampt)))
    t
    )
    )
    (list end1 end2 end3 end4)
    )
     
    Jeff Mishler, Jan 9, 2005
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.