Author Topic: Renaming Layout Tabs  (Read 2029 times)

0 Members and 1 Guest are viewing this topic.

Offline acad2015Topic starter

  • Full Member
  • ***
  • Posts: 116
  • Country: us
  • Gender: Male
Renaming Layout Tabs
« on: Jul 15, 2019, 14:39:13 PM »
Morning all,

I have 7 layout tabs inside of a drawing. The first being "7001 LU5A1-HV". I want to replace the "7" with a "1" and the "HV" with "PN". Below is the code I have come up with so far but I do not know how to apply my finished list to the layout names. Any help would be appreciated.
Code: [Select]
(defun c:lwn ( / lst lst1 lst2 lst3 lst4 )
  (setq lst (layoutlist))
  (setq len (length lst))
;;;  (setq lst1 nil)
;;;  (setq lst2 nil)
;;;  (setq lst3 nil)
;;;  (setq lst4 nil)
  (foreach x lst
(setq lst1 (append lst1 (list (substr x 2))))
  )
  (foreach c lst1
(setq lst2 (append lst2 (list (strcat "1" c))))
  )
  (foreach v lst2
(setq lst3 (append lst3 (list (substr v 1 11))))
  )
  (foreach b lst3
(setq lst4 (append lst4 (list (strcat b "PN"))))
  )
 )

Offline edh

  • Premier Member
  • *****
  • Posts: 507
  • Country: us
  • Gender: Male
Re: Renaming Layout Tabs
« Reply #1 on: Jul 15, 2019, 18:02:56 PM »
Code: [Select]
(defun c:renametabs ( / doc layouts)
(vl-load-com) 
(setq layouts (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))))
(vlax-for layout layouts
(while (vl-string-search "OLD name" (vla-get-name layout))
(vla-put-name layout (vl-string-subst "NEW name" "OLD name" (vla-get-name layout)))))
(princ)
)

Above is what I have been using.
Don

Offline TonyHolsinger

  • Full Member
  • ***
  • Posts: 194
  • Country: us
  • Gender: Male
Re: Renaming Layout Tabs
« Reply #2 on: Jul 15, 2019, 18:08:44 PM »
This will work as a find and replace.

Code: [Select]
(princ "TABRENAME.LSP loaded - type TABRENAME to run.")

(defun C:TABRENAME
       (/ LTLIST OLD_TEXT NEW_TEXT GO_NOGO LIST_ITEM NEW_LIST ITEM)
  (setq LTLIST (layoutlist))
  (prompt "\nFind and replace text in layout tabs...")
  (setq OLD_TEXT (getstring "\n   Find: "))
  (setq NEW_TEXT (getstring "\n   Replace with: "))

  (while LTLIST
    (foreach N LTLIST
      (setq LIST_ITEM (car LTLIST))
      (setq LTLIST (cdr LTLIST))
      (if (vl-string-search OLD_TEXT LIST_ITEM)
(progn
  (setq NEW_LIST_ITEM
(vl-string-subst NEW_TEXT OLD_TEXT LIST_ITEM)
  )
  (command "layout" "R" LIST_ITEM NEW_LIST_ITEM)
  (PRINC)
)
      )
    )
  )

  (PRINC "To undo this change, you must run TABRENAME again...")
)

Offline thejikz

  • Active Member
  • **
  • Posts: 23
  • Country: us
  • Gender: Male
Re: Renaming Layout Tabs
« Reply #3 on: Jul 15, 2019, 18:21:43 PM »
Another option- very specific to your case, no need for extra lists, just work on each name directly.

Code: [Select]
(vl-load-com)
(setq lst (layoutlist))
(foreach x lst
(command "layout" "R" x (vl-string-subst "PN" "HV" (vl-string-subst "1" "7" x)))
)

Offline acad2015Topic starter

  • Full Member
  • ***
  • Posts: 116
  • Country: us
  • Gender: Male
Re: Renaming Layout Tabs
« Reply #4 on: Jul 15, 2019, 18:49:53 PM »
Thank you all.

You thejikz are an amazing person. That's exactly what I started out to achieve.

Offline SSchmitt85

  • Full Member
  • ***
  • Posts: 63
  • Country: us
  • Gender: Male
Re: Renaming Layout Tabs
« Reply #5 on: Jul 16, 2019, 22:16:05 PM »
This program from Lee Mac is amazing. i use it all the time and it does way more then just renumbering and renaming.

http://www.lee-mac.com/tabsort.html
~Therapy is expensive.... But popping bubble wrap is cheap and effective~

Offline acad2015Topic starter

  • Full Member
  • ***
  • Posts: 116
  • Country: us
  • Gender: Male
Re: Renaming Layout Tabs
« Reply #6 on: Jul 17, 2019, 10:34:07 AM »
This program from Lee Mac is amazing. i use it all the time and it does way more then just renumbering and renaming.

http://www.lee-mac.com/tabsort.html

Thank you for sharing. This program is nice and will be used in the future.