Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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")))
  )
)

 

Posted
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 ;)

Posted
7 hours ago, rog1n said:

Thank you Lee Mac, this exactly I needed.

 

You're most welcome 🍺

  • Thanks 1
Posted
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:

Posted

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

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

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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