Jump to content

ROUTINE CUMULATIVE DISTANCES HELP...


leonucadomi

Recommended Posts

hello all:

I found this good routine here,  

 

 

 

(defun c:cd ()
(setvar "cmdecho" 0)
(graphscr)
(setq 
 p1 (getpoint "\nPick start point ")
 p2 (getpoint p1 "\nPick next point ")
 d1 (distance p1 p2)
 prdist (strcat "\nDistance: " (rtos d1 2 0))
)
(princ prdist)
(setq p3 (getpoint p2 "\nPick next point or RETURN if done "))
(while p3
 (setq
  d0 (distance p2 p3)
  d1 (+ (distance p2 p3) d1)
  p2 p3
  prdist (strcat "\nDistance: " (rtos d0 2 0) ", Cumulative distance: " (rtos d1 2 0))
 )
 (princ prdist)
 (setq p3 (getpoint p2 "\nPick Next Point "))
)
(setq cumd (strcat "Cumulative distance --> " (rtos d1 2 0)))
(prompt cumd)
(princ)
)

I hope someone can help

 

thanks

Edited by leonucadomi
Link to comment
Share on other sites

With this modification?

 

(defun c:cd ( / p1 p2 d1 prdist p3 d0 cumd)
  (setvar "cmdecho" 0)
  (graphscr)
  (setq 
    p1 (getpoint "\nPick start point ")
    p2 (getpoint p1 "\nPick next point ")
    d1 (abs (- (car p2) (car p1)))
    prdist (strcat "\nDistance: " (rtos d1 2 0))
  )
  (princ prdist)
  (setq p3 (getpoint p2 "\nPick next point or RETURN if done "))
  (while p3
    (setq
      d0 (abs (- (car p3) (car p2)))
      d1 (+  (abs (- (car p3) (car p2))) d1)
      p2 p3
      prdist (strcat "\nDistance: " (rtos d0 2 0) ", Cumulative distance: " (rtos d1 2 0))
    )
    (princ prdist)
    (setq p3 (getpoint p2 "\nPick Next Point "))
  )
  (setq cumd (strcat "Cumulative distance --> " (rtos d1 2 0)))
  (prompt cumd)
  (princ)
)

 

  • Thanks 1
Link to comment
Share on other sites

Why not

(setq p3 (getpoint p2 "\nPick next point or RETURN if done "))
  (while p3

(while (setq p3 (getpoint p2 "\nPick next point or RETURN if done "))

 

Link to comment
Share on other sites

This is what I use:

(defun c:mdist (/ n p1 p2 d v)
  (setq d 0 n 0)
  (while (and (or p1 (setq p1 (getpoint "\nSpecify start point: ")))
	      (setq p2 (getpoint p1 "\nSpecify next point: "))
	 )
    (setq d  (+ d (distance p1 p2))
	  v  (append v (list (setq n (1+ n)) p1 p2))
	  p1 p2
    )
    (grvecs v)
    (princ (strcat "\nRunning total is " (rtos d)))
  )
)

 

Edited by ronjonp
  • Thanks 1
Link to comment
Share on other sites

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...