Lisp - Number layour. Specific character postiion

Lisp - Number layour. Specific character postiion

Anonymous
Not applicable
1,049 Views
7 Replies
Message 1 of 8

Lisp - Number layour. Specific character postiion

Anonymous
Not applicable

Hi guys,

 

I would like to get a lisp to number layouts. I have found many codes, but I want to number only a character for the ctab. My layouts name are: "X.##.Floor" (##is the layout number) So, if I create a new layout, I have to number all layouts.

 

 (substr,$(getvar,ctab),2,3)

 

0 Likes
Accepted solutions (1)
1,050 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

Hello and welcome to the forums.

 

Try this to re-number layouts. See the spoiler.

 

Spoiler
(vl-load-com)


(defun c:LayoutRenumber (/ i :Layorder :AddLeadingZeros)  ;sort layout order
  
  (defun :AddLeadingZeros (a d / b) ;add zeros to 'd' many digits  ;a string
    (strcat (substr "000000000" 1 (if (>= d (setq b (strlen (itoa (fix (atof a)))))) (- d b) 0)) a))
  
  ; pbejse https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-order/td-p/3749964
  (defun :Layorder (/ order)
    (vlax-for lay (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
      (setq order (cons (list (vla-get-name lay)
                              (vla-get-taborder lay))
                        order)))
    (mapcar 'car (Cdr (vl-sort order '(lambda (j k) (< (cadr j) (cadr k)))))))
  
  (setq i 0)
  (foreach x (:Layorder)
    (vla-put-name
      (vla-item	(vla-get-layouts
                  (vla-get-activedocument (vlax-get-acad-object)))
                x)
      (strcat (itoa (setq i (1+ i))) "-tmp")))
  
  (setq i 0)
  (foreach x (:Layorder)
    (vla-put-name
      (vla-item	(vla-get-layouts
                  (vla-get-activedocument (vlax-get-acad-object)))
                x)
      (strcat "X." (:AddLeadingZeros (itoa (setq i (1+ i))) 2) ".Floor")))
  (princ)
)

 

 

0 Likes
Message 3 of 8

Anonymous
Not applicable

Thank you, it works, but I would like to remain the word "floor" for each layout because I have this for exarmple: X01 FistFloor, X02.SecondFloor X.03.Section, it's variable. So, I want to change only numbers position. 

0 Likes
Message 4 of 8

Anonymous
Not applicable

So, in code, "Floor", it woul be (getvar,ctab),4) or similar?

0 Likes
Message 5 of 8

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

Thank you, it works, but I would like to remain the word "floor" for each layout because I have this for exarmple: X01 FistFloor, X02.SecondFloor X.03.Section, it's variable. So, I want to change only numbers position. 


Ok, you gotta type in the suffix. 

 

Spoiler
(vl-load-com)


(defun c:LayoutRenumber (/ i :Layorder :AddLeadingZeros suffix)  ;sort layout order
  
  (defun :AddLeadingZeros (a d / b) ;add zeros to 'd' many digits  ;a string
    (strcat (substr "000000000" 1 (if (>= d (setq b (strlen (itoa (fix (atof a)))))) (- d b) 0)) a))
  
  ; pbejse https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-order/td-p/3749964
  (defun :Layorder (/ order)
    (vlax-for lay (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
      (setq order (cons (list (vla-get-name lay)
                              (vla-get-taborder lay))
                        order)))
    (mapcar 'car (Cdr (vl-sort order '(lambda (j k) (< (cadr j) (cadr k)))))))

  (setq suffix (getstring T "\nSuffix: "))
  
  (setq i 0)
  (foreach x (:Layorder)
    (vla-put-name
      (vla-item	(vla-get-layouts
                  (vla-get-activedocument (vlax-get-acad-object)))
                x)
      (if (wcmatch x (strcat "*" suffix))
        (strcat (itoa (setq i (1+ i))) suffix)
        x)))
  
  (setq i 0)
  (foreach x (:Layorder)
    (vla-put-name
      (vla-item	(vla-get-layouts
                  (vla-get-activedocument (vlax-get-acad-object)))
                x)
      (if (wcmatch x (strcat "*" suffix))
        (strcat "X." (:AddLeadingZeros (itoa (setq i (1+ i))) 2) "." suffix)
        x)))
  (princ)
)

 

In LISP (substr (getvar 'CTAB) 6) - no length needed

0 Likes
Message 6 of 8

Anonymous
Not applicable

Well, but now it changes only the layout with the suffix which I have wrote. And, only it numbers that layout. I don't want to change the suffix.

 

So, what I need. "X.01.Floor"

X-Prefix, it always the same,

01-Layout number. When I add other layout in the middle, I need to number all layouts. 

Floor-Suffix that I have wrote on layout name, It shouldn't change when I run the lisp.

 

I'm sorry, maybe I haven't explain it well. 

 

0 Likes
Message 7 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, so you have "X." and always 2 digits. 5th+ is suffix. 🙂

 

Spoiler
(vl-load-com)


(defun c:LayoutRenumber (/ i :Layorder :AddLeadingZeros)  ;sort layout order
  
  (defun :AddLeadingZeros (a d / b) ;add zeros to 'd' many digits  ;a string
    (strcat (substr "000000000" 1 (if (>= d (setq b (strlen (itoa (fix (atof a)))))) (- d b) 0)) a))
  
  ; pbejse https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-order/td-p/3749964
  (defun :Layorder (/ order)
    (vlax-for lay (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
      (setq order (cons (list (vla-get-name lay)
                              (vla-get-taborder lay))
                        order)))
    (mapcar 'car (Cdr (vl-sort order '(lambda (j k) (< (cadr j) (cadr k)))))))
  
  (setq i 0)
  (foreach x (:Layorder)
    (vla-put-name
      (vla-item	(vla-get-layouts
                  (vla-get-activedocument (vlax-get-acad-object)))
                x)
      (strcat "tm" (:AddLeadingZeros (itoa (setq i (1+ i))) 2) (substr x 5))))
  
  (setq i 0)
  (foreach x (:Layorder)
    (vla-put-name
      (vla-item	(vla-get-layouts
                  (vla-get-activedocument (vlax-get-acad-object)))
                x)
      (strcat "X." (:AddLeadingZeros (itoa (setq i (1+ i))) 2) (substr x 5))))
  (princ)
)
0 Likes
Message 8 of 8

Anonymous
Not applicable

Yes!! Thank you! Smiley Happy

0 Likes