Greetings all,
I am finishing up a long lisp routine that standardizes a Layout, Title Block and Revision Block, and I seem to stuck with the final icing on the cake, so to speak.
(Also I can't seem to figure out how to properly post autolisp code, so forgive me if I posted my code improperly.... and I did search for how to do it properly.)
Basically this routine adds a new Layout with said Title Block and one Rev Block (and a Viewport) properly configured. It swiches to the improper (old) Layout with same blocks, only the exisinting blocks are often filled in with good information.
It then copies all the blocks from the existing (source) Layout, switches to the New Layout and pastes them at an offset 2 inches to the right because of our vertical title block. It then grabs all the Ent Names necessary to copy attributes.
Then at the very end, where I modified a pretty standard lisp I've used for years and included it as my sub function. My first call to copy all the Attributes from the old Insert to the new title block Insert works like a charm, but the subsequent calls to copy Attributes from my 2 Rev Blocks don't work. The original COPYATTR.LSP has you select the old block, new block and works perfectly from the command prompt.
(Maybe someone can point me to one that works from Ent Names, or I may just write my own, but I'm trying to get the project off my desk... full disclosure here: I've looked at it too long.)
The messages print, indicating that the code ran, but the target Rev Blocks don't get the Source Rev Block attributes. What am I missing?
And I know there's some junk in here still for troubleshooting, I'll clean it up.
Thanks, Bill~
Code:
(copyattr SrcTbEname TargetTbEName)
(princ "\nTitleBlock Attributes copied...\n")
(copyattr SrcRevBlk1Ename TargetRevBlk1Ename)
(princ "\nRevision Block 1 Attributes copied...\n")
(cond ((= 3 BlkCnt)
(copyattr SrcRevBlk2Ename TargetRevBlk2Ename)
(princ "\nRevision Block 2 Attributes copied...\n")
)
((= 4 BlkCnt)
(copyattr SrcRevBlk2Ename TargetRevBlk2Ename)
(copyattr SrcRevBlk3Ename TargetRevBlk3Ename)
)
((= 5 BlkCnt)
(copyattr SrcRevBlk2Ename TargetRevBlk2Ename)
(copyattr SrcRevBlk3Ename TargetRevBlk3Ename)
(copyattr SrcRevBlk4Ename TargetRevBlk4Ename)
)
) ;cond
(setvar "cmdecho" cmde)
(setvar "attdia" attdia)
(princ)
) ;defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TIP1045B.LSP: COPYATTR.LSP Attribute Utilities (C)1994, Robert L. Zipprich
(defun copyattr (BLK1 BLK2 / BLK1 BLK2 DATA1 DATA2 BLKNAME INSPT BLKENT SWDATA)
; BLK1 is source block with attributes to copy
; Blk2 is new target block to get attributes from the original source block
(setq EBLK1 BLK1) ; to erase old block
(setq DATA1 (entget BLK1))
(setq DATA2 (entget BLK2))
; (setq BLK2 TargetTbEname DATA2 TargetTbData) ;primes the pump
; (setq BLKNAME (cdr (assoc 2 (entget EBLK1)))
(setq BLKNAME (cdr (assoc 2 (entget BLK1)))
INSPT (cdr (assoc 10 (entget BLK2)))
)
;---------------
(setq BLK1 (entnext BLK1) DATA1 (entget BLK1)) ;primes the pump
(while (/= "SEQEND" (cdr (assoc 0 DATA1))) ;steps from ent to ent in 1st blk
(if (setq TAGNAME1 (cdr (assoc 2 DATA1))) ;if ent is attrib
(progn
(setq SWDATA (cdr (assoc 1 DATA1))) ;1st attrib value
(setq BLKENT (entnext BLK2) DATA2 (entget BLKENT)) ;next ent in 2nd blk
(while (/= "SEQEND" (cdr (assoc 0 DATA2)))
(if (eq TAGNAME1 (cdr (assoc 2 DATA2))) ;if tags match
(progn
(Setq DATA2 (subst (cons 1 SWDATA) (assoc 1 DATA2) DATA2))
(entmod DATA2) ;modifies 2nd attrib value
(setq BLKENT (entnext BLKENT) DATA2 (entget BLKENT)) ;set to next ent in 2nd blk
)
(setq BLKENT (entnext BLKENT) DATA2 (entget BLKENT)) ;set to next ent in 2nd blk
)
)
(setq BLK1 (entnext BLK1) DATA1 (entget BLK1)) ;set to next ent in 1st blk
)
(setq BLK1 (entnext BLK1) DATA1 (entget BLK1)) ;set to next ent in 1st blk
)
)
(entmod (entget BLK2))
(setq BLK1 nil Blk2 nil Data1 nil Data2 nil)
(princ)
) ; end defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Here's what I have done so far:
(defun c:UPTB ()
:
:
; some amazing nice coding here
:
:
(copyattr SrcTbEname TargetTbEName)
(princ "\nTitleBlock Attributes copied...\n")
(copyattr SrcRevBlk1Ename TargetRevBlk1Ename)
(princ "\nRevision Block 1 Attributes copied...\n")
(cond ((= 3 BlkCnt)
(copyattr SrcRevBlk2Ename TargetRevBlk2Ename)
(princ "\nRevision Block 2 Attributes copied...\n")
)
((= 4 BlkCnt)
(copyattr SrcRevBlk2Ename TargetRevBlk2Ename)
(copyattr SrcRevBlk3Ename TargetRevBlk3Ename)
)
((= 5 BlkCnt)
(copyattr SrcRevBlk2Ename TargetRevBlk2Ename)
(copyattr SrcRevBlk3Ename TargetRevBlk3Ename)
(copyattr SrcRevBlk4Ename TargetRevBlk4Ename)
)
) ;cond
(setvar "cmdecho" cmde)
(setvar "attdia" attdia)
(princ)
) ;defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TIP1045B.LSP: COPYATTR.LSP Attribute Utilities (C)1994, Robert L. Zipprich
(defun copyattr (BLK1 BLK2 / BLK1 BLK2 DATA1 DATA2 BLKNAME INSPT BLKENT SWDATA)
; BLK1 is source block with attributes to copy
; Blk2 is new target block to get attributes from the original source block
(setq EBLK1 BLK1) ; to erase old block
(setq DATA1 (entget BLK1))
(setq DATA2 (entget BLK2))
; (setq BLK2 TargetTbEname DATA2 TargetTbData) ;primes the pump
; (setq BLKNAME (cdr (assoc 2 (entget EBLK1)))
(setq BLKNAME (cdr (assoc 2 (entget BLK1)))
INSPT (cdr (assoc 10 (entget BLK2)))
)
;---------------
(setq BLK1 (entnext BLK1) DATA1 (entget BLK1)) ;primes the pump
(while (/= "SEQEND" (cdr (assoc 0 DATA1))) ;steps from ent to ent in 1st blk
(if (setq TAGNAME1 (cdr (assoc 2 DATA1))) ;if ent is attrib
(progn
(setq SWDATA (cdr (assoc 1 DATA1))) ;1st attrib value
(setq BLKENT (entnext BLK2) DATA2 (entget BLKENT)) ;next ent in 2nd blk
(while (/= "SEQEND" (cdr (assoc 0 DATA2)))
(if (eq TAGNAME1 (cdr (assoc 2 DATA2))) ;if tags match
(progn
(Setq DATA2 (subst (cons 1 SWDATA) (assoc 1 DATA2) DATA2))
(entmod DATA2) ;modifies 2nd attrib value
(setq BLKENT (entnext BLKENT) DATA2 (entget BLKENT)) ;set to next ent in 2nd blk
)
(setq BLKENT (entnext BLKENT) DATA2 (entget BLKENT)) ;set to next ent in 2nd blk
)
)
(setq BLK1 (entnext BLK1) DATA1 (entget BLK1)) ;set to next ent in 1st blk
)
(setq BLK1 (entnext BLK1) DATA1 (entget BLK1)) ;set to next ent in 1st blk
)
)
(entmod (entget BLK2))
(setq BLK1 nil Blk2 nil Data1 nil Data2 nil)
(princ)
) ; end defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;