AutoCAD Redefine Blocks Bulk

AutoCAD Redefine Blocks Bulk

kieran.leadbetter
Advocate Advocate
2,397 Views
18 Replies
Message 1 of 19

AutoCAD Redefine Blocks Bulk

kieran.leadbetter
Advocate
Advocate

Hello, would anyone know how of a lisp which will redefine a block if it exists within another drawing.

I have 500+ Blocks in a master file which contain blocks which need to be updated regularly, and as there are so many it makes it difficult to use design centre to redefine a block with so many block names.

So hoping a more easier solution is, if blocks in drawing A exist, then update/redefine block to match drawing B (Master File).

I have spent all day looking at programs like WBlock, BlockUpdate, BlockOut, but none complete the task smoothly. My original plan was to somehow bulk-xref all the blocks in the master file to individual xrefs, meaning I could still open the drawing and copy the blocks where required, and if the block updates, it will be automatically updated in any other relevant drawing.

Please help me with this if anyone can,
Kind Regards

0 Likes
Accepted solutions (1)
2,398 Views
18 Replies
Replies (18)
Message 2 of 19

pendean
Community Legend
Community Legend
Just INSERT the not-updated drawing A into the uber-updated Drawing B, then SAVEAS to create a new drawing A version2.0

That's it.
0 Likes
Message 3 of 19

kieran.leadbetter
Advocate
Advocate

Hello, sorry for the late reply, I thought I had sent a reply this morning.

This wouldn't work, I am attempting to make this an automated task due to the quanity of drawings which will be required in future as well as drawings being linked to others and such. 

0 Likes
Message 4 of 19

pbejse
Mentor
Mentor

Redefining the blocks by bulk is definitely doable.
 
Xrefs will work the best for your requirement @kieran.leadbetter , is it too late to do that now?  

i’m thinking if that can also be done programagically.

 

 

Message 5 of 19

ronjonp
Mentor
Mentor

@kieran.leadbetter You could try the code HERE. It requires your 500+ blocks to be separate drawings within AutoCAD's search path to work.

 

You can use this code to extract them from your template:

