Hi everyone, I have looked for something similar here but have not succeeded.
I have several drawings in a folder that I need to open one by one, delete a block, purge the block, and finally paste the new block version.
The new block version is in another dwg, which I copied with the base point 0,0. The pasting is in the same coordinate, 0,0. All the blocks (the new version) and the old to be replaced have the same name and are located in the layout at 0,0 (not in the model). I do need to run the purge command after deleting so the block is pated with the new changes.
I'm wondering if any of you have an LISP file that can help me automate this process.
The inputs could be the Block name, the route of the new block version, and the folder route with the other drawings where the block will be replaced. Another option could be that the lisp is executed over the drawings opened in the current session, and the new block is taken from the active drawing where the command is executed.
Solved! Go to Solution.
Solved by DGCSCAD. Go to Solution.
A couple of questions:
Does the original block have attributes, and if so, do you want to perserve those values ?
A lisp can be made to swap out the 'old' block with a 'new' block by selecting the 'old'
blockname (foreach Layout), and checking the insert point, and scale factor. Then,
if you have the replacement block wblocked somewhere, it can be inserted in the same location
and scale factor. The question is, if the old block has attributes or not.
Or, updating the 'same' blockname can be done with a simple (command "_-insert" Blockname= ... type block update.
Could you post a sample drawing before / after ?
ECCAD
I pieced this together with some code I had and some from Lee Mac.
Instructions:
Lightly tested.
I think this line:
(setq scrline (strcat "open" " " n2 " " "(load\"batcher\")" " " "batcher_insert" " " "qsave" " " "close"))
Should have (c:batcher_insert) .. maybe.
ECCAD
@jesusrperezd wrote:
Hi, pkenewell6347. No, I haven't tried it. So, wil the script run over all the drawings i select? Thanks for your time!
Nevermind on that. Both blocks need to be in the drawing and named differently with BLOCKREPLACE.
@ec-cad wrote:I think this line:
(setq scrline (strcat "open" " " n2 " " "(load\"batcher\")" " " "batcher_insert" " " "qsave" " " "close"))
Should have (c:batcher_insert) .. maybe.
ECCAD
It's not inside a function, so normal command call. The scrline variable is a string that is setting the script.
Thanks for doing this.
I opened the file and saw the line:
(setq blk_ss (ssget "_X" '((0 . "INSERT") (2 . "YourBlockName"))));;;<-----Replace YourBlockName with your actual block name. Use \\ if a path is needed, i.e.: C:\\YourPath\\YourBlockName
My new block is named 'TMP' (it is always the same name). I understand that If the new block is in the active drawing, I just write "TMP" ("YourBlockName"), if the block is in another route I write the route, let's say "C:\\Users\JP\Desktop\tes lisp\xxf.dwg\TMP" .
Did I understand this well?
Another question, I saw 2 execution commands Batcher and Batcher_insert, I suppose I have to execute only the Batcher, is that correct? I'm trying to find a step-by-step process.
thanks again!
@jesusrperezd wrote:Thanks for doing this.
I opened the file and saw the line:
(setq blk_ss (ssget "_X" '((0 . "INSERT") (2 . "YourBlockName"))));;;<-----Replace YourBlockName with your actual block name. Use \\ if a path is needed, i.e.: C:\\YourPath\\YourBlockName
My new block is named 'TMP' (it is always the same name). I understand that If the new block is in the active drawing, I just write "TMP" ("YourBlockName"), if the block is in another route I write the route, let's say "C:\\Users\JP\Desktop\tes lisp\xxf.dwg\TMP" .
Did I understand this well?
Another question, I saw 2 execution commands Batcher and Batcher_insert, I suppose I have to execute only the Batcher, is that correct? I'm trying to find a step-by-step process.
thanks again!
You are on the right track. Assuming you have your folder of drawings already backed-up:
Step-by-Step Instructions:
@jesusrperezd wrote:... if the block is in another route I write the route, let's say "C:\\Users\JP\Desktop\tes lisp\xxf.dwg\TMP" !
Also, the quoted text in red above doesn't seem like a valid directory. You'll need to change that line to the real valid directory, but use double backslashes for each folder level, as in:
C:\\Users\\JP\\tes lisp\\BLOCKNAMEHERE
...where BLOCKNAMEHERE is the block name TMP.
@jesusrperezd wrote:
Hi ec-cad. The original block has attributes, as well as the new one, but I don't care about losing the values loaded on the attributes. I have a routine that I can run so all the attributes will be filled again quickly.
The insert point is the same for both (0,0). The scale factor is 1. The dwg files only have a layout
Thanks for your time!
Just saw this pertinent information. That'll throw a monkey wrench into the gears. The insert command call will need to have the attributes taken into consideration.
Im sorry I got an error. It happens after it opens the first drawing.
. Please check the message I got:
Enter name of drawing to open <C:\Users\JP\Desktop\tes lisp\241206\N2P13947.01.dwg>: "C:\Users\JP\Desktop\tes lisp\241206\N2P13947.01.dwg"
Opening an AutoCAD 2018 format file.
Regenerating layout.
Regenerating model.
AutoCAD menu utilities loaded.
Command:
Autodesk DWG. This file is a TrustedDWG last saved by an Autodesk application or Autodesk licensed application.
Command:
Command:
Command: (load"batcher") ; error: LOAD failed: "batcher"
Command: batcher_insert Unknown command "BATCHER_INSERT". Press F1 for help.
Yes, it's in a script. BUT, the script must load "batcher_block", not "batcher", and
to call the Command function inside batcher_block, you will have to do "(C:batcher_insert)",
So the whole line =:
(setq scrline (strcat "open" " " n2 " " "(load\"batcher_block\")" " " "(C:batcher_insert)" " " "qsave" " " "close"))
To avoid the Attributes, just before the (command "_-insert" ...... line - add (setvar 'attreq 0), as in:
(foreach n ins_list
(setvar 'attreq 0)
(command "-insert" "YourBlockName" n "" "" "")
The lisp file should be placed in a support path for input.
And, the block insert may need a formal 'path/path/blockname as well.
ECCAD
Yes, ec-cad has the correct command call for (load\"batcher_block\"). My apologies, it was an oversight on my part.
The command call for (c:bacher_insert) can be called either way. It will be called at the command line on each drawing, so it can be called using it's localized command call name, or in parenthesis.
For the ATTREQ, I'd set that before the foreach, then reset it back to what it was after the insert(s).
...and yes, Batcher_Block.lsp needs to be located on a support/trusted path. Lots of little things need to be in place, but when they are it'll get you the results you're after. I've been using variations of this batch routine for a long time, so I tend to glaze over the important stuff that I have already set.
I can get to this tomorrow with an updated lisp file if noone else posts up a solution.
@ec-cadThank you for the revisions! Was speed posting.
Also, if you could post the actual file location/folder of the TMP block, we can hard code that and make sure it's correct.
If you already have the new block saved out into a folder location then would it not be as simple as using the built-in command of Insert blockname=pathofdwg.
For example if the block inside the current dwg is named "My Block" and the newer version is saved under C:\Autodesk\My Block.dwg, then the following lisp code should replace the old with the new whether in Model or Layout:
(command "_.INSERT" "My Block=C:\\Autodesk\\My Block" \E)
@paullimapa wrote:If you already have the new block saved out into a folder location then would it not be as simple as using the built-in command of Insert blockname=pathofdwg.
For example if the block inside the current dwg is named "My Block" and the newer version is saved under C:\Autodesk\My Block.dwg, then the following lisp code should replace the old with the new whether in Model or Layout:
(command "_.INSERT" "My Block=C:\\Autodesk\\My Block" \E)
I had no idea. Thats amazing. What is the \E switch for?
Can't find what you're looking for? Ask the community or share your knowledge.