Author Topic: Prefer a selectionset by fence an more layers inside  (Read 1203 times)

0 Members and 1 Guest are viewing this topic.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Prefer a selectionset by fence an more layers inside
« on: May 11, 2014, 02:55:09 PM »
Hello!
I have some questions with selectionset if it´s possible to collect drawingObjects som block on a Polyline on different layers.
first I get a pointList of all vertex in a Polyline
than
I select a Polyline it marks all blocks which are crossing the Polyline
(ssget "_F" pointList '((0 . "INSERT")))

When I read all blocks an these Layers I get a Layerlist.
Now I want select some layers and do a new selectionset which read first PolylineVertexes again and put in layerlist I have done
It is looking something like this.
(ssget "_F" pointList '((0 . "INSERT") .... Layer1 Layer2 Layer3....))

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Prefer a selectionset by fence an more layers inside
« Reply #1 on: May 11, 2014, 11:50:38 PM »
Perhaps this will show you the way.
Code - Auto/Visual Lisp: [Select]
  1. ;;=============================================================
  2. ;;     Sel.lsp by Charles Alan Butler
  3. ;;            Copyright 2004
  4. ;;   by Precision Drafting & Design All Rights Reserved.
  5. ;;   Contact CAB at TheSwamp.org
  6. ;;
  7. ;;    Version 1.0 Beta  July 23,2004
  8. ;;    Version 1.1 Beta  July 13,2005
  9. ;;
  10. ;;   Creates a selection set of objects on a layer(s)
  11. ;;   User picks objects to determine the layer(s)
  12. ;;   Then User selects objects for ss or presses enter to
  13. ;;   get all objects on the selected layer(s)
  14. ;;   You may select the selection set before starting this
  15. ;;   routine. Then select the layers to keep in the set
  16. ;;=============================================================
  17. (defun c:sel (/ ent lay ss lay:lst lay:prompt ss:first ent:lst)
  18.  
  19. ;;  An integer value that controls the visibility and highlighting of the entity.
  20. ;;  The mode can be one of the following values:
  21. ;;  1  Show entity
  22. ;;  2  Hide entity (blank it out)
  23. ;;  3  Highlight entity
  24. ;;  4  Unhighlight entity
  25.  
  26. (defun ssredraw ( ss mode / i ename vlaobj)
  27.   (and (eq 'pickset (type ss))
  28.        (setq i -1)
  29.        (while (setq ename (ssname ss (setq i (1+ i))))
  30.            (setq vlaobj (vlax-ename->vla-object (ssname ss i)))
  31.            (vla-Highlight vlaobj :vlax-true)
  32.            (vla-update vlaobj)
  33.        )
  34.   )
  35. )
  36.  
  37.   ;;  get anything already selected
  38.   (setq ss:first (cadr(ssgetfirst))
  39.         ss (ssadd))
  40.  
  41.   ;;  Get user selected layers
  42.   (if ss:first
  43.     (setq lay:prompt "\nSelect the object to choose layers to keep.")
  44.     (setq lay:prompt "\nSelect object(s) for layer filter. ENTER to continue.")
  45.   )
  46.   (while (setq ent (entsel lay:prompt))
  47.     (setq ent:lst (cons (car ent) ent:lst))
  48.     (setq lay:lst
  49.            (cons (setq lay (cdr(assoc 8 (entget (car ent))))) lay:lst))
  50.     (prompt (strcat "\n*-* Selected Layer -> " lay))
  51.   )
  52.   ;;  Un HighLite the entities
  53.   (and ent:lst (mapcar '(lambda (x) (redraw x 4)) ent:lst))
  54.  
  55.   (if (> (length lay:lst) 0); got layers to work with
  56.     (progn
  57.       (setq lay "")
  58.       (setq lay:lst (vl-sort lay:lst '<)) ; removes douplicates
  59.       (foreach itm  lay:lst ; combine lay names into one , del string
  60.         (setq lay (strcat lay itm ",")))
  61.       (setq lay (substr lay 1 (1- (strlen lay)))); remove the last ,
  62.       (if ss:first ; ALREADY GOT SELECTION SET
  63.         (while (setq ent (ssname ss:first 0))
  64.           (if (member (cdr(assoc 8 (entget ent))) lay:lst)
  65.             (ssadd (ssname ss:first 0) ss)
  66.           )
  67.           (ssdel (ssname ss:first 0) ss:first)
  68.         )
  69.         (progn ; else get a selection set to work with
  70.           (prompt (strcat "\nOK >>--> Select objects for Selection set or "
  71.                           "ENTER for All objects on layer(s) " lay))
  72.           ;;  get objects using filter with user select
  73.           (if (null (setq ss (ssget (list (cons 8 lay)))))
  74.             ;; or get ALL objects in current space using filter
  75.             (setq ss (ssget "_X" (list (cons 8 lay)(cons 410 (getvar "ctab")))))
  76.           )
  77.         )
  78.       )
  79.       (if (> (sslength ss) 0)
  80.         (progn
  81.           (prompt (strcat "\n" (itoa (sslength ss))
  82.                       " Object(s) selected on layer(s) " lay
  83.                       "\nStart an ACAD command, REGEN to un highlite."))
  84.           (sssetfirst nil ss)
  85.           (if (< (sslength ss) 500) (ssredraw ss 3))
  86.         )
  87.         (prompt "\n***  Nothing Selected  ***")
  88.       )
  89.     )
  90.   )
  91.   (princ)
  92. )
  93. (prompt "\nSelect on Layer loaded, Enter Sel to run.")
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.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Prefer a selectionset by fence an more layers inside
« Reply #2 on: May 12, 2014, 04:08:20 AM »
Thanks Charles!
Nice example - I descibe my problem not well, here is my solution
Code: [Select]
(if (setq ss (ssget "_F" plst '((0 . "INSERT"))))
       (repeat
(setq i (sslength ss))
(setq LayName (cdr (assoc 8 (entget (ssname ss (setq i (1- i)))))))
(setq LayListe (cons LayName LayListe))
)
take a hole string from all LayerNames
Quote
(defun cd:STR_ReParse (Lst Sep / res)
  (setq res (car Lst))
  (foreach % (cdr Lst)
    (setq res (strcat res Sep %))
  )
  res
)
build a Layerfilterstring
Code: [Select]
(setq Filter (cd:STR_ReParse (REMOVEDUPLICATES LayListe))",")
selectionset
Code: [Select]
(ssget "_F" plst (list '(0 . "INSERT") (cons 8 Filter)))