Author Topic: changing end points of polyline to the specified point  (Read 6210 times)

0 Members and 1 Guest are viewing this topic.

subbup

  • Guest
changing end points of polyline to the specified point
« on: July 06, 2004, 06:34:13 AM »
hello all,

I am going to give the following data.
entity name(polyline)
ins(it may be start point or endpoint of polyline)
tp(target point)

We have to modify the polyline with the target point.
means if user supplies startpoint the new startpoint for the polyline will be the point supplied by user (tp). for endpoint also same.

Any ideas to do this

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
changing end points of polyline to the specified point
« Reply #1 on: July 06, 2004, 08:28:21 AM »
Not exactly sure what you are asking for?
This code reverses the direction of the LWpoly line and keeps the same starting point.
Most routines I saw use the end point as the new starting point.
If this is not what you are looking for , please be more specific.

Are you drawing a new polylines?
Are you splitting an existing pline?
...Is the pline closed?
...If not closed are you creating two new plines?
Is the pline old style or light weight pline?

Code: [Select]
;;;           Polyline Reverse        
;;;      lwr.lsp by Charles Alan Butler
;;;            Copyright 2004          
;;;  by Precision Drafting & Design All Rights Reserved.
;;;  Contact at ab2draft@TampaBay.rr.com
;;;
;;;   Version Alpha  March 20,2004
;;;
;;;   Reverse the vertex order of a light weight polyline
;;;   Keeps the same starting point unlike most reverse routines
;;;
;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;                                                                    ;
;;;  You are hereby granted permission to use, copy and modify this    ;
;;;  software without charge, provided you do so exclusively for       ;
;;;  your own use or for use by others in your organization in the     ;
;;;  performance of their normal duties, and provided further that     ;
;;;  the above copyright notice appears in all copies and both that    ;
;;;  copyright notice and the limited warranty and restricted rights   ;
;;;  notice below appear in all supporting documentation.              ;
;;;
(defun c:plr (/ elst vlst newlst new-vlst code42 code210
              obj nam pair )
  (command "_.undo" "_be")
  (while (null (setq en1 (entsel "\nPick an object to reverse: "))))
  (setq nam  (car en1) elst (entget nam) obj  (cdr (assoc 0 elst)))
  (cond
    ((= obj "LWPOLYLINE")
     (setq new-vlst (list (assoc 10 elst))) ; start point
     (while (setq pair (car elst))
       (cond
         ((= (car pair) 10) ; vertex
          (while (member (caar elst) '(10 40 41 42))
            (setq vlst (cons (car elst) vlst) elst (cdr elst))))
         ((= (car pair) 210) ; extru direction??
          (setq code210 pair elst (cdr elst)))
         ((setq newlst (cons pair newlst) elst (cdr elst)))))
     (while vlst
       (if (= (car (setq pair (car vlst))) 42) ; bulge
         (setq code42 (cons 42 (* (cdr pair) -1)) vlst (cdr vlst)))
       (if (= (car (setq pair (car vlst))) 41)
         (setq vlst     (cdr vlst)
               new-vlst (cons (cons 40 (cdr pair)) new-vlst)
               new-vlst (cons (cons 41 (cdr (car vlst))) new-vlst)
               vlst     (cdr vlst)))
       (if code42 ; add bulge back to list
         (setq new-vlst (cons code42 new-vlst) code42 nil))
       (if (= (car (setq pair (car vlst))) 10)
         (setq new-vlst (cons pair new-vlst) vlst (cdr vlst))))
     (setq new-vlst (cdr new-vlst)) ; remove the start pt
     (setq newlst (append new-vlst newlst))
     (if code210  (setq newlst (append (list code210) newlst)))
     (entmod (reverse newlst))
     (entupd nam) ; Regenerates the polyline entity
    )

    ((= obj "POLYLINE")
     (prompt "\nNot yet working... Old Style Polyline."))
    ((prompt "\nObject selected is not a polyline"))) ; end cond stmt
  (princ)
) ; end defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

subbup

  • Guest
changing end points of polyline to the specified point
« Reply #2 on: July 06, 2004, 09:07:21 AM »
simply I can tell that
I want to stretch the specified point (start or endpoint) of polyline to the user specified point.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
changing end points of polyline to the specified point
« Reply #3 on: July 06, 2004, 10:00:08 AM »
So as I understand it you want to do the following:

User picks a pline.
Error if it is a closed pline.
Find the closest end of the pline
Stretch that point to a new point picked by the user

I don't have time today to write any code so perhaps
someone else can help you with that.

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
changing end points of polyline to the specified point
« Reply #4 on: July 06, 2004, 10:35:07 AM »
Ok, here is a quickie, no real error checking.
If you get too close to the next vertex it will grab it
instead of the END of the pline.


Code: [Select]
;;  Polyline Stretch
(defun c:pls( / pt cp1 cp2)
  (if (and (setq ent (entsel "\nSelect point on polyline: "))
           (= (cdr(assoc 0 (entget(car ent)))) "LWPOLYLINE"))
           
    (progn
      (setq pt (getNearestVertex ent))
      (setq cp1 (polar pt 0.78 5))
      (setq cp2 (polar pt 3.9 5))
      (command "._stretch" "_box" cp1 cp2 "" "_end" pt pause)
    ); progn
    (prompt "\nObject is not a Polyline.")
  ) ; endif
  (princ)
); defun


;;  John Uhden - improved version
;;  Modified by CAB for this use
(defun getNearestVertex (ent / pnt vobj param NearestVertex)
  (and
    ;;(setq ent (entsel "\nSelect point on polyline: "))
    (setq pnt (cadr ent))
    (setq pnt (trans pnt 1 0))
    (setq vobj (vlax-ename->vla-object (car ent)))
    (setq pnt (vlax-curve-getClosestPointTo vobj pnt))
    (setq param (vlax-curve-getParamAtPoint vobj pnt))
    (setq param (float (fix (+ 0.5 param))))
    (cond
      ((equal param (vlax-curve-getStartParam vobj) 1e-10)
        (setq NearestVertex (vlax-curve-getStartPoint vobj))
      )
      ((equal param (vlax-curve-getEndParam vobj) 1e-10)
        (setq NearestVertex (vlax-curve-getEndPoint vobj))
      )
      (T (setq NearestVertex (vlax-curve-getPointAtParam vobj param)))
    )
  )
  (cond
    ((not ent)(prompt "\nYou missed."))
    ((not pnt)(prompt "\nCouldn't find point on object."))
    ((not param)(prompt "\nCouldn't find Param at point."))
    ((not NearestVertex)(prompt "\nPointAtParam failed."))
    (T (trans NearestVertex 0 1))
  )
)


Edited:   Had to add some error checking :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: changing end points of polyline to the specified point
« Reply #5 on: July 06, 2004, 06:43:08 PM »
Quote from: subbup

Any ideas to do this


Here's a small routine that does this. You add to it to make it "smarter" and give it some error handling, but at least this should move you in the right direction.

Code: [Select]

(defun c:p-move (/ ans coords newcoords newpt obj oldpt ss)
  (while (setq ss (ssget ":S" '((0 . "*POLYLINE")(-4 . "<NOT")(-4 . "&")(70 . 1)(-4 . "NOT>"))))    
    (initget "Start End")
    (setq ans (getkword "\nMove the Start or End point? [Start/End]"))
    (if (not ans) (setq ans "Start"))
    (setq obj (vlax-ename->vla-object (ssname ss 0)))
    (setq coords (vlax-get obj "coordinates"))
    (if (= ans "Start")
      (progn
(setq oldPt (list (car coords) (cadr coords) 0.0))
(setq newPt (getpoint oldPt "\nNew startpoint location: "))
(setq newcoords (append (list (car newPt)(cadr newPt))(cdr (cdr coords))))
)
      (progn
(setq oldPt (list (cadr (reverse coords)) (car (reverse coords)) 0.0))
(setq newPt (getpoint oldPt "\nNew endpoint location: "))
(setq coords (reverse coords))
(setq newcoords (append (reverse (cdr (cdr coords))) (list (car newPt)(cadr newPt))))
)
      )
    (vlax-put obj "coordinates" newcoords)
    )
  )

Anonymous

  • Guest
changing end points of polyline to the specified point
« Reply #6 on: July 07, 2004, 01:37:52 AM »
Thanks for both of you CAB and Jeff Mishler
 :D