;; | --------------------------------------------------------------------------- ;; | BL_RepBlk ;; | --------------------------------------------------------------------------- ;; | Function : Replace one Block with another ;; | Arguments: ;; | 'blk1' - Name of first block ;; | 'blk2' - Name of second block ;; | 'blk1' and 'blk2' can be the same, in which case, the new block ;; | definition will be taken, including the attributes. ;; | See 'SyncMethod' option below for description on how the block ;; | will be synchronized. ;; | ;; | 'SyncMethod' - This option will be used only if both source and ;; | target block names are the same. ;; | Indicates method to use for synchronization with an ;; | external DWG block from disk or an updated block ;; | definition from within the current drawing. ;; | Possible values: ;; | 'ExtSync' - New block definition will be read from ;; | an external DWG file by the same name as ;; | as the blockname ;; | 'IntSync' - New block definition will be read from a ;; | same named internal updated block within ;; | current drawing. ;; | 'AttMap' - Attribute Map, of old and new tag names that can be ;; | used for replacing attributes. ;; | This is a nested list of the type ;; | (list (list OldTag NewTag) ...) ;; | ;; | 'RepositionAtts' - Flag (T or nil) which indicates whether the attribute ;; | positions must be retained as in the source blocks or reset ;; | to the positions as in the new target block definition. ;; | 'ss' - Selection Set to process - If nil, all blocks ;; | belonging of the source name will be processed. ;; | Action : Replaces all insertions of one Block with another ;; | The number of attributes in the two blocks need not ;; | be the same. As many attributes as possible will ;; | be transferred, the rest will be lost if there ;; | is less in target block. If there are more attributes ;; | in target block, they will be blank ;; | Updated : February 28, 2002 ;; | e-mail : rakesh.rao@4d-technologies.com ;; | Web : www.4d-technologies.com ;; | --------------------------------------------------------------------------- (defun BL_RepBlk ( blk1 blk2 SyncMethod RepositionAtts ss AttMap / aname ARQ Att AttLst AttVal blk cnt ename ename1 entl flag72 flag74 Insp Insp10 Insp11 Just la od odLst Rot OS RotAng ss1 ssl Tables TagLst TagName tmp xd XScl YScl _AttLst _Just ) (setq ss1 (ssadd) blk1 (strcase blk1) blk2 (strcase blk2) ) (if (not (tblsearch "BLOCK" blk1)) (progn (alert (strcat "Cannot find source block definition in drawing : " blk1)) (exit) )) (if (not ss) (setq ss (SS_SeleBlk blk1)) ) (if ss (progn (setq ssl (sslength ss) tmp (strcat " of " (itoa ssl)) cnt 0 OS (getvar "OSMODE") ARQ (getvar "ATTREQ") ) (setvar "ATTREQ" 0) (setvar "OSMODE" 0) (if (= blk1 blk2) (progn (if (= SyncMethod "ExtSync") (progn (if (not (findfile (strcat blk2 ".dwg"))) (progn (alert (strcat "Cannot find destination block drawing : " blk2 ".dwg")) (exit) )) (setq blk (BL_GetTmpBlk)) (if (tblsearch "BLOCK" blk2) (progn (command "._Rename" "_Block" blk2 blk) (setq blk1 blk) )) (command "._Insert" blk2 (list 0.0 0.0 0.0) 1.0 1.0 0.0) (entdel (entlast)) )) )) (princ "\n") (repeat ssl (setq ename (ssname ss cnt) xd (assoc -3 (entget ename (list "*"))) entl (entget ename) la (LI_item 8 entl) Insp (LI_item 10 entl) XScl (LI_item 41 entl) YScl (LI_item 42 entl) rot (LI_item 50 entl) cnt (1+ cnt) AttLst (BL_GetAtts ename) _AttLst '() ) (foreach Att AttLst (setq AttVal (nth 0 Att) TagName (nth 1 Att) aname (nth 3 Att) entl (entget aname) flag72 (LI_item 72 entl) flag74 (LI_item 74 entl) Just (TX_GetJust flag72 flag74) Insp10 (LI_item 10 entl) Insp11 (LI_item 11 entl) RotAng (LI_item 50 entl) _AttLst (cons (list TagName aname Insp10 Insp11 Just RotAng AttVal) _AttLst) ) ) (setq AttLst _AttLst) (if #AcadMap (progn (setq Tables (AM_GetTables ename) odLst '() ) (foreach Table Tables (setq od (AM_GetTableData ename Table)) (if od (setq odLst (cons (list Table od) odLst)) ) ) )) (LA_mk_c_lyr la "") (command "._Insert" blk2 Insp XScl YScl (MI_r2d rot)) (setq ename1 (entlast) TagLst (mapcar 'cadr (BL_GetAtts ename1)) ) (ssadd ename1 ss1) (foreach TagName TagLst (if (or (setq Att (assoc TagName AttLst)) (setq Att (BLi_GetAttFromLookup TagName AttLst AttMap)) ) (progn (setq aname (BL_FindAttr ename1 TagName)) (if aname (progn (setq entl (entget aname) flag72 (LI_item 72 entl) flag74 (LI_item 74 entl) _Just (TX_GetJust flag72 flag74) Insp10 (nth 2 Att) Insp11 (nth 3 Att) Just (nth 4 Att) RotAng (nth 5 Att) AttVal (nth 6 Att) ) (if RepositionAtts (progn (if (= Just _Just) (progn (cond ((member Just (list "TL" "TC" "TR" "ML" "MR" "MC" "BL" "BC" "BR" "C" "R" "M")) (setq entl (subst (list 11 (car Insp11) (cadr Insp11) (caddr Insp11)) (assoc 11 entl) entl)) ) ((member Just (list "F" "A")) (setq entl (subst (list 11 (car Insp11) (cadr Insp11) (caddr Insp11)) (assoc 11 entl) entl) entl (subst (list 10 (car Insp10) (cadr Insp10) (caddr Insp10)) (assoc 10 entl) entl) ) ) (T (setq entl (subst (list 10 (car Insp10) (cadr Insp10) (caddr Insp10)) (assoc 10 entl) entl)) ) ) ) (progn (alert (strcat "Error: Text justification for attribute tag '" TagName "' is different in source and target blocks. It must be the same")) (exit) )) )) (setq entl (subst (cons 50 RotAng) (assoc 50 entl) entl)) (entmod entl) (entupd aname) (BL_WriteAttr ename1 TagName AttVal) (if #Verbose (princ (strcat "\nAttribute tag: " TagName " value/position updated\n")) ) )) ) ) ) (entupd ename1) (entdel ename) (if xd (XD_AddXdata ename1 xd) ) (if (and #AcadMap odLst) (AM_PutAllTableData ename1 odLst "Overwrite") ) (princ (strcat "\rReplacing block insertions of " blk1 " with " blk2 "..." (itoa cnt) tmp)) ) (princ (strcat "\nDeleting original block " blk1)) (command "._Erase" ss "") (if (= blk1 blk2) (progn (if (= SyncMethod "ExtSync") (command "._Purge" "_Blocks" blk "_No") ) )) (setvar "OSMODE" OS) (setvar "ATTREQ" ARQ) )) (if (> (sslength ss1) 0) ss1 nil) )