Author Topic: select whatever lines touched to a polyline  (Read 6704 times)

0 Members and 1 Guest are viewing this topic.

sathish

  • Guest
select whatever lines touched to a polyline
« on: July 21, 2004, 08:46:14 AM »
Hello all,

I want to select whatever lines touching specific polyline.
What I was doing is
1) take vertexs of polyline
2) do ssget with fence option with the vertex list.
but sometimes it's giving all entites that touches that polyline, some times it's not giving all entities.
Help please.
thing is that i don't want to select the lines that crossing polyline.
I want to select the entities those are snapping to that polyline.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
select whatever lines touched to a polyline
« Reply #1 on: July 21, 2004, 09:18:48 AM »
sathish

A few things,

First Welcome to the Swamp. Hope you like it. Mark & the others have done a
wonderful job putting it together.

Second please register. It would be nice to think you are here to stay and
we could get to know you better.

Third post the code you are working on. There are some very smart people here
that have helped me and will help you but they don't often have time to write
full routines. Often the problem is a simple code fix. Without seeing the code
or at least a portion of the code the answers to your problem often takes many
questions and answers, and usually the code has to be posted anyway. So don't
be shy, post a little of your code and someone will offer a suggestion.

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

Anonymous

  • Guest
select whatever lines touched to a polyline
« Reply #2 on: July 21, 2004, 09:35:00 AM »
thanks cab, definetly i will register. I never got response this much faster cab.

;below the code that I am using. could you look at it.

(defun c:sd()
  (setq ent (car (entsel)))
  (setq ins_list (massoc 10 (entget ent)))
  (setq sset (ssget "_F" ins_list '((0 . "line")(8 . "0"))))
  );e_def

(defun massoc (key alist / x nlist)
  (foreach x alist
    (if (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
      )
    )
  (reverse nlist)
  )

SMadsen

  • Guest
select whatever lines touched to a polyline
« Reply #3 on: July 21, 2004, 09:42:22 AM »
Problem with Fence is that it's rather picky with entities that just touches the fence. I'd suggest that you use Crossing instead.
A simple way is to find the bounding box of the polyline and use that. Next, you'd want to find the lines that touches the polyline. That can be done by comparing distances between each point and the polyline. The VLAX-CURVE-GETPOINTCLOSESTTO functions can do that and is simple to use.

Here's my take on such a function (without any error checking):

Code: [Select]
(defun ptouch (/ vlst a d1 d2 ent entl maxpt minpt newss opl p10 p11 pl plst ss)
  (vl-load-com)
  (setq pl   (car (entsel "\nPline: "))
        opl  (vlax-ename->vla-object pl)
        plst (vlax-safearray->list
               (vlax-variant-value (vla-get-coordinates opl)))
  )
  (vla-getboundingbox opl 'minpt 'maxpt)
  (mapcar 'set '(minpt maxpt)(mapcar 'vlax-safearray->list (list minpt maxpt)))
  (while (cdr plst)
    (setq vlst (cons (list (car plst) (cadr plst)) vlst)
          plst (cddr plst)
    )
  )
  (cond ((setq ss (ssget "C" minpt maxpt '((0 . "LINE"))))
         (setq a 0 newss (ssadd))
         (repeat (sslength ss)
           (setq ent  (ssname ss a)
                 entl (entget ent)
                 p10  (cdr (assoc 10 entl))
                 p11  (cdr (assoc 11 entl))
                 a    (1+ a)
           )
           (setq d1 (vlax-curve-getclosestPointTo opl p10 T)
                 d2 (vlax-curve-getclosestPointTo opl p11 T))
           (and (or (equal (distance p10 d1) 0.0 1e-6)
                    (equal (distance p11 d2) 0.0 1e-6))
                (ssadd ent newss)
           )
         )
        )
  )
  (vlax-release-object opl)
  newss
)

SMadsen

  • Guest
select whatever lines touched to a polyline
« Reply #4 on: July 21, 2004, 09:56:55 AM »
Oh by the way, thanks for the idea for this routine, sathish. That's a pretty cool tool to have.

I just found quite a few lines on a roof plan that should've touched the edge of the roof but didn't   :oops:

Anonymous

  • Guest
select whatever lines touched to a polyline
« Reply #5 on: July 21, 2004, 10:17:37 AM »
Thank you very much SMadsen, it's working perfectly.

SMadsen

  • Guest
select whatever lines touched to a polyline
« Reply #6 on: July 21, 2004, 11:15:53 AM »
You're welcome.

Here's a small improvement. It expands the crossing rectangle (currently by 1/15 of the view height) and accepts plines, lines, circles, ellipse and splines as the object to be touched.

Code: [Select]
(defun ptouch (/ a d1 d2 ent entl maxpt minpt newss opl p10 p11 pl ss)
  (vl-load-com)
  (setvar "ERRNO" 0)
  (while (and (not (setq pl (car (entsel "\nSelect edge object: "))))
              (/= (getvar "ERRNO") 52))
  )
  (cond ((and pl (member (cdr (assoc 0 (entget pl)))
                      '("LWPOLYLINE" "LINE" "ELLIPSE" "SPLINE" "CIRCLE")))
         (setq opl  (vlax-ename->vla-object pl)
               ;; expand crossing selection by 1/15th of view height
               expd (/ (getvar "VIEWSIZE") 15.0)
         )
         ;; get diagonal points of bbox
         (vla-getboundingbox opl 'minpt 'maxpt)
         ;; convert to point lists
         (mapcar 'set '(minpt maxpt)
                 (mapcar 'vlax-safearray->list (list minpt maxpt)))
         ;; expand points
         (setq minpt (mapcar '- minpt (list expd expd))
               maxpt (mapcar '+ maxpt (list expd expd)))
         ;; go select lines
         (cond ((setq ss (ssget "C" minpt maxpt '((0 . "LINE"))))
                ;; remove self - if self was a line
                (ssdel pl ss)
                ;; init counter and new sset
                (setq a 0 newss (ssadd))
                (repeat (sslength ss)
                  (setq ent  (ssname ss a)
                        entl (entget ent)
                        p10  (cdr (assoc 10 entl))
                        p11  (cdr (assoc 11 entl))
                        a    (1+ a)
                  )
                  ;; find closest point and compare distances
                  (setq d1 (vlax-curve-getclosestPointTo opl p10 T)
                        d2 (vlax-curve-getclosestPointTo opl p11 T))
                  (and (or (equal (distance p10 d1) 0.0 1e-6)
                           (equal (distance p11 d2) 0.0 1e-6))
                       (ssadd ent newss)
                  )
                )
               )
         )
         (vlax-release-object opl)
        )
  )
  (if (and newss (> (sslength newss) 0)) newss)
)


To adjust expansion, change the divisor at the (getvar "VIEWSIZE") statement .. or just remove it along with setq'ing minpt and maxpt.
To adjust fuzz factor for point 'closeness', adjust the fuzz factor in the EQUAL conditions.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
select whatever lines touched to a polyline
« Reply #7 on: July 21, 2004, 12:34:06 PM »
Wow - go out for a few hours and look what I missed.
That is a cool routine Stig.
Thanks for sharing it.
CAB
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.

Balaji

  • Guest
Re: select whatever lines touched to a polyline
« Reply #8 on: October 24, 2010, 08:07:34 AM »
Problem with Fence is that it's rather picky with entities that just touches the fence. I'd suggest that you use Crossing instead.
A simple way is to find the bounding box of the polyline and use that. Next, you'd want to find the lines that touches the polyline. That can be done by comparing distances between each point and the polyline. The VLAX-CURVE-GETPOINTCLOSESTTO functions can do that and is simple to use.

Here's my take on such a function (without any error checking):

Code: [Select]
(defun ptouch (/ vlst a d1 d2 ent entl maxpt minpt newss opl p10 p11 pl plst ss)
  (vl-load-com)
  (setq pl   (car (entsel "\nPline: "))
        opl  (vlax-ename->vla-object pl)
        plst (vlax-safearray->list
               (vlax-variant-value (vla-get-coordinates opl)))
  )
  (vla-getboundingbox opl 'minpt 'maxpt)
  (mapcar 'set '(minpt maxpt)(mapcar 'vlax-safearray->list (list minpt maxpt)))
  (while (cdr plst)
    (setq vlst (cons (list (car plst) (cadr plst)) vlst)
          plst (cddr plst)
    )
  )
  (cond ((setq ss (ssget "C" minpt maxpt '((0 . "LINE"))))
         (setq a 0 newss (ssadd))
         (repeat (sslength ss)
           (setq ent  (ssname ss a)
                 entl (entget ent)
                 p10  (cdr (assoc 10 entl))
                 p11  (cdr (assoc 11 entl))
                 a    (1+ a)
           )
           (setq d1 (vlax-curve-getclosestPointTo opl p10 T)
                 d2 (vlax-curve-getclosestPointTo opl p11 T))
           (and (or (equal (distance p10 d1) 0.0 1e-6)
                    (equal (distance p11 d2) 0.0 1e-6))
                (ssadd ent newss)
           )
         )
        )
  )
  (vlax-release-object opl)
  newss
)




Hai i am tried in Cad 2007 Version....But its not select the Lines Touched Entities.....Can you chk?i am waiting for u r reply....i am expect select whatever lines touched to a polyline.....So here hw can i chk reply????
« Last Edit: October 25, 2010, 11:52:59 AM by Balaji »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: select whatever lines touched to a polyline
« Reply #9 on: October 24, 2010, 08:50:39 AM »
Hi,

Just 2 things with ssget with modes requiring points:
- Only visible entities in the current view would be selected
- points have to be specified in current UCS coordinates

Code: [Select]
(defun massoc (code alst / pair)
  (if (setq alst (member (assoc code alst) alst))
    (cons (cdar alst) (massoc code (cdr alst)))
  )
)

(defun c:test (/ pl elst pts ss)
  (if (and (setq ent (car (entsel "\nSelect a polyline: ")))
   (setq elst (entget ent))
   (= (cdr (assoc 0 elst)))
      )
    (progn
      (command "_zoom" "_extents")
      (setq pts (mapcar '(lambda (x) (trans x ent 1))
(massoc 10 elst)
)
    ss (ssget "_F" pts '((0 . "LINE") (8 . "0")))
      )
      (command "_zoom" "_previous")
      (sssetfirst nil ss)
    )
  )
  (princ)
)
« Last Edit: October 24, 2010, 09:00:12 AM by gile »
Speaking English as a French Frog

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Joe Burke

  • Guest
Re: select whatever lines touched to a polyline
« Reply #11 on: October 26, 2010, 08:02:50 AM »
Hi,

Just 2 things with ssget with modes requiring points:
- Only visible entities in the current view would be selected
- points have to be specified in current UCS coordinates

Code: [Select]
(defun massoc (code alst / pair)
  (if (setq alst (member (assoc code alst) alst))
    (cons (cdar alst) (massoc code (cdr alst)))
  )
)

(defun c:test (/ pl elst pts ss)
  (if (and (setq ent (car (entsel "\nSelect a polyline: ")))
   (setq elst (entget ent))
   (= (cdr (assoc 0 elst)))
      )
    (progn
      (command "_zoom" "_extents")
      (setq pts (mapcar '(lambda (x) (trans x ent 1))
(massoc 10 elst)
)
    ss (ssget "_F" pts '((0 . "LINE") (8 . "0")))
      )
      (command "_zoom" "_previous")
      (sssetfirst nil ss)
    )
  )
  (princ)
)


Hi gile,

As I'm sure you are aware, there is a problem with using fence selection when dashed objects are involved. Selection will fail if the fence crosses a gap. The IntersectWith method avoids that problem. Something I dealt with in my CookieCutter2 routine.

Regards
Joe