elfert Posted January 20, 2012 Posted January 20, 2012 Hello again I have a block name 'what ever' with some attribut values inside it and i need to replace the block with another block called not the same but the with the same tags and this means the same values inside. I don't want to selected the blocks because i know the names of the blocks. I just need a lisp routine that takes out values of a block with at specific name and replace this with another block with a specific name and put the values inside of this block and this block have to retain it insert point from the first block. thx in advance, from elfert. Quote
pBe Posted January 21, 2012 Posted January 21, 2012 Why not just redefine the block? Note: Attsync Quote
SELFCAD Posted January 24, 2012 Posted January 24, 2012 Maybe he has 100 blocks inserted in his drawing, and want to change only 20 blocks.... if he redefine the block, all 100 blocks will be changed... and maybe he doesn't want something like this... i don't know...i only guess Quote
elfert Posted January 24, 2012 Author Posted January 24, 2012 No i have one block that has some tags inside an this means some Values inside then i want to insert a another block from another file but with the same tags but i need to put the values from the first block to the new one without have to selecting the blocks because i know the the names of the 2 blocks because the names of the blocks i always the same. I found a lisp by searching by the net but in this i have to select the first and the target block. I could be good if the lisp routine remember the insertion point of the first block plus its Values and remembers it erase the block and insert the another block in the same place as the first block and put in the values from the first block to the target block. ;mtb copies attribute data from one block to other blocks with the same tags inside. write mtb to Run (defun C:mtb (/ baselist ename elist tag val i ss ename1 elist1) (setq baselist (list)) (while (not (setq ename (car (entsel "\nSelect Block:")))) (princ "\nNothing Picked")) (cond ( (assoc 66 (setq elist (entget ename))) (setq ename (entnext ename) elist (entget ename)) (while (= "ATTRIB" (cdr (assoc 0 elist))) (setq tag (cdr (assoc 2 elist)) val (cdr (assoc 1 elist)) baselist (append (list (list tag val)) baselist) ename (entnext ename) elist (entget ename)) ) (setq i -1 ss (ssget '((0 . "INSERT")(66 . 1)))) (repeat (sslength ss) (setq ename1 (ssname ss (setq i (1+ i))) ename1 (entnext ename1) elist1 (entget ename1)) (while (= "ATTRIB" (cdr (assoc 0 elist1))) (setq tag (cdr (assoc 2 elist1))) (if (assoc tag baselist) (entmod (subst (cons 1 (cadr (assoc tag baselist))) (assoc 1 elist1) elist1))) (setq ename1 (entnext ename1) elist1 (entget ename1)) ) ) ) ) (princ) ) Thx in advance, elfert Quote
AaronHolmes Posted March 6, 2012 Posted March 6, 2012 This might help, but you have to click on each block you want to replace, as well as hard-coding the block name and the attribute names from the previous block. I'm actually trying to figure out how to make it loop, getting all the blocks of a particular type and changing them all, but for now, I have to click on each of them. Good luck. -Aaron. ; REPLACE BLOCKS ; ; ; Use this with care, as the script will delete the selected block when it's run. ; This may not work as advertised - Use, as always, at your own risk. ; ; INSTRUCTIONS FOR USE: ; Before you load this file, determine the names of the attributes you need to extract. ; Replace the attribute names below with the names of the attributes in the blocks you want to replace, and save the file. ; ; Use <APPLOAD> to load the file. ; use <RTG> at the command line {think RoomTaG} to activate the command. ; Once you've started the command, it's designed to allow you to keep clicking on existing room tag blocks ; to replace each one without restarting the command. ; Use [esc] to get out of the routine. ; Make sure the active layer is the one you want the roomtag on. ; ; TROUBLESHOOTING: ; <attreq> must be set to 1 - That tells autocad to require attributes when you insert a block. ; If the script inserts a roomtag without attributes, this may be the culprit, otherwise check the attribute names. ; ROOMTAG.DWG must be present in the drawing. Just insert one if it's not there. You can immediately delete it. ; -This lisp routine does not know where to find the block, it assumes it's in the drawing. ; ; It uses the original insertion point of the previous block, so a little adjustment may be required ; once the new blocks have been inserted. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:RTG ( / ipt FIRSTATTRIBUTE SECONDATTRIBUTE) ;inspired in large part by http://www.jefferypsanders.com/autolispexp_enti.html ; The While command with no exit conditions lets you do this over and over again without restarting the command. (while (if (setq ent(entsel "\n Select a Block: ")) ;- Let the user select a block ;;Get the attribute list and set the variables. (progn (setq en(car ent)) ;- Get the entity name of the block (setq enlist(entget en)) ;- Get the DXF group codes (setq blkType(cdr(assoc 0 enlist))) ;- Save the type of entity (setq ipt (cdr (assoc 10 enlist))) ;- gets the insertion point of block, for use later during insert (if (= blkType "INSERT") ;- If the entity type is an Insert entity then do the following: (progn (if(= (cdr(assoc 66 enlist)) 1) ;- See if the attribute flag equals one (if so, attributes follow) (progn (setq en2(entnext en)) ;- Get the next sub-entity (setq enlist2(entget en2)) ;- Get the DXF group codes (while (/= (cdr(assoc 0 enlist2)) "SEQEND") ;- Start the while loop and keep looping until SEQEND is found. ;check to see if the attribute tag is the one we want, if so, set the variable. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;CHANGE THE NEXT LINE TO INCLUDE THE NAME OF THE ORIGINAL ATTIRIBUTE NAME IN THE BLOCK (if (= (cdr(assoc 2 enlist2)) "ORIGINAL-ATTRIBUTE-NAME1") (setq FIRSTATTRIBUTE (assoc 1 enlist2)) ) ;Check to see if the attribute tag is the one we want, if so, set the variable ;CHANGE THE NEXT LINE TO INCLUDE THE NAME OF THE ROOM NUMBER ATTRIBUTE IN THE BLOCK (if (= (cdr(assoc 2 enlist2)) "ORIGINAL-ATTRIBUTE-NAME2") (setq SECONDATTRIBUTE (assoc 1 enlist2)) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (princ) ;(princ "\n ") ;-Print a new line ;(princ enlist2) ;- Print the attribute DXF group codes (setq en2(entnext en2)) ;- Get the next sub-entity (setq enlist2(entget en2)) ;- Get the DXF group codes ) ) ) ;- Close the if group code 66 = 1 statement ) ) ;- Close the if block type = "ATTRIB" statement ) ) ;(setq ipt (getpoint "\nPick Insertion Point:")) - This line has been commented out, because the insertion point is read from the block. (command "-insert" "NEWBLOCK.DWG" "_NON" ipt "1" "1" "0" (CDR FIRSTATTRIBUTE) "" (CDR SECONDATTRIBUTE)) ;delete the original block (entdel en) );close the While loop (princ) ) 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.