Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
New Member
chrismathewsjr
Posts: 2
Registered: ‎06-20-2012
Message 1 of 3 (165 Views)

Replace block on different layers with different blocks

165 Views, 2 Replies
06-20-2012 11:24 AM

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.

 

*Expert Elite*
Kent1Cooper
Posts: 5,611
Registered: ‎09-13-2004
Message 2 of 3 (158 Views)

Re: Replace block on different layers with different blocks

06-20-2012 12:13 PM in reply to: chrismathewsjr

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
New Member
chrismathewsjr
Posts: 2
Registered: ‎06-20-2012
Message 3 of 3 (147 Views)

Re: Replace block on different layers with different blocks

06-20-2012 03:15 PM in reply to: Kent1Cooper

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.