Author Topic: ssget limit only 10 entities  (Read 1287 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 493
ssget limit only 10 entities
« on: February 27, 2016, 01:48:46 AM »
How to limit number of entities to be selected by ssget, say 10 numbers only.


ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ssget limit only 10 entities
« Reply #1 on: February 27, 2016, 03:39:18 AM »
Select as much as you can (more than 10), then iterate through sel.set and redefine it to contain just 10... Use (while) in combination with (ssdel)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

David Bethel

  • Swamp Rat
  • Posts: 656
Re: ssget limit only 10 entities
« Reply #2 on: February 27, 2016, 04:25:08 AM »
Maybe:

Code: [Select]

  (setq mq 10)

  (while (not ss)
         (and (setq ps (ssget))
              (<= (sslength ps) mq)
              (setq ss ps)))

-David
R12 Dos - A2K

mailmaverick

  • Bull Frog
  • Posts: 493
Re: ssget limit only 10 entities
« Reply #3 on: February 28, 2016, 12:46:44 AM »
We can do it by while but I thought there might be something inbuilt in ssget to limit number of entities.

Thanks a lot.

ChrisCarlson

  • Guest
Re: ssget limit only 10 entities
« Reply #4 on: February 29, 2016, 07:54:36 AM »
No direct limiting built into SSGET, only filtering what gets included and defining how it is included.

http://www.lee-mac.com/ssget.html


Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: ssget limit only 10 entities
« Reply #5 on: February 29, 2016, 08:57:32 AM »
Hi mailmaverick

This lisp will allow you to select exactly n objects, but it can be modified to accept n OR less than n objects.

Code - Auto/Visual Lisp: [Select]
  1. ;Selecting exactly n entities
  2. ;s - selected objects; initial nil or empty selection set
  3. ;f - selection filter
  4. (defun sel_obj (s f n / i c j k e)
  5.   (cond
  6.     (s
  7.       (setq i 0)
  8.       (repeat (sslength s)
  9.         (redraw (ssname s i) 3)
  10.         (setq i (1+ i))
  11.       )
  12.     )
  13.     (T (setq s (ssadd) i 0))
  14.   )
  15.   (setvar 'errno 0)
  16.   (if
  17.     (setq c (if f (ssget ":S:L" f) (ssget ":S:L")))
  18.     (progn
  19.       (setq j (sslength c))
  20.       (repeat (setq k j)
  21.         (if
  22.           (ssmemb (setq e (ssname c (setq k (1- k)))) s)
  23.           (ssdel e c)
  24.         )
  25.       )
  26.       (setq k (sslength c))
  27.       (cond
  28.         ( (> (+ i k) n)
  29.           (princ (strcat "\nToo many objects selected. Only " (itoa (- n i)) " objects left."))
  30.           (sel_obj s f n)
  31.         )
  32.         ( (< (+ i k) n)
  33.           (princ (strcat "\n" (itoa j) " objects selected, " (itoa (- j k)) " duplicates, total " (itoa (+ i k)) " objects selected."))
  34.           (repeat k
  35.             (ssadd (ssname c (setq k (1- k))) s)
  36.             )
  37.          (sel_obj s f n)
  38.          )
  39.         (T (repeat k
  40.              (ssadd (ssname c (setq k (1- k))) s)
  41.            )
  42.            (princ (strcat "\n" (itoa n) " objects selected."))
  43.            (repeat n
  44.              (redraw (ssname s (setq n (1- n))) 4)
  45.            )
  46.            s
  47.         )
  48.       )
  49.     )
  50.     (if
  51.       (/= (getvar 'errno) 52)
  52.       (sel_obj s f n)
  53.       (repeat i
  54.         (redraw (ssname s (setq i (1- i))) 4)
  55.         )
  56.       )
  57.     )
  58.   )
  59.  
  60.  
  61. (defun c:test nil
  62.   (sssetfirst nil (sel_obj nil nil 10))
  63.   (princ)
  64.   )
  65.  
  66. (defun c:test1 nil
  67.   (sssetfirst nil (sel_obj nil '((0 . "CIRCLE")) 5))
  68.   (princ)
  69.   )