Community
I was wondering if someone could help me write a lisp that takes the name of the file and replaces an existing attribute with the name of the file. Basically, have a attributed title block with a number of tags, and need to change two tags in the attributed block to be the dame as the filename.
Thanks
;change attrib (defun C:CHAT (/ BNAME ANAME VAL1 VAL2) (setq BNAME (getstring "\nBlock name \(all = enter\) : ") ANAME (strcase (getstring "Attribute name \(all = enter\) : ") ) VAL1 (getstring t "Search value \(all = enter / all empty = \"empty\" \) : " ) VAL2 (getstring t "New value : ") ) ;s (CHATZ BNAME ANAME VAL1 VAL2 ) (princ) ) ;******** ; Assoc funktie ;******** (defun DXF (N ED) (cdr (assoc N ED))) (princ) ;******** ;change attrib ;******** (defun CHATZ (BNAME ANAME VAL1 VAL2 /) (setq SEL (ssget "X" '((0 . "INSERT"))) CNT (sslength SEL) TEL 0 ) ;s (while (/= CNT 0) (setq EN1 (ssname SEL (1- CNT)) END (entget EN1) BNAM (DXF 2 END) EN1 (cdar END) EN1 (entnext EN1) ) ;s ;check BLOCK name (if (or (= BNAME "") (= (strcase BNAME) (strcase BNAM))) (while (and (/= EN1 NIL) (/= "SEQEND" (DXF 0 (entget EN1)))) (setq END (entget EN1)) (if (= "ATTRIB" (DXF 0 END)) (progn (setq ED1 (DXF 1 END) ED2 (DXF 2 END) ) ;s ;check TAG name (if (or (= ANAME "") (= ANAME ED2)) ;check val (if (or (= VAL1 "") (= VAL1 ED1) (and (= VAL1 "empty") (= ED1 "")) ) (progn (setq D (assoc 1 END) D1 (cons 1 VAL2) E5 (subst D1 D END) TEL (1+ TEL) ) ;s (entmod E5) (entupd (cdar E5)) ) ;p ) ;i ) ;i ) ;p ) ;i (setq EN1 (entnext EN1)) ) ;w ) ;i (setq CNT (1- CNT)) ) ;w (princ "Number changed : ") (princ TEL) (princ "\n") (princ "Value changed : ") (princ VAL1) (princ " to ") (princ VAL2) (princ "\n") (princ) )
Use CHAT to do it manualy.
Use CHATZ like this :
(defun C:LAZY-S1006771 () (load "chat")
(setq DWGN (getvar "dwgname") BLOCKNAME "ARRANGEMENT" ATTRIBUTENAME "SECTION" ) (CHATZ BLOCKNAME ATTRIBUTENAME "" DWGN) )
Change block and attribute name as you like.
You can copy this line for other attrinutes and/or blocks:
(CHATZ BLOCKNAME ATTRIBUTENAME "" OtherValue)