Jump to content

Lisp to calculate distances between each two consecutive points after selecting a set of points.


Recommended Posts

Posted (edited)

Hello,

 

I have a set of about 5400 points that are created consecutively. I am looking for a lisp that i select all those points and it gives me the distance between each consecutive two points. 

 

I have this lisp but I have to select each pair, which will take a lot of time. So, any help would be really appreciated.

 

;SHOW LEVEL DIFFERENT BETWEEN TWO POINTS
(defun c:LVDIF()
  (setq pt1 (getpoint"\nPick First Point"));SELECT FIRST POINT
  (setq pt2 (getpoint"\nPick Second Point"));SELECT SECOND POINT
  (setq dis (distance pt1 pt2));DISTANCE BETWEEN TOW POINTS
  (setq ang (angle pt1 pt2));ANGLE BETWEEN TWO POINTS
  (setq mid (polar pt1 ang (/ dis 2)));POINT BETWEEN SELLECTED TWO POINTS
  (setq vpt1 (nth 2 pt1));LEVEL OF FIRST POINT
  (setq vpt2 (nth 2 pt2));LEVEL OF SECOMD POINT
  (setq vdif (- vpt1 vpt2));LEVEL DIFFERENT
   (if (< vdif 0);CHANGE SIGN IF IT NIGATIVE VALUE
    (setq vdif (* vdif -1)))
   (if (> vdif 0.5);CHANGE COLOR OF LEVEL DIFFERENT TO RED IN CASE MORETHAN LIMIT 
    (command "color" "T" "255,0,0")
    (command "-color" "bylayer")) 
  (command "text" "J" "MC" mid 2.5 0 (strcat "DIF="(rtos vdif 2 2)));WRITE TEXT BETWEEN SELLECTED POINTS
  
);end

 

Edited by SLW210
Added Code Tags!
Posted

Please use Code Tags! (use the <> in the editor).

Posted

when you say consecutive points, are you looking for them in consecutive order of creation or as drawn on the sheet, distance between the point and it's closest neighbour?

 

First option is trickier, 2nd option is easier. For the 2nd option is there a maximum distance between consecutive points, my thinking here is that to find the closest point you will need to asses other points to work it out, if you can limit the distance you are searching over you might only need the LISP to consider 10 points rather than 5400... which will make it quicker,.

 

To give the result, are you wanting a list or perhaps a dimension drawn between the 2 points?

Posted

It seems like our new friend forgot to answer...

Anyway, if the previous routine works as expected, I kept it as much as possible and I feed it with point pars. Not sure if that's what the OP needs... :(

