Jump to content

distance between two points of Polyline (Close / Open)


Recommended Posts

Posted

I find here this lisp

 

http://cadtips.cadalyst.com/distance/determine-distance-between-points-entity

 

(defun c:DBP (/ AT:DrawX AT:CycleThroughSS p1 ent p2 d1 d2 dlst)
 ;; Calculate distance between 2 specified points on curve object
 ;; Alan J. Thompson, 03.20.10 / 03.28.10 / 03.07.11 / 05.09.11

 (vl-load-com)

 (defun AT:DrawX (P C)
   ;; Draw and "X" vector at specified point
   ;; P - Placement point for "X"
   ;; C - Color of "X" (must be integer b/w 1 & 255)
   ;; Alan J. Thompson, 10.31.09
   (if (vl-consp P)
     ((lambda (d)
        (grvecs (cons C
                      (mapcar (function (lambda (n) (polar P (* n pi) d)))
                              '(0.25 1.25 0.75 1.75)
                      )
                )
        )
        P
      )
       (* (getvar 'viewsize) 0.02)
     )
   )
 )

 (defun AT:CycleThroughSS (ss / l i e)
   ;; Cycle through a selection set to choose one
   ;; ss - selection set
   ;; Alan J. Thompson, 03.30.11
   (if (eq (type ss) 'PICKSET)
     (if (eq (setq l (sslength ss)) 1)
       (ssname ss 0)
       (progn (princ "\n<Tab> to cycle through entities: ")
              (redraw (setq e (ssname ss (setq i 0))) 3)
              (while (eq (cadr (grread nil 10)) 9)
                (mapcar 'redraw (list e (setq e (ssname ss (setq i (rem (1+ i) l))))) '(4 3))
              )
              (redraw e 4)
              e
       )
     )
   )
 )

 (redraw)

 (if (and (AT:DrawX (setq p1 (getpoint "\nSpecify first point on curve: ")) 3)
          (or (setq ent (AT:CycleThroughSS
                          (ssget "_C"
                                 (list (car p1) (cadr p1))
                                 (list (car p1) (cadr p1))
                                 '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE"))
                          )
                        )
              )
              (progn (alert "Point must be on curve!") (redraw))
          )
          (progn (redraw ent 3) T)
          (AT:DrawX (setq p2 (getpoint p1 "\nSpecify next point on curve: ")) 3)
          (or (and (ssget "_C"
                          (list (car p2) (cadr p2))
                          (list (car p2) (cadr p2))
                          '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE"))
                   )
                   (setq d1 (vlax-curve-getDistAtPoint ent (trans p1 1 0)))
                   (setq d2 (vlax-curve-getDistAtPoint ent (trans p2 1 0)))
              )
              (progn (alert "Points must be on curve!") (redraw))
          )
     )
   ((lambda (dist / div)
      (while (< dist (- (cadr dlst) (setq div (/ (cadr dlst) 100.))))
        (grdraw (trans (vlax-curve-getPointAtDist ent dist) 0 1)
                (trans (vlax-curve-getPointAtDist ent (setq dist (+ div dist))) 0 1)
                1
        )
      )
      (princ)
      (alert (strcat "Distance between points on curve: " (rtos (abs (- d1 d2)))))
    )
     (car (setq dlst (vl-sort (list d1 d2) (function <))))
   )
 )
 (and ent (redraw ent 4))
 (princ)
)

 

For open polylines works fine.

 

When i have a close polyline give me one direction results. I try to Reverse the polyline but gives me the same results. Can someone convert it

 

 

1) Open or Close polyline [O/C]

 

if it is open is ok

 

2) for Close polyline ask

 

CW or CCW

 

Something like this. Look the attach photos and you will understand

 

Thanks

1.jpg

2.jpg

Posted

I would use plav.lsp to add start-end vetices on polyline and then use plpath.lsp to create new polyline between these 2 points - both options are available [TOP/BOTTOM] - [CW/CCW]... Then I would just get length of new polyline by LIST command, or for more precise use (vl-load-com); (rtos (vla-get-length (vlax-ename->vla-object (car (entsel)))) 2 50) and pick newly created polyline...

 

For pline tools by M.R. (plpath.lsp+plintav.lsp+plav.lsp+pldv.lsp) check this link :

http://www.cadtutor.net/forum/showthread.php?67924-Draw-polyline-along-with-2-or-more-adjacent-closed-polylines/page3&highlight=plpath&p=#25

 

M.R.

Posted

Search for a reverse polyline direction function, I seem to recall seeing one in the past couple of weeks.

Posted
Search for a reverse polyline direction function, I seem to recall seeing one in the past couple of weeks.

Autocad have comand to Reverse direction but the lisp give the same results.Understand a close polyline as open and measure the distanse with direction from the first point to last.

Can anyone fix it ?

Thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...