Jump to content

Line connecting two points


aloy

Recommended Posts

Hi everyone,

What is the simplest way to find whether two points are connected in a drawing using Alisp.

Thanking in advance.

Aloy

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • MSasu

    5

  • anaskattayil

    5

  • Lee Mac

    3

  • aloy

    3

Top Posters In This Topic

Perhaps:

(defun connected-p ( p1 p2 )
   (and
       (ssget "_X"
           (list
              '(0 . "LINE")
              '(-4 . "<OR")
                  '(-4 . "<AND")
                       (cons 10 p1)
                       (cons 11 p2)
                  '(-4 . "AND>")
                  '(-4 . "<AND")
                       (cons 10 p2)
                       (cons 11 p1)
                  '(-4 . "AND>")
              '(-4 . "OR>")
           )
       )
   )
)

Test program:

(defun c:test ( / p1 p2 )
   (if
       (and
           (setq p1 (getpoint "\nPoint 1: "))
           (setq p2 (getpoint "\nPoint 2: "))
       )
       (print (connected-p (trans p1 1 0) (trans p2 1 0)))
   )
   (princ)
)

 

Though, the above is very inefficient if you are looking to test multiple points - a more efficient method would be to retrieve the set of all lines in the appropriate drawing layout and test the points against the end points of the lines in this set.

Link to comment
Share on other sites

Another

(defun c:demo (/ A B ENT FLAG ITM NUM P1 P2 SS)
 (if (and (setq p1 (getpoint "\nPick the first point <exit> : "))
   (setq p2 (getpoint "\nPick the second point <exit> :"))
   (setq ss (ssget "_F" (list p1 p2) '((0 . "LINE"))))
     )
   (progn
     (setq itm 0
    num (sslength ss)
    flag nil
     )
     (while (and (< itm num)
	  (/= flag T)
     )
(setq ent (entget (ssname ss itm))
      a	  (cdr (assoc 10 ent))
      b	  (cdr (assoc 11 ent))
      itm (1+ itm)
)
(if (and (or (equal p1 a 1e- (equal p1 b 1e-)
	 (or (equal p2 a 1e- (equal p2 b 1e-)
    )
  (progn (setq flag T)
	 (prompt "\nA line is connecting the two points!")
  )
)
     )
     (if (not flag) (prompt "\nNo line is connecting the two points!"))
   )
 )
 (princ)
)

HTH

Henrique

Link to comment
Share on other sites

Though, the above is very inefficient if you are looking to test multiple points - a more efficient method would be to retrieve the set of all lines in the appropriate drawing layout and test the points against the end points of the lines in this set.

 

Lee wouldn't be more eficiente if your "connected-p" function only tests a possible line

(defun connected-p (p1 p2)
 (and
   (ssget "_F"
   (list p1 p2)
   (list
     '(0 . "LINE")
     '(-4 . "<OR")
...

 

Henrique

Link to comment
Share on other sites

Lee wouldn't be more eficiente if your "connected-p" function only tests a possible line

(defun connected-p (p1 p2)
 (and
   (ssget "_F"
      (list p1 p2)
      (list
        '(0 . "LINE")
        '(-4 . "<OR")
...

Henrique

 

A good suggestion Henrique, but since the Fence mode string is a graphical selection method, this relies on the points always being visible in the drawing area, otherwise the function will return unexpected results.

Link to comment
Share on other sites

A good suggestion Henrique, but since the Fence mode string is a graphical selection method, this relies on the points always being visible in the drawing area, otherwise the function will return unexpected results.

 

Good point!

 

Henrique

Link to comment
Share on other sites

Thanks LeeMac your input has been always useful. I used the above function without arguments so that I can go round the convexhull connecting any points that are unconnected together with any others inside in one go. Thanks to hmsilva (a very familiar name in my part of the world) and to Tharwat, too.

Regards,

Aloy

Link to comment
Share on other sites

  • 3 weeks later...

I have 500 points in Auto cad, 250 points up & others are down. Surveyor take the points at up&down one bye one position. I connected that points by the help of a lisp. Its coming in ZIGZAG model. I need to make a rectangular model. Please help me. is there any lisp for that. Please help me....

Link to comment
Share on other sites

Assankattayil,

The question I have put to the forum has been answered and I found the solution. I do not know how it is related to yours and also your question.

What do you mean by "I have 500 points in Auto cad, 250 points up & others are down." In what form the survey data came?. The experts in this forum may be able to tell how to put them in ZIGZAG or any other model which I am not familiar. Please put it to them in the form of a post, not as a reply to another thread.

Regards,

Aloy

Link to comment
Share on other sites

I connected that points by the help of a lisp. Its coming in ZIGZAG model. I need to make a rectangular model.

Most probably your AutoLISP tool is connecting the points by their adding order; may be useful to adjust it to work on a selection set rather that entire drawing and run it once on top items, respectively on bottom one.

Link to comment
Share on other sites

I attached one file for example. I connected that points with the help of lisp. But its coming one line goto to up then down then up etc...... I need the drawing in rectangular shape. please can you arrange for me.........

Drawing2.dwg

Link to comment
Share on other sites

Your file contains only 100 points; just activate the Osnap mode Node and will be done in a couple of minutes. May help also to adjust points display mode by calling DDPTYPE command.

Link to comment
Share on other sites

Hi Msasu,

its an example. Its a rock filling area 8640m length. every 2mtr have points. 4320points in one side. so its 8640 points . Please arrange for me one lisp.

Link to comment
Share on other sites

What I'm suggesting is to separate the points in two groups, the top, respectively the bottom ones. To don't have to adjust the code (as per above suggestion), may also do this by dividing the drawing in two copies (one for top points and another one for bottom points) and run the aforementioned tool on each of these; next step copy the results in a single file.

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