(defun c:exportblocks (/ p)
  (setvar 'cmdecho 0)
  (setq p (strcat (getvar 'dwgprefix) "_ExportedBlocks\\"))
  (vl-mkdir p)
  (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (if	(= 0 (vlax-get b 'isxref) (vlax-get b 'islayout))
      (command "._-wblock" (strcat p (vla-get-name b) ".dwg") (vla-get-name b))
    )
  )
  (setvar 'cmdecho 1)
  (alert p)
  (princ)
)
Message 6 of 19

kieran.leadbetter
Advocate
Advocate
It's not too late, I was attempting to do this but was uncertain of how to set this up, every single block would be required to be an xref,

Drawing A - Original and gets drawn in
Drawing B - Everyblock is a unique xref to drawing A, as well as matching coordinates
Drawing C - Any drawings I work across in future, links into drawing B, allowing me to freely edit Drawing A without damaging any xref stuff

I can't xref via file names however, I would need to xref via the blocks otherwise it would take way too long to work with

Any ideas on how to set this up
0 Likes
Message 7 of 19

kieran.leadbetter
Advocate
Advocate
The exporting all blocks lisp works like a charm, however when I run that code from the link you gave, nothing happens, it runs the command, but nothing afterwards
Command Promt shows:

Command: foo
Command:
0 Likes
Message 8 of 19

pbejse
Mentor
Mentor

@kieran.leadbetter wrote:
Drawing A - Original and gets drawn in
Drawing B - Everyblock is a unique xref to drawing A, as well as matching coordinates
Drawing C - Any drawings I work across in future, links into drawing B, allowing me to freely edit Drawing A without damaging any xref stuff

Post a sample drawing and let's see what other forum members come up with.

 

 

Message 9 of 19

kieran.leadbetter
Advocate
Advocate
It's more the process that I need to understand, I can't upload the blocks as they are security sensitive to the client I work for.

This template would have the same implications however, just not the correct blocks
0 Likes
Message 10 of 19

pbejse
Mentor
Mentor

@kieran.leadbetter wrote:
This template would have the same implications however, just not the correct blocks

What template are you referring to?
You mean the drawing attachment at post #1?

 


@kieran.leadbetter wrote:
f blocks in drawing A exist, then update/redefine block to match drawing B  (Master File )

Drawing A and drawing B currently open?  

Can we assume Block Insertion point will remain the same?

 

Message 11 of 19

kieran.leadbetter
Advocate
Advocate
The insertion point should remain the same yes, this xref method is a last resort however

I just learned you can not xref a dynamic block without losing its dynamic abilities, more than half of these blocks are dynamic
0 Likes
Message 12 of 19

pbejse
Mentor
Mentor

@kieran.leadbetter wrote:
I just learned you can not xref a dynamic block without losing its dynamic abilities, more than half of these blocks are dynamic

You are absolutely right. there will be complications. what about that template you're referring to, how complex is this Dynamic block of yours.

 

Message 13 of 19

kieran.leadbetter
Advocate
Advocate

Quite, its 4 blocks for an orthographic drawing pack, every block contains some aspect of dynamic block, some just stretch some lines, but some others control visibilities which then some contain 8 within the block

Its a large task which is why I'm trying to automate what I can.

As Xref won't be a possiblity now, the most efficient way I can think is to find some sort of method to batch Redefine Blocks like I initially intended, but for some reason no lisp I use or external program seems to work

0 Likes
Message 14 of 19

Ranjit_Singh_WA
Participant
Participant

Hello @ronjonp / @pbejse, I have came across couple broken LISPs (attached), but I am not a programmer, so dont know how to fix this lisp.

 

It was created for user to select the source drawing, block, and then multiple destination drawings in a dialog box. After the selections, it updates and redefines the block at its own insertion point in the chosen destination drawings. To exit the selection of destination drawings, press Enter.

 

Would you think this might be a start and may fix this to get things automated, please.

0 Likes
Message 15 of 19

ronjonp
Mentor
Mentor

@kieran.leadbetter Did you add that _ExportedBlocks folder to AutoCAD search path? If not the code cannot find them.

Message 16 of 19

kieran.leadbetter
Advocate
Advocate
Morning, yes but for some reason it does nothing, I put in the file path where it says *|*

(defun c:Redef (/ file out)
(vlax-for x (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(if (not (wcmatch (strcase (vla-get-name x)) "C:\Users\KL\Desktop\_ExportedBlocks"))
(setq out (cons (vla-get-name x) out))
)
)
(setvar 'cmdecho 0)
(foreach x out
(if (setq file (findfile (strcat x ".dwg")))
(progn (command ".-INSERT" (strcat x "=" file) nil)
(and (ssget "_x" (list '(0 . "insert") (cons 2 x) '(66 . 1)))
(command "._attsync" "name" x)
)
)
)
)
(setvar 'cmdecho 1)
(princ)
)
0 Likes
Message 17 of 19

ronjonp
Mentor
Mentor
Accepted solution

@kieran.leadbetter Try this. Note you have to put double backslashes in paths for lisp. The WCMATCH "*|*" prevents using blocks that are within xrefs.

 

(defun c:redef (/ file out path)
  (setq path "C:\\Users\\KL\\Desktop\\_ExportedBlocks\\")
  (vlax-for x (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (if	(not (wcmatch (strcase (vla-get-name x)) "*|*"))
      (setq out (cons (vla-get-name x) out))
    )
  )
  (setvar 'cmdecho 0)
  (foreach x out
    (if	(setq file (findfile (strcat path x ".dwg")))
      (progn (command ".-INSERT" (strcat x "=" file) nil)
	     (and (ssget "_x" (list '(0 . "insert") (cons 2 x) '(66 . 1)))
		  (command "._attsync" "name" x)
	     )
      )
    )
  )
  (setvar 'cmdecho 1)
  (princ)
)

 

 

Message 18 of 19

kieran.leadbetter
Advocate
Advocate
You sir are a godsend, it works perfectly, even functions perfect with dynamic block (doesn't change visibilities or override anything else)

Thank you so much, and thank you everyone else for your help also

Would you be able to explain why it requries a double \\ on the path links
0 Likes
Message 19 of 19

ronjonp
Mentor
Mentor

@kieran.leadbetter Glad to help! The double backslash is an escape character for \. Read HERE.

 

Paste this into the command line for a quick visual interpretation.

(alert "C:\Temp")
(alert "C:\\Temp")

0 Likes