Dj_T_Rex2002 Posted June 28, 2017 Posted June 28, 2017 Hi, I am trying to find the most simple way to use Blockreplace or Replace command. I know when you type Replace then Enter it asks you to select the block you want to replace it with but you have to type "=" then Enter to be able to select the block. THEN you have to select another block but still have to type "=" then Enter and select it... I'm trying to create a lisp code similar to this... (Defun C:RB1 (/ SS ) (SetQ SS (SSGet)) (Command "Replace" "=" SS SS "Y"))[code] Sorry if it did not wrap the code but I did click the "#" button and it did nothing. I can't remember how to wrap code in here. Wish there was an example. Quote
Dj_T_Rex2002 Posted June 28, 2017 Author Posted June 28, 2017 Hi, I am trying to find the most simple way to use Blockreplace or Replace command. I know when you type Replace then Enter it asks you to select the block you want to replace it with but you have to type "=" then Enter to be able to select the block. THEN you have to select another block but still have to type "=" then Enter and select it... I'm trying to create a lisp code similar to this... : (Defun C:RB1 (/ SS ) (SetQ SS (SSGet)) (Command "Replace" "=" SS SS "Y") ) /[code] Sorry if it did not wrap the code but I did click the "#" button and it did nothing. I can't remember how to wrap code in here. Wish there was an example. Quote
Jef! Posted June 28, 2017 Posted June 28, 2017 Hi DJ. For the code tags... [code] Your code here [/code] As a side note, in your try you substitute the old block for the same old block. (Command "Replace" "=" SS SS "Y") Also the way that function works, when you have to tell cad with what block you want to replace the original with, either you provide a string with the name of the block, or hit "=" and make a selection. As for using the replace command, I found out that that command have a very weird behavior (using 2015 here). When you launch "replace" it launches the "-BLOCKREPLACE" command. The strange thing is that I get this message "Unknown command "-BLOCKREPLACE". Press F1 for help." no matters the method I tried (command/command-s/vl-cmdf "-BLOCKREPLACE"). (same for trying to use "REPLACE" as a command/command-s or vl-cmdf). That is the 1rst time I see that kind of behavior. Basically what it seems to mean is that you might have to "mimic" the whole replace command. I'd help further but i'm in a hurry. Quote
Dj_T_Rex2002 Posted June 29, 2017 Author Posted June 29, 2017 Hi Jef, What I am trying to do with that command is click new block I am trying to replace with an existing one. Rather than deleting the old one, renaming the new one, and moving it to the insert point. I just want to know if there is a way to tell it "ok pause for a minute while I select the new block then select the old block". It asks me to press "=" Quote
SLW210 Posted June 29, 2017 Posted June 29, 2017 Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote
Tharwat Posted June 29, 2017 Posted June 29, 2017 Hi, Maybe this would of interest: REPLACE BLOCKS WITH ANOTHER Quote
Tharwat Posted June 30, 2017 Posted June 30, 2017 Great stuff Tharwat!!! Thank you halam. Happy to hear that. Quote
Aftertouch Posted June 30, 2017 Posted June 30, 2017 I have been having some problems with replacing blocks with lisp too, Biggest problem was to replace a NON-annotative block for a annotative block. I managed to fix this with a quite simple work-around. - Get the coordinates of the block - Insert new block on those coordinates - Delete old block That way to never have any problem with annotations. ; setq oldblocksome in a way you like first... ; setq newblocksome in a way you like first... (if (/= newblockname "") (progn (setq blockobjecten (ssget "_X" (list (cons 0 "INSERT")(cons 2 oldblockname)))) (setq n (sslength blockobjecten)) (repeat n (setq ensel (ssname blockobjecten (setq n (1- n)))) (setq enlist (entget ensel)) ;; Set DXF group codes (setq xyz (cdr (assoc 10 enlist))) ;; Set coordinates (command "-insert" newblockname xyz "1" "1" "") ) (command "ERASE" blockobjecten "") ) ) (This a a global replace code) Quote
halam Posted July 21, 2017 Posted July 21, 2017 I dedicated this page for the solution Tharwat provided. Maybe it can lead to some ideas for even improving it. Annotative blocks can be hard to handle. I think this is deep down AutoCAD behaviour which I can't fully understand. https://www.linkedin.com/pulse/autocad-block-tool-hans-lammerts Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.