Author Topic: Can I get some help with selection set?  (Read 2100 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Can I get some help with selection set?
« 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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Can I get some help with selection set?
« Reply #1 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)))))
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.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Can I get some help with selection set?
« Reply #2 on: September 27, 2016, 02:36:15 PM »
What CAB said, except omit the space after the comma.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Can I get some help with selection set?
« Reply #3 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)
)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Can I get some help with selection set?
« Reply #4 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. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can I get some help with selection set?
« Reply #5 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.
« Last Edit: September 27, 2016, 04:10:04 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Can I get some help with selection set?
« Reply #6 on: September 27, 2016, 04:42:17 PM »
Lotsa good reading HERE too about selection sets.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Can I get some help with selection set?
« Reply #7 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!

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Can I get some help with selection set?
« Reply #8 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 was my take on it.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can I get some help with selection set?
« Reply #9 on: September 27, 2016, 08:50:55 PM »
Lucid, well documented.

<mock_surprise.mpg>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst