Author Topic: Selecting Specific lines  (Read 4191 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Selecting Specific lines
« on: May 18, 2011, 07:05:36 AM »
Hello .

Is it possible to Select one line and automatically select all the connected lines at start and end points only (things like a chain of lines).

Thanks

kruuger

  • Swamp Rat
  • Posts: 637
Re: Selecting Specific lines
« Reply #1 on: May 18, 2011, 07:09:19 AM »
Hello .

Is it possible to Select one line and automatically select all the connected lines at start and end points only (things like a chain of lines).

Thanks
FASTSEL from express menu.
kruuger

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Selecting Specific lines
« Reply #2 on: May 18, 2011, 07:13:12 AM »
Code: [Select]
(setq p1(getpoint "\n point 1: ")p2(getpoint "\n point 2: "))
(ssget "_x"
       (list '(0 . "line")
             '(-4 . "<AND")
             '(-4 . "<OR")
             (cons 10 p1)
             (cons 11 p1)
             '(-4 . "OR>")
             '(-4 . "<OR")
             (cons 10 p2)
             (cons 11 p2)
             '(-4 . "OR>")
             '(-4 . "AND>")
       ) ;_  list
)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Selecting Specific lines
« Reply #3 on: May 18, 2011, 07:15:45 AM »
However, the choice of using the select function is very slow.
If you need to find a chain of lines to be quicker to select all the lines and continue to use automatically pick LISP for comparison points, without reference to the drawing.

Coder

  • Swamp Rat
  • Posts: 827
Re: Selecting Specific lines
« Reply #4 on: May 18, 2011, 07:26:12 AM »
Thanks .

but that does not work for me or I may missed understand it as it should be .

I guess it should be with entnext but I do not know how step through that .


Coder

  • Swamp Rat
  • Posts: 827
Re: Selecting Specific lines
« Reply #5 on: May 18, 2011, 07:28:55 AM »
Hello .

Is it possible to Select one line and automatically select all the connected lines at start and end points only (things like a chain of lines).

Thanks
FASTSEL from express menu.
kruuger

Thanks krugger .

I do not mean this command and it performs different than what I am looking for .

Aerdvark

  • Guest
Re: Selecting Specific lines
« Reply #6 on: May 18, 2011, 08:52:23 AM »
I believe the TS means like if it were a polyline, unxploded.

But I have no olution however...

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Selecting Specific lines
« Reply #7 on: May 18, 2011, 09:22:38 AM »
Extreeeeeemely inefficient...

Code: [Select]
(defun c:test ( / el en i l1 l2 ls ss so x )

  (if
    (and
      (setq ss (ssget "_X"      '((0 . "LINE"))))
      (setq en (ssget "_+.:E:S" '((0 . "LINE"))))
    )
    (progn
      (setq so (ssadd)
            en (entget (ssname en 0))
            l1 (list (cdr (assoc 10 en)) (cdr (assoc 11 en)))
      )
      (repeat (setq i (sslength ss))
        (setq en (ssname ss (setq i (1- i)))
              el (entget en)
              ls (cons (list (cdr (assoc 10 el)) (cdr (assoc 11 el)) en) ls)
        )
      )
      (while
        (setq l2
          (vl-remove-if-not
            (function
              (lambda ( x )
                (vl-some
                  (function
                    (lambda ( p )
                      (or (equal (car x) p 1e-8) (equal (cadr x) p 1e-8))
                    )
                  )
                  l1
                )
              )
            )
            ls
          )
        )
        (setq ls
          (vl-remove-if
            (function
              (lambda ( x )
                (vl-some
                  (function
                    (lambda ( p )
                      (or (equal (car x) p 1e-8) (equal (cadr x) p 1e-8))
                    )
                  )
                  l1
                )
              )
            )
            ls
          )
          l1 (apply 'append (cons l1 (mapcar '(lambda ( x ) (list (car x) (cadr x))) l2)))
        )
        (foreach x l2 (ssadd (last x) so))
      )
    )
  )
 
  (sssetfirst nil so)
  (princ)
)

I'm sure there is a better way...
« Last Edit: May 18, 2011, 09:25:41 AM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Selecting Specific lines
« Reply #8 on: May 18, 2011, 09:24:45 AM »
Here is very old lisp I had modified.

Code: [Select]
;;  ***************************************************************
;;   pline path finder.lsp
;;   CAB 07/08/2004
;;   Modified rourine to find a path from picked start entity
;;   to picked end entity.
;;
;;   Returns the path if it exist else nil
;;   Selects & highlites the path also
;;  ***************************************************************

 ;shortcut
(defun c:plp () (c:PlinePath))

;;;  ***************************************************************
;;;               Original Routine                                  
;;;
;;;  ;; based on Inline.lsp by John Uhden
;;;  ;; modified Joe Burke 5/15/03
;;;  ;; pick a line, arc or lwpline
;;;  ;; creates a selection set of objects which meet end to end
;;;  ;; only selects objects on the same layer as picked object
;;;  ;; pass selection set to pedit join...
;;;
;;;  ***************************************************************


;;===================================
;;      -=<  Sub Routines  >=-      
;;===================================

;;  Return (ename Startpt Endpt)
(defun @arc (ent / e rp r ba ea p1 p2)
  (setq e  (cdr (assoc -1 ent))
        rp (cdr (assoc 10 ent))
        r  (cdr (assoc 40 ent))
        ba (cdr (assoc 50 ent))
        ea (cdr (assoc 51 ent))
        p1 (trans (polar rp ba r) e 0)
        p2 (trans (polar rp ea r) e 0)
  )
  (list e p1 p2)
) ;end

;;  Return (ename Startpt Endpt)
(defun @line (ent)
  (list
    (cdr (assoc -1 ent))
    (cdr (assoc 10 ent))
    (cdr (assoc 11 ent))
  )
) ;end

;;  Return (ename Startpt Endpt)
(defun @pline (ent / e)
  (setq e (cdr (assoc -1 ent)))
  (list
    e
    (car (getends e))
    (cadr (getends e))
  )
) ;end

;;  Add ent-> (ename Startpt Endpt) to list
(defun @list (e / ent)
  (setq ent (entget e))
  (cond
    ((= (cdr (assoc 0 ent)) "LINE")
     (setq sslist (cons (@line ent) sslist))
    )
    ((= (cdr (assoc 0 ent)) "ARC")
     (setq sslist (cons (@arc ent) sslist))
    )
    ((= (cdr (assoc 0 ent)) "LWPOLYLINE")
     (setq sslist (cons (@pline ent) sslist))
    )
  )
) ;end

;;argument: an ename - returns: Start and End points as a list
(defun getends (vobj / name stpt endpt)
  (if (= (type vobj) 'ename)
    (setq vobj (vlax-ename->vla-object vobj))
  )
  (and
    (setq name (vla-get-objectname vobj))
    (cond
      ((vl-position
         name
         '("AcDbArc"           "AcDbLine"          "AcDbEllipse"
           "AcDbSpline"        "AcDbPolyline"      "AcDb2dPolyline"
           "AcDb3dPolyline"
          )
       )
       (setq stpt (vlax-curve-getstartpoint vobj))
       (setq endpt (vlax-curve-getendpoint vobj))
      )
    ) ;cond
  ) ;and
  (list stpt endpt)
) ;end

;;  CAB added
;; get list of (ename startpt endpt) for picked ent
(defun get:elst(ent)
  (cond
    ((= (cdr (assoc 0 ent)) "ARC")
     (setq ent (@arc ent))
    )
    ((= (cdr (assoc 0 ent)) "LINE")
     (setq ent (@line ent))
    )
    ((= (cdr (assoc 0 ent)) "LWPOLYLINE")
     (setq ent (@pline ent))
    )
  )
  ent
); end defun


;; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;          main function              
;; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
(defun c:plinepath (/      sslist elist  ss     ssres  i      e      e2
                    found  ent    ent2   ok     start  end    start2 end2
                    fuzz   layer  ssex   typlst
                   )
  ;; Get the start object
  (if ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    (and
      (cadr (ssgetfirst)) ;objects are selected
      ;;at least one arc, line or pline
      (setq ssex (ssget "i" (list (cons 0 "LINE,ARC,LWPOLYLINE"))))
    ) ;and

     ;; ======  then  =============
     (setq e (ssname ssex 0))
     ;; ======  else  =============
     (progn
       (sssetfirst)
       (setq typlst '("LINE" "ARC" "LWPOLYLINE"))
       (while
         (or
           (not (setq e (car (entsel "\nSelect Starting line, pline or arc: "))))
           (not (member (cdr (assoc 0 (entget e))) typlst))
         )
          (princ "\nMissed pick or wrong object type: ")
       ) ;while
     ) ;progn
  ) ;if  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  ;;  Get the End object, CAB added
  (setq typlst '("LINE" "ARC" "LWPOLYLINE"))
  (while
    (or
      (not (setq e2 (car (entsel "\nSelect Ending line, pline or arc: "))))
      (not (member (cdr (assoc 0 (entget e2))) typlst))
    )
     (princ "\nMissed pick or wrong object type: ")
  ) ;while

  (and
    (setq ok   1
          fuzz 1e-8 ; 0.00000001
    )
    (setq ent (entget e)) ; first or picked ent
    (setq ent2 (entget e2)) ; second picked ent
    (setq layer (cdr (assoc 8 ent))) ; layer to match
    (= layer (cdr (assoc 8 ent2))) ; layers match
    (setq ent    (get:elst ent)
          elist  '()
          start  (cadr ent)
          end    (caddr ent)
          ent2   (get:elst ent2); CAB
          start2 (cadr ent2)
          end2   (caddr ent2)
    )
    (setq ss ; get all objects that matched picked
           (ssget "X" (list '(0 . "LINE,ARC,LWPOLYLINE") (cons 8 layer)))
    )
    (ssdel e ss) ; remove picked start from selection set

    ;;  make a list of all from ss  ((ename startpt endpt) ....)
    (setq i 0)
    (repeat (sslength ss)
      (@list (ssname ss i))
      (setq i (1+ i))
    ) ;repeat
    ;;  CAB revised from here down
    ;;  find attached items, does not test all branches
    (@ckpoint start ent sslist)
    (if (not found) ; check the other end of start ent
      (@ckpoint end ent sslist)
    )
  ) ;and
  (if found
    (progn
      (setq elist (cons ent elist))
      (setq ssres (ssadd))
      (foreach x elist ; create a selection set of the list
        (ssadd (car x) ssres)
      )
      (prompt "\n*-* Done *-*\n")
      (cadr(sssetfirst nil ssres)) ; display the selected items
    ); progn
    (prompt "\n*-* Path not found *-*")
  )

) ;end
;; -------------------------------

;;  @ckPoint by CAB
;;  check the list for matching points
;;  p point to match
;;  elst (ename startpt endpt) of pt
;;  |List list pf remaining elst
(defun @ckpoint( p elst |list / entx ex p1 p2 idx res)
  (setq idx (length |List))
  (while (and (not found) (>= (setq idx (1- idx)) 0))
    (setq entx (nth idx |List)
          ex  (car entx)
          p1  (cadr entx)
          p2  (caddr entx)
     )
    (cond ; test point match with fuzz factor
      ((equal p start2 fuzz) ; text for target
       (setq found 1)
       (setq elist (cons ent2 elist))
      )
      ((equal p end2 fuzz) ; text for target
       (setq found 1)
       (setq elist (cons ent2 elist))
      )
      ((equal p p1 fuzz) ; test for next branch
       (setq res (@ckpoint p2 entx (vl-remove entx |List)))
       (if found ; we are backing out collecting the path
        (setq elist (cons entx elist))
       )
      )
      ((equal p p2 fuzz) ; test for next branch
       (setq res (@ckpoint p1 entx (vl-remove entx |List)))
       (if found; we are backing out collecting the path
        (setq elist (cons entx elist))
       )
      )
    )
  ); while
  T ; return to satisfy AND
); defun

;;========================
;;   End Of File          
;;========================
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Coder

  • Swamp Rat
  • Posts: 827
Re: Selecting Specific lines
« Reply #9 on: May 18, 2011, 09:38:51 AM »
Great Routines .

Lee you are saying Extreeeeeemely inefficient... ?

But I say it is more than great .  Thank you  :-)

Thank you CAB .

Your routine is really nice but it is too long for me to read to understand what's going on inside .  :-)

Thank you gentlemen .

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Selecting Specific lines
« Reply #10 on: May 18, 2011, 09:45:57 AM »
This is probably better than my last code:

Code: [Select]
(defun c:test ( / el en fl i l1 l2 ls ss so x )
  (if
    (and
      (setq ss (ssget "_X"      '((0 . "LINE"))))
      (setq en (ssget "_+.:E:S" '((0 . "LINE"))))
    )
    (progn
      (setq so (ssadd)
            en (entget (ssname en 0))
            l1 (list (cdr (assoc 10 en)) (cdr (assoc 11 en)))
      )
      (repeat (setq i (sslength ss))
        (setq en (ssname ss (setq i (1- i)))
              el (entget en)
              ls (cons (list (cdr (assoc 10 el)) (cdr (assoc 11 el)) en) ls)
        )
      )
      (while
        (progn
          (foreach x ls
            (if
              (vl-some
                (function
                  (lambda ( p )
                    (or (equal (car x) p 1e-8) (equal (cadr x) p 1e-8))
                  )
                )
                l1
              )
              (setq so (ssadd (last x) so) l1 (cons (car x) (cons (cadr x) l1)) fl T)
              (setq l2 (cons x l2))
            )
          )
          fl
        )
        (setq ls l2 l2 nil fl nil)
      )
    )
  ) 
  (sssetfirst nil so) (princ)
)
« Last Edit: May 18, 2011, 09:49:11 AM by Lee Mac »

hmspe

  • Bull Frog
  • Posts: 367
Re: Selecting Specific lines
« Reply #11 on: May 18, 2011, 12:51:27 PM »
I use something like this.  Endpoints can be obtained by a function like VxGetEndPoints from http://www.menziengineering.ch/Downloads/Download.htm.

Code: [Select]
  (setq selset1 (getss start_point 0.001 '((0 . "LINE"))))
  (setq selset2 (getss end_point 0.001 '((0 . "LINE"))))

  (defun getss (apnt adist filter)  ; gets a selection set using a bounding box
    (ssget "c"
       (list (- (car apnt) adist) (- (cadr apnt) adist))
       (list (+ (car apnt) adist) (+ (cadr apnt) adist))
       filter
    )
  )
"Science is the belief in the ignorance of experts." - Richard Feynman