Hello all. I'm trying to write a LISP routine and I'm not very good at it. I was wondering if I could ask for help.
I'm trying to write a LISP that will copy the value from one attribute to another, all within the same block. I've found a LISP similar online, but it uses screen clicks. I want to use this in a script so the LISP has to use command prompts. I'd like the command line prompts to go like this:
1. Block name?
2. FROM attribute tag?
3. TO attribute tag?
I've attached a copy of the code. I don't know where I'm going wrong. Can someone take a look at it? Thanks.
-Justin
@Anonymous wrote:Hello all. I'm trying to write a LISP routine and I'm not very good at it. I was wondering if I could ask for help.
I'm trying to write a LISP that will copy the value from one attribute to another, all within the same block. I've found a LISP similar online, but it uses screen clicks. I want to use this in a script so the LISP has to use command prompts. I'd like the command line prompts to go like this:
1. Block name?
2. FROM attribute tag?
3. TO attribute tag?
I've attached a copy of the code. I don't know where I'm going wrong. Can someone take a look at it? Thanks.
-Justin
Ok, this has very little error catching and even less testing, but it should work as requested.
(DEFUN GET-ATT (tag blk / val enx) ; Thank you Lee Mac (SETQ blk (SSNAME (SSGET "x" (LIST '(0 . "INSERT") (CONS 2 blk) (CONS 410 (GETVAR 'ctab)))) 0)) (WHILE (AND (NULL val) (= "ATTRIB" (CDR (ASSOC 0 (SETQ enx (ENTGET (SETQ blk (ENTNEXT blk))))))) ) (IF (= (STRCASE tag) (STRCASE (CDR (ASSOC 2 enx)))) (SETQ val (CDR (ASSOC 1 enx))) ) ) ) (DEFUN PUT-ATT (blk tag val / end enx) ; Again, thank you Lee Mac (SETQ blk (SSNAME (SSGET "x" (LIST '(0 . "INSERT") (CONS 2 blk) (CONS 410 (GETVAR 'ctab)))) 0)) (WHILE (AND (NULL end) (= "ATTRIB" (CDR (ASSOC 0 (SETQ enx (ENTGET (SETQ blk (ENTNEXT blk)))))))) (IF (= (STRCASE tag) (STRCASE (CDR (ASSOC 2 enx)))) (IF (ENTMOD (SUBST (CONS 1 val) (ASSOC 1 enx) enx)) (PROGN (ENTUPD blk) (SETQ end val)) ) ) ) ) (DEFUN COPY-ATT (BLOCKNAME FROMatt TOatt / VALUE) ; You mentioned scripting and so I put a function. (SETQ VALUE (GET-ATT FROMatt BLOCKNAME)) (PUT-ATT BLOCKNAME TOatt VALUE) ) (DEFUN C:COPY-ATT (/ BLOCKNAME FROMatt TOatt) ; The main command :: uses the function. (SETQ BLOCKNAME (GETSTRING "\n\t=> Block name? ") FROMatt (GETSTRING "\n\t=> FROM attribute tag? ") TOatt (GETSTRING "\n\t=> TO attribute tag? ") ) (IF (TBLSEARCH "BLOCK" BLOCKNAME) (COPY-ATT BLOCKNAME FROMatt TOatt) (PRINC "\n BLOCK NOT FOUND")) )
(By The Way the borrowed functions from Lee Mac can be found on his website HERE:-> http://www.lee-mac.com/attributefunctions.html )
You sir, are awesome. Thanks for putting that together. Works great. I see that it doesn't find multiple instances of the same blocks though. In my original code you can see a repeat loop in there to go through every found block name. But this works fantastic. I think I can modify it to take care of multiple blocks. And thanks for the website link. Very useful.
mid-awe, thanks again for your help.
I've modified the code you gave me to update all blocks in the drawing with the same name. I've attached it to this post so others can use it.
Your original code will find the first instance of the block and modify it (useful for something like a titleblock because there really shouldn't be more than 1 titleblock in a drawing.)
The attached code will find all instances of the block name in the drawing and update all of them, even across model space and layouts.
This way, one can pick which lisp works best for them. Always good to have choices.
Have a great day.