TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Biscuits on September 27, 2016, 01:54:42 PM

Title: Can I get some help with selection set?
Post by: Biscuits on September 27, 2016, 01:54:42 PM
Trying to combine several block names in a single selection set to condense this code...there will be additional blocks added at a later date.
How might I tweak this to run the burst one time on all blocks listed rather once for each one?
I mess it up every time I try. Any help would be appreciated. Thanks

Code: [Select]
;;; Creates a selection set of blocks by the name of
;;; "TIC", "TIC MARK", "SW",
;;; explodes them, making sure they stay on the layer in which they were inserted.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:Tixplode ()
(setq ctab (getvar "ctab"))
(foreach tab (cons "Model" (layoutlist))
  (setvar 'CTAB tab)


(while (setq nerd1 (ssget "X" (list (cons 0 "INSERT") (cons 2 "TIC") (cons 410 (getvar 'ctab)))))
(sssetfirst nil nerd1)
(C:Burst)
)

(while (setq nerd2 (ssget "X" (list (cons 0 "INSERT") (cons 2 "TIC MARK") (cons 410 (getvar 'ctab)))))
(sssetfirst nil nerd2)
(C:Burst)
)
;;;;;;;;;;;;;;;;;;
(while (setq nerd3 (ssget "X" (list (cons 0 "INSERT") (cons 2 "SW") (cons 410 (getvar 'ctab)))))
(sssetfirst nil nerd3)
(C:Burst)
)
(setvar "ctab" ctab)
)
(princ)
)

And yes, we need to explode these older blocks for various reasons.
Title: Re: Can I get some help with selection set?
Post by: CAB on September 27, 2016, 02:30:17 PM
Maybe this?
Code: [Select]
(setq nerd1 (ssget "X" (list (cons 0 "INSERT") (cons 2 "block1, block2, block3") (cons 410 (getvar 'ctab)))))
Title: Re: Can I get some help with selection set?
Post by: Jeff_M on September 27, 2016, 02:36:15 PM
What CAB said, except omit the space after the comma.
Title: Re: Can I get some help with selection set?
Post by: Grrr1337 on September 27, 2016, 02:38:12 PM
Your overall code could be shortened up to:
Code: [Select]
;;; Creates a selection set of blocks by the name of
;;; "TIC", "TIC MARK", "SW",
;;; explodes them, making sure they stay on the layer in which they were inserted.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:Tixplode ( / s )
(if (setq s (ssget "X" (list (cons 0 "INSERT") (cons 2 "TIC,TIC MARK,SW") )))
(progn
(sssetfirst nil s)
(C:Burst)
)
)
(princ)
)
Title: Re: Can I get some help with selection set?
Post by: ronjonp on September 27, 2016, 02:47:42 PM
Code - Auto/Visual Lisp: [Select]
  1. (setq nerd1 (ssget "_X"
  2.                    (list '(0 . "INSERT")
  3.                          '(2 . "tic*,sw")
  4.                          (cons 410 (getvar 'ctab))
  5.                    )
  6.             )
  7. )
Title: Re: Can I get some help with selection set?
Post by: MP on September 27, 2016, 04:00:44 PM
Be careful with layout tabs that host wildcard chars, e.g. "Layout#1", lest ssget fail to retrieve entities as intended.

Code: [Select]
(defun _Tame ( text / wild )
    (   (lambda ( lst nfg / result )
            (vl-list->string
                (foreach x (reverse lst)
                    (setq result
                        (if (member x nfg)
                            (vl-list* 96 x result)
                            (cons x result)
                        )
                    )
                )
            )
        )
        (vl-string->list text)
        (vl-string->list "#@.*?~[]-,") 
    )
)

Usage:

Code: [Select]
(setq nerd1
    (ssget "_X"
        (list
           '(0 . "INSERT")
           '(2 . "tic*,sw")
            (cons 410 (_Tame (getvar 'ctab)))
        )
    )
)

FWIW, Cheers.

Edit: Embedded wildcards and the impact upon ssget is not limited to layout names -- can effect anything with a name: layers, blocks, text styles yada ... but for some reason layout names are prone to the malady more than others (in my experience), ergo my intrusion.
Title: Re: Can I get some help with selection set?
Post by: ronjonp on September 27, 2016, 04:42:17 PM
Lotsa good reading HERE (https://www.theswamp.org/index.php?topic=35028.msg402471#msg402471) too about selection sets.
Title: Re: Can I get some help with selection set?
Post by: Biscuits on September 27, 2016, 05:32:15 PM
Thank you all. I got close a few times. Thanks to you guys...mission accomplished.
We need a line of code like:

Code: [Select]
(ya know what I meant (dang-it))

Thanks again, everyone!
Title: Re: Can I get some help with selection set?
Post by: Lee Mac on September 27, 2016, 05:39:38 PM
Be careful with layout tabs that host wildcard chars, e.g. "Layout#1", lest ssget fail to retrieve entities as intended.

< ... >

Edit: Embedded wildcards and the impact upon ssget is not limited to layout names -- can effect anything with a name: layers, blocks, text styles yada ... but for some reason layout names are prone to the malady more than others (in my experience), ergo my intrusion.

Good stuff MP - FWIW, this (http://lee-mac.com/escapewildcards.html) was my take on it.
Title: Re: Can I get some help with selection set?
Post by: MP on September 27, 2016, 08:50:55 PM
Lucid, well documented.

<mock_surprise.mpg>