Jump to content
rog1n

SSGET with number of itens

Recommended Posts

rog1n

Hello, is possible to make a ssget that the user can only select for example two circles and one polyline?

Share this post


Link to post
Share on other sites
Lee Mac

It's possible, but not as part of a single ssget expression - you would need to construct a loop such as:

(defun c:test ( / s )
    (while
        (and (setq s (ssget '((0 . "CIRCLE,LWPOLYLINE"))))
            (or (/= 3 (sslength s))
                (vl-some '/=
                   '("CIRCLE" "CIRCLE" "LWPOLYLINE")
                    (acad_strlsort (mapcar '(lambda ( i ) (cdr (assoc 0 (entget (ssname s i))))) '(0 1 2)))
                )
            )
        )
        (princ "\nPlease select two circles and a polyline.")
    )
    (if s
        (princ "\nThe user selected two circles and a polyline.")
        (princ "\nThe user cancelled the selection.")
    )
    (princ)
)

 

  • Thanks 1

Share this post


Link to post
Share on other sites
rog1n
19 minutes ago, Lee Mac said:

It's possible, but not as part of a single ssget expression - you would need to construct a loop such as:


(defun c:test ( / s )
    (while
        (and (setq s (ssget '((0 . "CIRCLE,LWPOLYLINE"))))
            (or (/= 3 (sslength s))
                (vl-some '/=
                   '("CIRCLE" "CIRCLE" "LWPOLYLINE")
                    (acad_strlsort (mapcar '(lambda ( i ) (cdr (assoc 0 (entget (ssname s i))))) '(0 1 2)))
                )
            )
        )
        (princ "\nPlease select two circles and a polyline.")
    )
    (if s
        (princ "\nThe user selected two circles and a polyline.")
        (princ "\nThe user cancelled the selection.")
    )
    (princ)
)

 

 

 

Thank you Lee Mac, this exactly I needed.

Share this post


Link to post
Share on other sites
Grrr

Just leaving this (I had fun) -

('((L) (vl-every ''((x)(member x L)) '(("LWPOLYLINE" . 1) ("CIRCLE" . 2))))
  ('(( f SS ) (if SS (f SS (1- (sslength SS)) nil)))
    '(( SS i c / itm k )
      (if (<= 0 i)
        (f SS (1- i)
          (if (setq itm (assoc (setq k (cdr (assoc 0 (entget (ssname SS i))))) c))
            (subst ('((itm)(cons (car itm) (1+ (cdr itm)))) itm) itm c)
            (cons (cons k 1) c)
          )
        )
        c
      )
    )
    (ssget '((0 . "CIRCLE,LWPOLYLINE")))
  )
)

 

Share this post


Link to post
Share on other sites
Lee Mac
6 hours ago, Grrr said:

Just leaving this (I had fun) -


('((L) (vl-every ''((x)(member x L)) '(("LWPOLYLINE" . 1) ("CIRCLE" . 2))))
  ('(( f SS ) (if SS (f SS (1- (sslength SS)) nil)))
    '(( SS i c / itm k )
      (if (<= 0 i)
        (f SS (1- i)
          (if (setq itm (assoc (setq k (cdr (assoc 0 (entget (ssname SS i))))) c))
            (subst ('((itm)(cons (car itm) (1+ (cdr itm)))) itm) itm c)
            (cons (cons k 1) c)
          )
        )
        c
      )
    )
    (ssget '((0 . "CIRCLE,LWPOLYLINE")))
  )
)

 

 

Try selecting other objects in addition to two circles and a polyline ;)

Share this post


Link to post
Share on other sites
Lee Mac
7 hours ago, rog1n said:

Thank you Lee Mac, this exactly I needed.

 

You're most welcome 🍺

  • Thanks 1

Share this post


Link to post
Share on other sites
Grrr
3 hours ago, Lee Mac said:

 

Try selecting other objects in addition to two circles and a polyline ;)

 

Ah, right..

(vl-every ''((x)(member x L)) '(("LWPOLYLINE" . 1) ("CIRCLE" . 2)))

should be

(and (= 2 (length L)) (vl-every ''((x)(member x L)) '(("LWPOLYLINE" . 1) ("CIRCLE" . 2))))

 


Or for a better performance, include the check before processing the SS -

(if SS (f SS (1- (sslength SS)) nil))

the above must be changed to 

(if (and SS (= 3 (sslength SS))) (f SS (1- (sslength SS)) nil))

 

Thanks Lee! :beer:

Share this post


Link to post
Share on other sites
David Bethel

Maybe :

(defun c:test (/ ls cs fs ss i en ed)
  (setq ls (ssadd)
        cs (ssadd)
        fs (ssadd))

  (while (/= (sslength fs) 3)
         (setq fs (ssadd))
         (and (princ "\nSelect 2 Lines and 1 Circle:   ")
              (setq ss (ssget '((0 . "LINE,CIRCLE"))))
              (= (sslength ss) 3)
              (setq i 0)
              (while (setq en (ssname ss i))
                     (setq ed (entget en))
                     (cond ((= "LINE" (cdr (assoc 0 ed)))
                            (ssadd en ls)
                            (ssadd en fs))
                           ((= "CIRCLE" (cdr (assoc 0 ed)))
                            (ssadd en cs)
                            (ssadd en fs)))
                    (setq i (1+ i)))
               (= (sslength ls) 2)
               (= (sslength cs) 1)
               fs))
  fs)

 

You would need to tweak LINE vs POLYLINE vs LWPOLYLINE

 

-David

Share this post


Link to post
Share on other sites
BIGAL
Posted (edited)

Maybe another way ‘(“circle” “circle” “Polyline”) use the nth and force a check till correct object picked. List can get bigger. On iPad no code.

Edited by BIGAL

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...