Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Section Fence using a polyline on a curtain layer

  1. #1
    Member
    Join Date
    2015-11
    Posts
    5
    Login to Give a bone
    0

    Default Section Fence using a polyline on a curtain layer

    Hello,

    First off, thanks for any help in advance, I am a newbie to LISP and have a issue I need solved. I would like a LISP which can search a drawing for all polylines on a curtain layer or color, then, using the points of the polylines create a selection fence to select non-AutoCAD 3D items above the line. At the end of this LISP I would like all these items selected.

    Thanks

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Section Fence using a polyline on a curtain layer

    Assuming that polylines don't have arcs, this should do it :

    Code:
    (vl-load-com)
    (defun c:selbycurlaycolplfence ( / curlay curcol ss n pl plvla plcoords pt plptlst ssflst )
      (setq curlay (getvar 'clayer))
      (setq curcol (getvar 'cecolor))
      (cond ((eq curcol "BYLAYER") (setq curcol 256))
            ((eq curcol "BYBLOCK") (setq curcol 0))
            (t (setq curcol (atoi curcol)))
      )
      (command "._zoom" "_E")
      (setq ss (ssget "_X" (list (cons 0 "*POLYLINE") (cons 100 "AcDb2dPolyline") (cons 8 curlay) (cons 62 curcol))))
      (repeat (setq n (sslength ss))
        (setq pl (ssname ss (setq n (1- n))))
        (setq plvla (vlax-ename->vla-object pl))
        (setq plcoords (vlax-safearray->list (vlax-variant-value (vla-get-coordinates plvla))))
        (if (eq (cdr (assoc 0 (entget pl))) "LWPOLYLINE")
          (progn
            (repeat (/ (length plcoords) 2)
              (setq pt (list (car plcoords) (cadr plcoords) 0.0))
              (setq plcoords (cddr plcoords))
              (setq plptlst (cons pt plptlst))
            )
          )
          (progn
            (repeat (/ (length plcoords) 3)
              (setq pt (list (car plcoords) (cadr plcoords) (caddr plcoords)))
              (setq plcoords (cdddr plcoords))
              (setq plptlst (cons pt plptlst))
            )
          )
        )
        (if (eq (cdr (assoc 70 (entget pl))) 1) (setq plptlst (cons (last plptlst) plptlst)))
        (set (read (strcat "ssf" (itoa n))) (ssget "_F" plptlst))
        (setq plptlst nil)
        (ssdel pl (eval (read (strcat "ssf" (itoa n)))))
      )
      (repeat (setq n (sslength ss))
        (setq ssflst (append (list (read (strcat "ssf" (itoa (setq n (1- n)))))) ssflst))
      )
      (sssetfirst nil (acet-ss-union (eval (cons 'list ssflst))))
      (foreach ssf ssflst
        (set ssf nil)
      )
      (princ)
    )
    (defun c:scpf nil (c:selbycurlaycolplfence))
    (prompt "\nShortcut for c:selbycurlaycolplfence is c:scpf")
    (princ)
    M.R.
    Last edited by marko_ribar; 2012-07-16 at 07:36 PM.

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Section Fence using a polyline on a curtain layer

    Marco, just be careful of dynamically creating a new selection set for each polyline. You only have a limited number of active selection sets available (apparently around 128).

    I'd attempt a rewrite so your code only uses at most 3 selection sets. One holding the polylines, then for each polyline create a temporary set from the fence points, add each item from the temporary one into a final. Set the temporary to nil and do a gc to force it to be cleared from ram - continue the loop to the next PL.

  4. #4
    Member
    Join Date
    2015-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: Section Fence using a polyline on a curtain layer

    Marko, exactly what I was looking for, works perfectly!!!! Thank you for all your help.

  5. #5
    Member
    Join Date
    2015-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: Section Fence using a polyline on a curtain layer

    So, if I'm understanding you irneb, your saying if there is more that 128 polylines this code will fail?

  6. #6
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Section Fence using a polyline on a curtain layer

    It might not fail entirely, but it's going to run into an error and not select everything.

    Perhaps this idea:
    Code:
    (defun massoc (key lst / a found)
      (while (setq a (assoc key lst))
        (setq found (cons (cdr a) found) lst (cdr (member a lst))))
      (reverse found))
    
    (defun c:SelectByPolyFence (/ CTab CCol ssPL nPL en ed vecPL en1 ssTmp nTmp ssResult)
      (command "_.zoom" "_Extents")
      (setq CCol (getvar "CeColor")
            CCol (cond ((eq CCol "BYLAYER") 256)
                       ((eq CCol "BYBLOCK") 0)
                       ((atoi CCol)))
            CTab (cond ((> (getvar "CVport") 1) "Model")
                       ((getvar "CTab")))
            ssResult (ssadd))
      (if (setq ssPL (ssget "_X" (list '(0 . "LWPOLYLINE") (cons 8 (getvar "CLayer")) (cons 62 CCol) (cons 410 CTab))))
        (repeat (setq nPL (sslength ssPL))
          (setq ed (entget (setq en (ssname ssPL (setq nPL (1- nPL)))))
                vecPL (massoc 10 ed))
          (if (= (cdr (assoc 70 ed)) 1)
            (setq vecPL (cons (last vecPL) vecPL)))
          (if (setq ssTmp (ssget "_F" vecPL))
            (repeat (setq nTmp (sslength ssTmp))
              (if (/= (setq en1 (ssname ssTmp (setq nTmp (1- nTmp)))) en)
                (ssadd en1 ssResult))))
          (setq ssTmp nil)
          (gc)))
      (sssetfirst nil ssResult)
      (princ))
    Though it only works on new 2d Polylines (i.e. Light Weight polies). But the principle is the same.
    Last edited by irneb; 2012-07-17 at 02:03 PM. Reason: Added the zoom extents

  7. #7
    Member
    Join Date
    2015-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: Section Fence using a polyline on a curtain layer

    Thanks irneb, this version works as well, and given my application for this lisp will require more than 128 polylines I will need it...

  8. #8
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Section Fence using a polyline on a curtain layer

    Yes, Irneb you're right... I made miscalculation and probably acet-ss-union wouldn't work with large list... Anyway I've corrected a little your code, as OP probably didn't wanted that polylines that are used for fence selection to be selected as well...

    Code:
    (defun massoc (key lst / a found)
      (while (setq a (assoc key lst))
        (setq found (cons (cdr a) found) lst (cdr (member a lst))))
      (reverse found))
    
    (defun c:SelectByPolyFence (/ CTab CCol ssPL nPL en ed vecPL en1 ssTmp nTmp ssResult)
      (command "_.zoom" "_Extents")
      (setq CCol (getvar "CeColor")
            CCol (cond ((eq CCol "BYLAYER") 256)
                       ((eq CCol "BYBLOCK") 0)
                       ((atoi CCol)))
            CTab (cond ((> (getvar "CVport") 1) "Model")
                       ((getvar "CTab")))
            ssResult (ssadd))
      (if (setq ssPL (ssget "_X" (list '(0 . "LWPOLYLINE") (cons 8 (getvar "CLayer")) (cons 62 CCol) (cons 410 CTab))))
        (repeat (setq nPL (sslength ssPL))
          (setq ed (entget (setq en (ssname ssPL (setq nPL (1- nPL)))))
                vecPL (massoc 10 ed))
          (if (= (cdr (assoc 70 ed)) 1)
            (setq vecPL (cons (last vecPL) vecPL)))
          (if (setq ssTmp (ssget "_F" vecPL))
            (repeat (setq nTmp (sslength ssTmp))
              (if (/= (setq en1 (ssname ssTmp (setq nTmp (1- nTmp)))) en)
                (ssadd en1 ssResult))))
          (setq ssTmp nil)
          (ssdel en ssResult)
          (gc)))
      (sssetfirst nil ssResult)
      (princ))
    M.R.
    We all make sometimes mistakes from time to time

  9. #9
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Section Fence using a polyline on a curtain layer

    Quote Originally Posted by marko_ribar View Post
    Yes, Irneb you're right... I made miscalculation and probably acet-ss-union wouldn't work with large list...
    Try copying a rectangle around about 200 times, then run your code. You'll see an error printed to command line and nothing seems to happen. It's not the acet-ss-union which gives the error. It's that you will have N+2 active selection sets (N = number of polylines) and acad limits the number of active selection sets to 128.

    Anyway I've corrected a little your code, as OP probably didn't wanted that polylines that are used for fence selection to be selected as well...
    That's not needed, it's already accomplished in my code, I simply don't add them to the ssResult selection set:
    Code:
              (if (/= (setq en1 (ssname ssTmp (setq nTmp (1- nTmp)))) en)
                (ssadd en1 ssResult))))

  10. #10
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Section Fence using a polyline on a curtain layer

    Maybe I'am not seeing something, but without my highlighted line, I get result with selected polylines... Tried several times, don't know...

    Think I know now, it should be :

    Code:
              (if (not (equal (setq en1 (ssname ssTmp (setq nTmp (1- nTmp)))) en))
                (ssadd en1 ssResult))))
    Yes, its number of active selection sets with my code that gives error... Thanks for pointing me that.
    Last edited by marko_ribar; 2012-07-18 at 02:14 PM. Reason: Think I know now

Page 1 of 2 12 LastLast

Similar Threads

  1. Fence - LISP to pick a pre determined fence line?
    By EngME in forum AutoCAD General
    Replies: 5
    Last Post: 2011-10-31, 08:21 PM
  2. Curtain Wall by Face on Polyline
    By tecnicheparametriche in forum Revit - Platform
    Replies: 2
    Last Post: 2011-02-04, 05:02 PM
  3. chain-link fence in corss-section?
    By Maverick91 in forum AutoCAD General
    Replies: 0
    Last Post: 2007-06-27, 07:33 PM
  4. Using a polyline as a selection window/fence area
    By ReachAndre in forum AutoLISP
    Replies: 4
    Last Post: 2007-03-13, 05:39 AM
  5. Chain Link Fence Curtain Wall?
    By jgardner.79905 in forum ACA General
    Replies: 3
    Last Post: 2006-04-27, 03:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •