;1.0 6/26/2014 ; (prompt " COPYCAT.lsp\n") ;;;Important variables ;blkname1 = name of block to modify ;attFROM = attribute tag within blkname1 to copy from ;attTO = attribure tag within blkname1 to copy to ;FROMvalue = value of attFROM ;TOvalue = value of attTO (defun C:COPYCAT () ;defines function w/ no variable (setvar "cmdecho" 0) ;turns off echoing (setq I 0) ;sets variable I to zero (setq blkname1 (getstring "\nBlock name: ")) ;sets blkname1 to user prompted input (setq attFROM (getstring "\nFROM attribute tag: ")) ;sets attFROM to user prompted input (setq attTO (getstring "\nTO attribute tag: ")) ;sets attTO to user prompted input (setq sset (ssget "x" (list (cons 2 blkname1)))) ;list created, add 2 to front of blockname to create list to create (2 . blkname1) ;select(get) everything that is (2 . blkname1) which is (insert with name blkname1) ;set "sset" to the selected block or blocks (if (= sset nil)(setq l 0) ;if nothing selected, set l to zero (setq l (sslength sset))) ;set l to the integer length of sset (number of blocks that were selected) (repeat l ;repeat everything after this for 'l' number of blocks ;;Find FROM attribute in current block and copy it ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq stop 1) ;set 'stop' to 1 (setq name (ssname sset I)) ;set 'name' to the entity ID name of the first(i=0) of selection 'sset' ;i.e this is the first block's entity name (while (= stop 1) ;while 'stop' is equal to 1 (setq name1 (entget (entnext name))) ;set name1 to the entity's definition (tag) of the next attribute in "name" (block) (setq ATT (cdr (assoc 2 name1))) ;set 'ATT' to everything after the first thing in list, which is anything with (2=att TAG) (if (= ATT attFROM)(setq go 1)) ;if 'att' is the name of attribute to copy, then set 'go' to 1 (setq name (cdr (assoc -1 name1))) ;don't actually know what's going on here (while (= go 1) ;if we found the correct attribute ('go' = 1), then do what's after this (setq FROMvalue (assoc 1 name1)) ;set 'FROMvalue' to the value of (1=attribute VALUE) in attribute 'name1' (setq go nil) ;set 'go' to nil (setq stop nil) ;set 'stop' to nil ) ;end 'go' while loop ) ;end 'stop' while loop ;;Find TO attribute in current block and replace it with FROMvalue ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq stop 1) ;set 'stop' to 1 (setq name (ssname sset I)) ;set 'name' to the entity ID name of the first(i=0) of selection 'sset' ;i.e this is the first block's entity name (while (= stop 1) ;while 'stop' is equal to 1 (setq name1 (entget (entnext name))) ;set name1 to the entity's definition (tag) of the next attribute in "name" (block) (setq ATT (cdr (assoc 2 name1))) ;set 'ATT' to everything after the first thing in list, which is anything with (2=att TAG) (if (= ATT attTO)(setq go 1)) ;if 'att' is the name of attribute to change, then set 'go' to 1 (setq name (cdr (assoc -1 name1))) ;don't know what's going on here (while (= go 1) ;if we found the correct attribute ('go' = 1), then do what's after this (setq TOvalue (assoc 1 name1)) ;set 'TOvalue' to the selected value to overwrite (setq d1 (subst TOvalue FROMvalue name1)) ;set d1 to a new list that substitutes FROMValue(new value) for TOvalue(old attribute value) in list name1(attribute entity) (entmod d1) ;update d1 list database which will update the attribute and block (setq go nil) ;set 'go' to nil (setq stop nil) ;set 'stop' to nil ) ;end 'go' while loop ) ;end 'stop' while loop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq i (1+ i)) ;i++ so it will go to the next block in the selection set ) ;end repeat loop (command "_regen") ;regen the drawing (princ);blank line i guess );ends routine