Replace blocks in drawing with block from file with same name

Replace blocks in drawing with block from file with same name

richie_hodgson
Collaborator Collaborator
5,655 Views
6 Replies
Message 1 of 7

Replace blocks in drawing with block from file with same name

richie_hodgson
Collaborator
Collaborator

Hi I am a bit flumoxed with something that should be simple. I am trying to replace a bunch of blocks with a block from a file with the same name, so something like

 

(command "_insert" "C:\CAD\lib\Baseplan Symbols\TOBY" "Y" "0,0" "1" "1" "0" )
(COMMAND "ERASE" "L" "")

 

Where "Y" is to replace existing blocks with the nameTOBY with the drawing called TOBY, so far nothing I have done is doing it. It just inserts a block like the one in the drawing.

 

You can do it using INSERT in autocad so it should be simple....

Richie
0 Likes
Accepted solutions (1)
5,656 Views
6 Replies
Replies (6)
Message 2 of 7

marko_ribar
Advisor
Advisor

Make sure TOBY.DWG don't have inside its body block named TOBY... Set sysvar BASE to point of insertion of DWG TOBY in relation to insertions of TOBY blocks in your opened DWG with blocks TOBY... Save TOBY DWG without block TOBY - it should have only geometry representing TOBY.DWG as you'd like to insert...

 

Try to change this line :

(command "_insert" "C:\CAD\lib\Baseplan Symbols\TOBY" "Y" "0,0" "1" "1" "0" )

 

To this :

(command "_.-insert" "C:\\CAD\\lib\\Baseplan Symbols\\TOBY.DWG" "Y" "0,0" "1" "1" "0")

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 7

3wood
Advisor
Advisor

You can also try BLOCKUPDATE.

 

0 Likes
Message 4 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

@richie_hodgson wrote:

.... 

(command "_insert" "C:\CAD\lib\Baseplan Symbols\TOBY" "Y" "0,0" "1" "1" "0" )
(COMMAND "ERASE" "L" "")

 

Where "Y" is to replace existing blocks with the nameTOBY with the drawing called TOBY, so far nothing I have done is doing it. It just inserts a block like the one in the drawing.

....


To reach outside for a redefinition of a Block to an external drawing, use the Blockname=Drawingname format:

 

(command "_insert" "TOBY=C:\CAD\lib\Baseplan Symbols\TOBY" "Y" nil)

 

By the time it has been told to go ahead and update the definition, that has been replaced, and there is no need to complete the Insertion and then Erase it -- the nil cancels the command.  Besides, finishing the Insertion and then Erasing the Last object will Erase something else [the last thing visible] if that Insertion at 0,0 is not at least partially visible in the current view.

 

If that drawing is in a Support File Search Path location, you don't need to give it the path, or even the name again:

 

(command "_insert" "TOBY=" "Y" nil)

Kent Cooper, AIA
0 Likes
Message 5 of 7

richie_hodgson
Collaborator
Collaborator

Hi Kent

 

I found some wonderful code from Lee Mac - redefall (Thank you Lee) which does what I was looking for before I read your post. I am about to test your code since it is nicely simplified so I can use it in future codes.

 

Ok it doesnt respond to (command "_insert" "TOBY=C:\CAD\lib\Baseplan Symbols\TOBY" "Y" nil)  ; error: Function cancelled

but does like (command "_insert" "TOBY=" "Y" nil) once the support file path has been set so I am happy to run with that.  

 

Regards

 

Richie

Richie
0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@richie_hodgson wrote:

.... 

Ok it doesnt respond to (command "_insert" "TOBY=C:\CAD\lib\Baseplan Symbols\TOBY" "Y" nil)  ; error: Function cancelled

...


I should have noticed that before....  Because of the use of a backslash as a control character in text strings in AutoLisp, try using either a double backslash for a filepath separator:

 

(command "_insert" "TOBY=C:\\CAD\\lib\\Baseplan Symbols\\TOBY" "Y" nil)

 

or a single forward slash:

 

(command "_insert" "TOBY=C:/CAD/lib/Baseplan Symbols/TOBY" "Y" nil)

 

You'll see countless examples of this in code on these Forums.  If I had modified @marko_ribar's suggestion [which uses the double backslashes] in Post 2 instead of your original, it would have been okay.

Kent Cooper, AIA
0 Likes
Message 7 of 7

richie_hodgson
Collaborator
Collaborator

Hi Kent

 

I am a bit dislexic so back slashes and forward slashes can get a little confusing so I cut and paste quite a bit and that wasn't working yesterday for some reason or other. Things are working today, that last code snippit worked just fine so confusion is over. Thanks for your efforts.

 

Regards

 

Richie

Richie
0 Likes