Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Replace block on different layers with different blocks

2 REPLIES 2
Reply
Message 1 of 3
chrismathewsjr
304 Views, 2 Replies

Replace block on different layers with different blocks

Hello everyone!

 

I was able to write a LISP that replaced each node with a block of my choice.

 

However, now I need to find a way now to replace the blocks with different blocks.

 

Each point shares the exact same block called "PILE". Different blocks are on different layers and have 11 different colors. I'd like to replace blocks on layer 1 with a block called "1" and blocks on layer 2 with a block called "2" and so on.

I was hoping there would be an easy way to do this in LISP, but I've been unable to get any of my scripts to work.

 

I've attached a link that helps visualize what my drawing is currently looking like:

http://jooniorstudios.com/images/CAD/script.png


Thank you in advance for your advice!

 

~Chris Jr.

 

2 REPLIES 2
Message 2 of 3


@chrismathewsjr wrote:

.... I need to find a way now to replace the blocks with different blocks.

 

Each point shares the exact same block called "PILE". Different blocks are on different layers and have 11 different colors. I'd like to replace blocks on layer 1 with a block called "1" and blocks on layer 2 with a block called "2" and so on.

....


This seems to do that [minimally tested]:

 

(foreach blk (mapcar 'cadr (ssnamex (ssget "_X" '((2 . "PILE")))))
  (setq
    edata (entget blk)
    edata (subst (cons 2 (cdr (assoc 8 edata))) '(2 . "PILE") edata)

      ;; puts Layer name into Block-name slot
  ); setq
  (entmod edata)
)

 

Whether there are any other aspects to be dealt with, such as scales and/or rotation, we don't know enough yet to say.

Kent Cooper, AIA
Message 3 of 3

Elegant and beautiful solution, thank you for the help Kent.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost