Author Topic: Lisp to change Attribute Tags layer to the block layer  (Read 1024 times)

0 Members and 1 Guest are viewing this topic.

tomohdi1969

  • Mosquito
  • Posts: 3
Lisp to change Attribute Tags layer to the block layer
« on: November 12, 2023, 01:53:30 AM »
Hi, I have different Blocks in my drawings, but all these blocks have the exact attributes with the same Tags, and each tag has a separate layer. I need to be able to choose and change the selected block tag layer to the related block layer. The attached file will explain what I mean. You will notice all the blocks do have the same Att. Tags but Tag name Code has different layers according to the block itself. Also, I need to be able to hide an ATT—value for some blocks. I would highly appreciate it if someone can help me.

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Lisp to change Attribute Tags layer to the block layer
« Reply #1 on: November 12, 2023, 03:29:37 AM »
Something like this ?
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ s)
  2.   ;;----------------------------------------------------;;
  3.   ;;    Author : Tharwat Al Choufi                      ;;
  4.   ;; website: https://autolispprograms.wordpress.com    ;;
  5.   ;;----------------------------------------------------;;
  6.   (and (princ "\nSelect attributed blocks to change Attributes' layers to block's layer :")
  7.        (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))
  8.        ((Lambda (i / n)
  9.           (while (setq n (ssname s (setq i (1+ i))))
  10.             (foreach x (vlax-invoke (vlax-ename->vla-object n) 'getattributes)
  11.               (vla-put-layer x (cdr (assoc 8 (entget n))))
  12.               )
  13.             )
  14.           )
  15.          -1
  16.          )
  17.        )
  18.   (princ)

tomohdi1969

  • Mosquito
  • Posts: 3
Re: Lisp to change Attribute Tags layer to the block layer
« Reply #2 on: November 12, 2023, 04:10:44 AM »
Thank you for your Replay. This lisp will change all the attribute layers to block layers. Is it possible to target the CODE Att. layer? Is it possible to add the Hide/Unhide option to the lisp?

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Lisp to change Attribute Tags layer to the block layer
« Reply #3 on: November 12, 2023, 09:00:34 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ s)
  2.   ;;----------------------------------------------------;;
  3.   ;;    Author : Tharwat Al Choufi                      ;;
  4.   ;; website: https://autolispprograms.wordpress.com    ;;
  5.   ;;----------------------------------------------------;;
  6.   (and (princ "\nSelect attributed blocks to change Attributes' layers to block's layer :")
  7.        (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))
  8.        ((Lambda (i / n)
  9.           (while (setq n (ssname s (setq i (1+ i))))
  10.             (foreach x (vlax-invoke (vlax-ename->vla-object n) 'getattributes)
  11.               (and (= (vla-get-tagstring x) "Code") (vla-put-layer x (cdr (assoc 8 (entget n)))))
  12.               )
  13.             )
  14.           )
  15.          -1
  16.          )
  17.        )
  18.   (princ)

tomohdi1969

  • Mosquito
  • Posts: 3
Re: Lisp to change Attribute Tags layer to the block layer
« Reply #4 on: November 13, 2023, 05:00:04 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ s)
  2.   ;;----------------------------------------------------;;
  3.   ;;    Author : Tharwat Al Choufi                      ;;
  4.   ;; website: https://autolispprograms.wordpress.com    ;;
  5.   ;;----------------------------------------------------;;
  6.   (and (princ "\nSelect attributed blocks to change Attributes' layers to block's layer :")
  7.        (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))
  8.        ((Lambda (i / n)
  9.           (while (setq n (ssname s (setq i (1+ i))))
  10.             (foreach x (vlax-invoke (vlax-ename->vla-object n) 'getattributes)
  11.               (and (= (vla-get-tagstring x) "Code") (vla-put-layer x (cdr (assoc 8 (entget n)))))
  12.               )
  13.             )
  14.           )
  15.          -1
  16.          )
  17.        )
  18.   (princ)

Thank you so much for the Code. It is working.