Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Renaming layouts according to Tittle block

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
524 Views, 10 Replies

Renaming layouts according to Tittle block

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

10 REPLIES 10
Message 2 of 11
pbejse
in reply to: Anonymous


@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?

 

Message 3 of 11
Anonymous
in reply to: pbejse

It is a one block with name "CMA_titleblock_ru". But attributes are different in every layout of course. 

Message 4 of 11
pbejse
in reply to: Anonymous

PROJECT

PHASE

 

So are those TAG string or prompt?

 

 

 

 

 

Message 5 of 11
pbejse
in reply to: pbejse

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

 

Message 6 of 11
Anonymous
in reply to: pbejse

I attach the tittle block. Example of two layouts. You can see that the name of every layout correspond to tittle block. 

Message 7 of 11
pbejse
in reply to: Anonymous

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?

 

 

Message 8 of 11
Anonymous
in reply to: pbejse

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...

Message 9 of 11
pbejse
in reply to: Anonymous


@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

 

Message 10 of 11
Anonymous
in reply to: pbejse

It works great!! 🙂 thank you very much. Your help is very appreciated. 

Message 11 of 11
pbejse
in reply to: Anonymous


@Anonymous wrote:

It works great!! 🙂 thank you very much. Your help is very appreciated. 


You are welcome cma_PavelPrchal. Glad I could help.

 

Cheers

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost