Jump to content

Recommended Posts

Posted

Hi,

 

I am looking for some help and hope this is possible.

 

Attached is a small water network drawing and I would like a routine that automatically selects the node at each end of the polyline when the polyline is selected. I would need it to the work on multiple polylines. An example on the attached would be selecting the 3 x polylines between nodes 1-2-4-5 and then automtically select the 4 x nodes as well.

I would then copy and paste these items. I hope this makes sense!

TEST.dwg

Posted

Hi,

I don't know if I understood correctly, but the following may be satisfactory for you.
You select all the polylines, then a single polyline (central or not).
The selection of polylines having a common vertex or close to a segment will then be selected.

 

(defun compare (l d l_e / prm new_l)
  (mapcar
    '(lambda (e)
      (mapcar
        '(lambda (x)
          (setq prm
            (cond
              ((equal (cadr x) (vlax-curve-getClosestPointTo e (cadr x) T) d)
                (vlax-curve-getparamatpoint e (trans (cadr x) e 0))
              )
              ((equal (last x) (vlax-curve-getClosestPointTo e (last x) T) d)
                (vlax-curve-getparamatpoint e (trans (last x) e 0))
              )
            )
          )
          (if (and prm (not (member (car x) l_e)))
            (progn
              (ssadd (car x) ss)
              (setq new_l (cons (car x) l_e))
            )
          )
        )
        l
      )
    )
    l_e
  )
  (if new_l new_l nil)
)
(defun list_pt_sel (l_e / dxf_ent)
  (mapcar
    '(lambda (e)
      (setq dxf_ent (entget e))
      (cons
        e
        (mapcar
          '(lambda (x)
            (trans x e 0)
          )
          (mapcar 'cdr
            (vl-remove-if
              '(lambda (x)
                (/= (car x) 10)
              )
              dxf_ent
            )
          )
        )
      )
    )
    l_e
  )
)
(defun c:pl_connect ( / dfzz js_all n e_all js_first ss e_master lst_pt_ori e_other lst_pt l)
  (if (not dfzz) (setq dfzz 1E-08))
  (princ "\nSelect polylines")
  (while (not (setq js_all (ssget '((0 . "LWPOLYLINE"))))))
  (repeat (setq n (sslength js_all))
    (setq e_all (cons (ssname js_all (setq n (1- n))) e_all))
  )
  (princ "\Select ONE central polyline")
  (while (not (setq js_first (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))))
  (setq ss (ssadd))
  (setq e_master (ssname js_first 0))
  (setq ss (ssadd e_master ss))
  (setq lst_pt_ori (list_pt_sel e_all))
  (cond
    (lst_pt_ori
      (setq e_other e_all)
      (setq e_other (vl-remove e_master e_other))
      (cond
        (e_other
          (setq lst_pt (list_pt_sel e_other))
          (setq l (list e_master))
          (while l
            (setq l (compare lst_pt dfzz l))
          )
        )
      )
      (sssetfirst nil ss)
    )
  )
)

 

Posted
55 minutes ago, Tsuky said:

Hi,

I don't know if I understood correctly, but the following may be satisfactory for you.
You select all the polylines, then a single polyline (central or not).
The selection of polylines having a common vertex or close to a segment will then be selected.

 

(defun compare (l d l_e / prm new_l)
  (mapcar
    '(lambda (e)
      (mapcar
        '(lambda (x)
          (setq prm
            (cond
              ((equal (cadr x) (vlax-curve-getClosestPointTo e (cadr x) T) d)
                (vlax-curve-getparamatpoint e (trans (cadr x) e 0))
              )
              ((equal (last x) (vlax-curve-getClosestPointTo e (last x) T) d)
                (vlax-curve-getparamatpoint e (trans (last x) e 0))
              )
            )
          )
          (if (and prm (not (member (car x) l_e)))
            (progn
              (ssadd (car x) ss)
              (setq new_l (cons (car x) l_e))
            )
          )
        )
        l
      )
    )
    l_e
  )
  (if new_l new_l nil)
)
(defun list_pt_sel (l_e / dxf_ent)
  (mapcar
    '(lambda (e)
      (setq dxf_ent (entget e))
      (cons
        e
        (mapcar
          '(lambda (x)
            (trans x e 0)
          )
          (mapcar 'cdr
            (vl-remove-if
              '(lambda (x)
                (/= (car x) 10)
              )
              dxf_ent
            )
          )
        )
      )
    )
    l_e
  )
)
(defun c:pl_connect ( / dfzz js_all n e_all js_first ss e_master lst_pt_ori e_other lst_pt l)
  (if (not dfzz) (setq dfzz 1E-08))
  (princ "\nSelect polylines")
  (while (not (setq js_all (ssget '((0 . "LWPOLYLINE"))))))
  (repeat (setq n (sslength js_all))
    (setq e_all (cons (ssname js_all (setq n (1- n))) e_all))
  )
  (princ "\Select ONE central polyline")
  (while (not (setq js_first (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))))
  (setq ss (ssadd))
  (setq e_master (ssname js_first 0))
  (setq ss (ssadd e_master ss))
  (setq lst_pt_ori (list_pt_sel e_all))
  (cond
    (lst_pt_ori
      (setq e_other e_all)
      (setq e_other (vl-remove e_master e_other))
      (cond
        (e_other
          (setq lst_pt (list_pt_sel e_other))
          (setq l (list e_master))
          (while l
            (setq l (compare lst_pt dfzz l))
          )
        )
      )
      (sssetfirst nil ss)
    )
  )
)

 

Thank you for looking at this for me. Sorry I am a complete novice, I know how to load the LISP file but usually the files I can used give a command prompt to use in CAD. How do I add this?

Posted

(defun compare) and (defun list_pt_sel) are functions used in (defun c:pl_connect) wich is the command function.
The command is PL_CONNECT

Posted
17 hours ago, Tsuky said:

(defun compare) and (defun list_pt_sel) are functions used in (defun c:pl_connect) wich is the command function.
The command is PL_CONNECT

Thank you for this! It nearly does what I require but could it also select the nodes as well as each polyline?

Posted
12 hours ago, andy_06 said:

Thank you for this! It nearly does what I require but could it also select the nodes as well as each polyline?

This can be to resolve it?

(defun compare (l l_b d l_e / prm new_l)
  (mapcar
    '(lambda (e)
      (mapcar
        '(lambda (x)
          (setq prm
            (cond
              ((equal (cadr x) (vlax-curve-getClosestPointTo e (cadr x) T) d)
                (vlax-curve-getparamatpoint e (trans (cadr x) e 0))
              )
              ((equal (last x) (vlax-curve-getClosestPointTo e (last x) T) d)
                (vlax-curve-getparamatpoint e (trans (last x) e 0))
              )
            )
          )
          (if (and prm (not (member (car x) l_e)))
            (progn
              (ssadd (car x) ss)
              (setq new_l (cons (car x) l_e))
              (mapcar
                '(lambda (xb)
                  (cond
                    ((or
                      (equal (cadr x) (trans (cadr xb) (car xb) 0) d)
                      (equal (last x) (trans (cadr xb) (car xb) 0) d)
                     )
                      (ssadd (car xb) ss)
                    )
                  )
                )
                l_b
              )
            )
          )
        )
        l
      )
    )
    l_e
  )
  (if new_l new_l nil)
)
(defun list_pt_sel (l_e / dxf_ent)
  (mapcar
    '(lambda (e)
      (setq dxf_ent (entget e))
      (cons
        e
        (mapcar
          '(lambda (x)
            (trans x e 0)
          )
          (mapcar 'cdr
            (vl-remove-if
              '(lambda (x)
                (/= (car x) 10)
              )
              dxf_ent
            )
          )
        )
      )
    )
    l_e
  )
)
(defun c:pl_connect ( / dfzz js_all n e_all js_first ss e_master lst_pt_ori e_other lst_pt l js_blk e_blk lst_pt_blk)
  (if (not dfzz) (setq dfzz 1E-08))
  (princ "\nSelect polylines")
  (while (not (setq js_all (ssget '((0 . "LWPOLYLINE"))))))
  (repeat (setq n (sslength js_all))
    (setq e_all (cons (ssname js_all (setq n (1- n))) e_all))
  )
  (princ "\Select ONE central polyline")
  (while (not (setq js_first (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))))
  (setq ss (ssadd))
  (setq e_master (ssname js_first 0))
  (setq ss (ssadd e_master ss))
  (setq lst_pt_ori (list_pt_sel e_all))
  (cond
    (lst_pt_ori
      (setq e_other e_all)
      (setq e_other (vl-remove e_master e_other))
      (cond
        (e_other
          (setq
            lst_pt (list_pt_sel e_other)
            l (list e_master)
            js_blk (ssget "_X" '((0 . "INSERT") (8 . "0water nodes") (2 . "GNW")))
          )
          (repeat (setq n (sslength js_blk))
            (setq e_blk (cons (ssname js_blk (setq n (1- n))) e_blk))
          )
          (setq lst_pt_blk (list_pt_sel e_blk))
          (while l
            (setq l (compare lst_pt lst_pt_blk dfzz l))
          )
        )
      )
      (sssetfirst nil ss)
    )
  )
)

 

Posted
10 hours ago, Tsuky said:

This can be to resolve it?

(defun compare (l l_b d l_e / prm new_l)
  (mapcar
    '(lambda (e)
      (mapcar
        '(lambda (x)
          (setq prm
            (cond
              ((equal (cadr x) (vlax-curve-getClosestPointTo e (cadr x) T) d)
                (vlax-curve-getparamatpoint e (trans (cadr x) e 0))
              )
              ((equal (last x) (vlax-curve-getClosestPointTo e (last x) T) d)
                (vlax-curve-getparamatpoint e (trans (last x) e 0))
              )
            )
          )
          (if (and prm (not (member (car x) l_e)))
            (progn
              (ssadd (car x) ss)
              (setq new_l (cons (car x) l_e))
              (mapcar
                '(lambda (xb)
                  (cond
                    ((or
                      (equal (cadr x) (trans (cadr xb) (car xb) 0) d)
                      (equal (last x) (trans (cadr xb) (car xb) 0) d)
                     )
                      (ssadd (car xb) ss)
                    )
                  )
                )
                l_b
              )
            )
          )
        )
        l
      )
    )
    l_e
  )
  (if new_l new_l nil)
)
(defun list_pt_sel (l_e / dxf_ent)
  (mapcar
    '(lambda (e)
      (setq dxf_ent (entget e))
      (cons
        e
        (mapcar
          '(lambda (x)
            (trans x e 0)
          )
          (mapcar 'cdr
            (vl-remove-if
              '(lambda (x)
                (/= (car x) 10)
              )
              dxf_ent
            )
          )
        )
      )
    )
    l_e
  )
)
(defun c:pl_connect ( / dfzz js_all n e_all js_first ss e_master lst_pt_ori e_other lst_pt l js_blk e_blk lst_pt_blk)
  (if (not dfzz) (setq dfzz 1E-08))
  (princ "\nSelect polylines")
  (while (not (setq js_all (ssget '((0 . "LWPOLYLINE"))))))
  (repeat (setq n (sslength js_all))
    (setq e_all (cons (ssname js_all (setq n (1- n))) e_all))
  )
  (princ "\Select ONE central polyline")
  (while (not (setq js_first (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))))
  (setq ss (ssadd))
  (setq e_master (ssname js_first 0))
  (setq ss (ssadd e_master ss))
  (setq lst_pt_ori (list_pt_sel e_all))
  (cond
    (lst_pt_ori
      (setq e_other e_all)
      (setq e_other (vl-remove e_master e_other))
      (cond
        (e_other
          (setq
            lst_pt (list_pt_sel e_other)
            l (list e_master)
            js_blk (ssget "_X" '((0 . "INSERT") (8 . "0water nodes") (2 . "GNW")))
          )
          (repeat (setq n (sslength js_blk))
            (setq e_blk (cons (ssname js_blk (setq n (1- n))) e_blk))
          )
          (setq lst_pt_blk (list_pt_sel e_blk))
          (while l
            (setq l (compare lst_pt lst_pt_blk dfzz l))
          )
        )
      )
      (sssetfirst nil ss)
    )
  )
)

 

Wow that is brilliant! Only one minor thing and that is it doesn't select the end node so is it possible to add this? I selected nodes 1-2-4-5 and it did everything I required apart from picking up node 5.

Posted
3 hours ago, andy_06 said:

Wow that is brilliant! Only one minor thing and that is it doesn't select the end node so is it possible to add this? I selected nodes 1-2-4-5 and it did everything I required apart from picking up node 5.

Indeed, I have to constat your comment.
However, following the single selection of the central polyline, the result is different:
If the selection of the central polyline is included between other segments the result is correct.
If the center polyline selection has no connection at one either end; an end block is omitted.
Honestly I don't know if I would be able to solve this problem...

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