(defun c:LVDIF()
  (setq points (ssget '((0 . "POINT"))))
  (repeat (setq i (1- (sslength points)))
    (lvdif1 (cdr (assoc 10 (entget (ssname points i)))) (cdr (assoc 10 (entget (ssname points (setq i (1- i)))))))
    )
  )
;SHOW LEVEL DIFFERENT BETWEEN TWO POINTS
(defun LVDIF1(pt1 pt2)
  ;(setq pt1 (getpoint"\nPick First Point"));SELECT FIRST POINT
  ;(setq pt2 (getpoint"\nPick Second Point"));SELECT SECOND POINT
  (setq dis (distance pt1 pt2));DISTANCE BETWEEN TOW POINTS
  (setq ang (angle pt1 pt2));ANGLE BETWEEN TWO POINTS
  (setq mid (polar pt1 ang (/ dis 2)));POINT BETWEEN SELLECTED TWO POINTS
  (setq vpt1 (nth 2 pt1));LEVEL OF FIRST POINT
  (setq vpt2 (nth 2 pt2));LEVEL OF SECOMD POINT
  (setq vdif (- vpt1 vpt2));LEVEL DIFFERENT
   (if (< vdif 0);CHANGE SIGN IF IT NIGATIVE VALUE
    (setq vdif (* vdif -1)))
   (if (> vdif 0.5);CHANGE COLOR OF LEVEL DIFFERENT TO RED IN CASE MORETHAN LIMIT 
    (command "color" "T" "255,0,0")
    (command "-color" "bylayer")) 
  (command "text" "J" "MC" mid 2.5 0 (strcat "DIF="(rtos vdif 2 2)));WRITE TEXT BETWEEN SELLECTED POINTS
  
);end

 

Posted (edited)
On 1/22/2024 at 3:22 PM, Steven P said:

when you say consecutive points, are you looking for them in consecutive order of creation or as drawn on the sheet, distance between the point and it's closest neighbour?

 

First option is trickier, 2nd option is easier. For the 2nd option is there a maximum distance between consecutive points, my thinking here is that to find the closest point you will need to asses other points to work it out, if you can limit the distance you are searching over you might only need the LISP to consider 10 points rather than 5400... which will make it quicker,.

 

To give the result, are you wanting a list or perhaps a dimension drawn between the 2 points?

Thank you for your reply. Actually, it is the first option where all the points were created in consecutive order. To clarify, I need the lisp to run in a loop to write the distance between each pair: 1&2, 3&4, 5&6 and so on.

Edited by Ali K
Posted
On 1/23/2024 at 3:22 PM, fuccaro said:

It seems like our new friend forgot to answer...

Anyway, if the previous routine works as expected, I kept it as much as possible and I feed it with point pars. Not sure if that's what the OP needs... :(

(defun c:LVDIF()
  (setq points (ssget '((0 . "POINT"))))
  (repeat (setq i (1- (sslength points)))
    (lvdif1 (cdr (assoc 10 (entget (ssname points i)))) (cdr (assoc 10 (entget (ssname points (setq i (1- i)))))))
    )
  )
;SHOW LEVEL DIFFERENT BETWEEN TWO POINTS
(defun LVDIF1(pt1 pt2)
  ;(setq pt1 (getpoint"\nPick First Point"));SELECT FIRST POINT
  ;(setq pt2 (getpoint"\nPick Second Point"));SELECT SECOND POINT
  (setq dis (distance pt1 pt2));DISTANCE BETWEEN TOW POINTS
  (setq ang (angle pt1 pt2));ANGLE BETWEEN TWO POINTS
  (setq mid (polar pt1 ang (/ dis 2)));POINT BETWEEN SELLECTED TWO POINTS
  (setq vpt1 (nth 2 pt1));LEVEL OF FIRST POINT
  (setq vpt2 (nth 2 pt2));LEVEL OF SECOMD POINT
  (setq vdif (- vpt1 vpt2));LEVEL DIFFERENT
   (if (< vdif 0);CHANGE SIGN IF IT NIGATIVE VALUE
    (setq vdif (* vdif -1)))
   (if (> vdif 0.5);CHANGE COLOR OF LEVEL DIFFERENT TO RED IN CASE MORETHAN LIMIT 
    (command "color" "T" "255,0,0")
    (command "-color" "bylayer")) 
  (command "text" "J" "MC" mid 2.5 0 (strcat "DIF="(rtos vdif 2 2)));WRITE TEXT BETWEEN SELLECTED POINTS
  
);end

 

Thank you so much for your reply and editing the lisp. However, when I run it, it doesn't accept to select the COGO points as shown in the picture below. image.png.a9c7d9358439eebcf6a6aacd6f7c9f90.png

Posted

You are right, that program will process plain "point" entities only :(

Posted
37 minutes ago, fuccaro said:

You are right, that program will process plain "point" entities only :(

I fixed the lisp to select cogo points, but the issue is the missing repeat or loop function to process the difference between each pair.

Posted

For CIV3D COGO points need to look at property "Location"

 

(setq obj (vlax-ename->vla-object  (car (entsel))))
(setq pt1 (vlax-safearray->list (vlax-variant-value (vlax-get-property obj "Location"))))

 

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