Author Topic: Switch User Selection to Defined Name  (Read 2062 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Switch User Selection to Defined Name
« on: October 19, 2016, 11:23:12 AM »
I found this code by Mr. Leemac. Works great and is simple, but for the life of me; I can not figure out how to change the selection set to be a defined block name. Any idea how I can get this working as such? I know I Can use the SSX to get the Name of the block via the filter. but as for where to swap it out at, I'm confused! lol.

Code: [Select]
((0 . "INSERT") (8 . "BlockName"))
http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-all-to-0-layer-by-layer-including-block-and-block-in/td-p/5376995
Code: [Select]
(defun c:blkto0 ( / idx lst sel )
(if (setq sel (ssget '((0 . "INSERT"))))
(repeat (setq idx (sslength sel))
(block->0 (cdr (assoc 2 (entget (ssname sel (setq idx (1- idx)))))))
)
)
(command "_.regen")
(princ)
)
(defun block->0 ( blk / ent enx )
(cond
( (member blk lst))
( (setq ent (tblobjname "block" blk))
(while (setq ent (entnext ent))
(entmod (subst-append 8 "0" (subst-append 62 256 (setq enx (entget ent)))))
(if (= "INSERT" (cdr (assoc 0 enx)))
(block->0 (cdr (assoc 2 enx)))
)
)
(setq lst (cons blk lst))
)
)
)
(defun subst-append ( key val lst / itm )
(if (setq itm (assoc key lst))
(subst (cons key val) itm lst)
(append lst (list (cons key val)))
)
)

Civil3D 2020

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Switch User Selection to Defined Name
« Reply #1 on: October 19, 2016, 11:37:39 AM »
Hi,
Group Code (GC) 8 is for Layer, GC2 is for Block's name, assuming its not a dynamic block, simple as that:
Code: [Select]
((0 . "INSERT") (2 . "BlockName"))
(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

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Switch User Selection to Defined Name
« Reply #2 on: October 19, 2016, 01:18:07 PM »
I am probably wrong about this... But all I thought I needed to do was replace the selection part. lol. Apparently I am missing a lot more than that.

Code: [Select]
(defun c:blkto0 ( / idx lst sel )
;(if (setq sel (ssget '((0 . "INSERT"))))
(ssget "x" '((0 . "INSERT") (2 . "REVS"))
(repeat (setq idx (sslength sel))
(block->0 (cdr (assoc 2 (entget (ssname sel (setq idx (1- idx)))))))
)
)
(command "_.regen")
(princ)
)
(defun block->0 ( blk / ent enx )
(cond
( (member blk lst))
( (setq ent (tblobjname "block" blk))
(while (setq ent (entnext ent))
(entmod (subst-append 8 "0" (subst-append 62 256 (setq enx (entget ent)))))
(if (= "INSERT" (cdr (assoc 0 enx)))
(block->0 (cdr (assoc 2 enx)))
)
)
(setq lst (cons blk lst))
)
)
)
(defun subst-append ( key val lst / itm )
(if (setq itm (assoc key lst))
(subst (cons key val) itm lst)
(append lst (list (cons key val)))
)
)
Civil3D 2020

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Switch User Selection to Defined Name
« Reply #3 on: October 19, 2016, 01:24:09 PM »
Code: [Select]
(defun c:blkto0 ( / idx sel )
  (if (setq sel (ssget "_A" '((0 . "INSERT") (2 . "REVS"))))
    (repeat (setq idx (sslength sel))
      (block->0 (cdr (assoc 2 (entget (ssname sel (setq idx (1- idx)))))))
    )
  )
  (command "_.regen")
  (princ)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Switch User Selection to Defined Name
« Reply #4 on: October 19, 2016, 01:26:21 PM »
Geesh... Thanks for the help... lol.
Civil3D 2020

ahsattarian

  • Newt
  • Posts: 112
Re: Switch User Selection to Defined Name
« Reply #5 on: November 02, 2022, 05:59:06 AM »
Try This  :



Code - Auto/Visual Lisp: [Select]
  1. (defun c:b0 ()
  2.   (defun subst-append (ass val enn)
  3.     (if (assoc ass enn)
  4.       (subst (cons ass val) (assoc ass enn) enn)
  5.       (append enn (list (cons ass val)))
  6.     )
  7.   )
  8.   (defun sub1 (nam1 / s1 en1)
  9.     (cond
  10.       ((not (member nam1 bli))
  11.        (setq bli (append bli (list nam1)))
  12.        (setq s1 (tblobjname "block" nam1))
  13.        (while (setq s1 (entnext s1))
  14.          (setq en1 (entget s1))
  15.          (setq en1 (subst-append 8 layer en1))
  16.          (setq en1 (subst-append 62 color en1))
  17.          (entmod en1)
  18.          (setq typ1 (strcase (cdr (assoc 0 en1)) t))
  19.          (cond ((= typ1 "insert") (setq nam1 (cdr (assoc 2 en1))) (sub1 nam1)))
  20.        )
  21.       )
  22.     )
  23.   )
  24.   (setq ss (ssget '((0 . "insert"))))
  25.   (setq layer "0")
  26.   (setq color 256)
  27.   (setq bli nil)
  28.   (setq n (sslength ss))
  29.   (setq k -1)
  30.   (repeat n
  31.     (setq k (1+ k))
  32.     (setq s (ssname ss k))
  33.     (setq en (entget s '("*")))
  34.     (setq nam (cdr (assoc 2 en)))
  35.     (sub1 nam)
  36.   )
  37.   (princ (strcat "\n   >>>   " (itoa (length bli)) " Blocks : " (vl-prin1-to-string bli) "  <<<  "))
  38.   (princ)
  39. )



Here,  repeated blocks are omitted.