Hi, I have a specific problem with renaming layouts. I found some similar lisps, but I just could not make them work.
In every layout I have following attributes.
PROJECT: 306
PHASE: RD
OBJECT: A0101
PART: EL
DRAWING: 611
ZOOM: X
REVISION: 01
I need to rename every each of layout using those attributes. Layout's name should look like that: "306_rd_A0101_el_611_x_01" . "rd", "el" and "x" must be written using lowercase.
Does anybody have any idea how to solve it using lisp routine?
Thanks in advance!
Pavel
@Anonymous wrote:Hi, I have a specific problem with renaming layouts. I found some similar lisps, but I just could not make them work.
In every layout I have following attributes.
PROJECT: 306
PHASE: RD
OBJECT: A0101
PART: EL
DRAWING: 611
ZOOM: X
REVISION: 01
Pavel
Are these attributes on one single block? or separate blocks?
Anyways...
(defun C:renlay (/ data Layout ss i e n Attval atv) (vl-load-com) (Setq data '("PROJECT" "PHASE" "OBJECT" "PART" "DRAWING" "ZOOM" "REVISION")) (setq Layout (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))) (if (setq ss (ssget "_x" '((0 . "INSERT") (2 . "CMA_titleblock_ru")))) (repeat (setq i (sslength ss)) (setq n 0 e (ssname ss (setq i (1- i))) ) (setq AttVal (mapcar '(lambda (k) (list (vla-get-tagstring k) (vla-get-textstring k))) (vl-remove-if-not '(lambda (j) (member (vla-get-tagstring j) data)) (vlax-invoke (vlax-ename->vla-object e) 'GetAttributes) ) ) ) ;;; This line will Arrange the sequence in case the attributes are not in right order ;;; (setq AttVal (substr (apply 'strcat (mapcar '(lambda (x) (setq v (assoc x Attval)) (strcat "_" (if (member (Car v) '("PHASE" "PART" "ZOOM")) (strcase (cadr v) t) (cadr v) ) ) ) data ) ) 2 ) atv attval ) ;;; In case there are equal values ;;; (while (member attval (layoutlist)) (setq Attval (strcat atv " (" (itoa (setq n (1+ n))) ")")) ) (vla-put-name (Vla-item Layout (cdr (Assoc 410 (entget e)))) attval) Attval ) ) (princ) )
HTH
I attach the tittle block. Example of two layouts. You can see that the name of every layout correspond to tittle block.
What is that symbol at the PHASE value? PД <----- it converts to "?" , there are limitations for LayoutNAme. so what would you want to replace it with?
The tittle block is more complicated than I thought. I am sorry, I should have uploaded drawing earlier.
РД - that means RD (realization documentation). There is quite common mistake, name of attribude should be:
PHASE=RD
PHASE2=РД
Simply speaking I need all attributes written by biggest letters and number in a row. For instance 306 RD A0101 EL 611 A 01 .... and then I need to put it as a name of layout as: 306_rd_A0101_el_611_a_01
Sorry for being confusing...
@Anonymous wrote:The tittle block is more complicated than I thought. I am sorry, I should have uploaded drawing earlier.
РД - that means RD (realization documentation). There is quite common mistake, name of attribude should be:
PHASE=RD
PHASE2=РД
Simply speaking I need all attributes written by biggest letters and number in a row. For instance 306 RD A0101 EL 611 A 01 .... and then I need to put it as a name of layout as: 306_rd_A0101_el_611_a_01
Sorry for being confusing...
I also notice there are tow PART tag names., in that case
EDIT: Hang on... the mod will assume there are tow PART & Phase...
I'll modify the code and re-post it again...
HYG
(defun C:renlay (/ data Layout ss i e n Attval atv) (vl-load-com) (Setq data '("PROJECT" "PHASE" "OBJECT" "PART" "DRAWING" "ZOOM" "REVISION")) (setq Layout (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))) (if (setq ss (ssget "_x" '((0 . "INSERT") (2 . "CMA_titleblock_ru")))) (repeat (setq i (sslength ss)) (setq n 0 e (ssname ss (setq i (1- i))) ) (setq AttVal (mapcar '(lambda (k) (list (vla-get-tagstring k) (vla-get-textstring k))) (vl-remove-if-not '(lambda (j) (and (member (vla-get-tagstring j) data) (not (vl-string-position 63 (vla-get-textstring j))))) (vlax-invoke (vlax-ename->vla-object e) 'GetAttributes) ) ) ) ;;; This line will Arrange the sequence in case the attributes are not in right order ;;; (setq AttVal (substr (apply 'strcat (mapcar '(lambda (x) (setq v (assoc x Attval)) (strcat "_" (if (member (Car v) '("PHASE" "PART" "ZOOM")) (strcase (cadr v) t) (cadr v) ) ) ) data ) ) 2 ) atv attval ) ;;; In case there are equal values ;;; (while (member attval (layoutlist)) (setq Attval (strcat atv " (" (itoa (setq n (1+ n))) ")")) ) (vla-put-name (Vla-item Layout (cdr (Assoc 410 (entget e)))) attval) Attval ) ) (princ) )
HTH
@Anonymous wrote:It works great!! 🙂 thank you very much. Your help is very appreciated.
You are welcome cma_PavelPrchal. Glad I could help.
Cheers