TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: domenicomaria on February 06, 2023, 05:55:15 AM

Title: replace blocks with the same name
Post by: domenicomaria on February 06, 2023, 05:55:15 AM
I need to replace a dozen blocks
with dwgs having the same name

When I try to insert the new blocks
obviously acad says :
Duplicate definition of block XXXXX ignored

So the block is not replaced.

Are there some system variables to change
to get what I want ?

Is there any trick, any idea?

I can imagine that there can be many solutions to get around the obstacle

. . .

but before starting to write something,
I'm curious to know if there is already a simple and immediate way

Title: Re: replace blocks with the same name
Post by: Marc'Antonio Alessi on February 06, 2023, 06:13:58 AM
You can control block insertion behavior using the following methods:
Title: Re: replace blocks with the same name
Post by: domenicomaria on February 06, 2023, 11:54:00 AM
marco I had tried with the asterisk
in this way
(command "insert" "c:\\xxxxxx\\yyyyy\\*block-01.dwg" . . .)

but that doesn't work

instead, the asterisk must be placed at the beginning
(command "insert" "*c:\\xxxxxx\\yyyyy\\block-01.dwg" . . .)
and so it works

A thousand thanks

ciao
Title: Re: replace blocks with the same name
Post by: mhupp on February 06, 2023, 11:57:55 AM
Quote
Updating a Block Definition: If you make changes to a block file that is inserted in your drawing and you want to change the existing block definition without creating a new block insertion, enter the following at the Insertion Point prompt (following the Block Name prompt):block name=

Code - Auto/Visual Lisp: [Select]
  1. (command "insert" "block-01=") ;this might work if left blank
  2. (command "insert" "block-01=c:\\xxxxxx\\yyyyy\\block-01.dwg") ;update block-01.

just make sure the block insertion point is in the same location or your blocks will shift.

--Edit
Code - Auto/Visual Lisp: [Select]
  1. (defun C:BLKUPDATE (/ ss BLKNAME)
  2.   (princ "\nSelect Block to Update: ")
  3.   (while (setq ss (ssget "_+.:S:E:L" '((0 . "INSERT")))) ;select block that isn't on a locked layer
  4.     (setq BLKNAME (cdr (assoc 2 (entget (ssname ss 0)))))
  5.     (command "insert" (strcat blockname "="))
  6.     (prompt (strcat "\n" BLKNAME " Updated"))
  7.   )
  8.   (princ)
  9. )
Title: Re: replace blocks with the same name
Post by: domenicomaria on February 06, 2023, 01:10:48 PM
@mhupp

(command "insert" "block-01=c:\\xxxxxx\\yyyyy\\block-01.dwg")

it works !

Thanks

ciao