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 (157 Views)

Replace block on different layers with different blocks

157 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,237
Registered: ‎09-13-2004
Message 2 of 3 (150 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 (139 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community