Author Topic: Need help with Layout tab rename lisp  (Read 4701 times)

0 Members and 1 Guest are viewing this topic.

SeanyB

  • Guest
Need help with Layout tab rename lisp
« on: December 14, 2010, 06:16:18 PM »
Hey,
Im new to lisp and am trying to rename the layout tab and prefix the letter 'R' in front of the revision attribute that is being read in the block
So if the revision is A it will then rename the layout tab to RA
This is what i have so far have done some research but canot find an answer
am unsure on how to prefix the letter R

attached is the title block attribute

Code: [Select]
(defun c:layName (/ bNme aNme lay ss att e)
(vl-load-com)

(setq bNme "GHD_G_1002_T" aNme "GHD_REV_NO")

(vlax-for lay (vla-get-layouts
(vla-get-ActiveDocument (vlax-get-acad-object)))

(if (and (not (eq "MODEL" (strcase (vla-get-Name lay))))
(setq ss (ssget "_X" (list (cons 0 "INSERT")
(cons 2 bNme)
(cons 66 1)
(cons 410 (vla-get-Name lay))))))
(foreach att (vlax-invoke
(vlax-ename->vla-object (ssname ss 0)) 'GetAttributes)

(if (apply 'eq (mapcar 'strcase (list aNme (vla-get-TagString att))))

(if (vl-catch-all-error-p
(setq e (vl-catch-all-apply 'vla-put-Name
(list lay (vla-get-TextString att)))))

(princ (strcat "\n** Error: " (vl-catch-all-error-message e) " **")))))))

(princ))
« Last Edit: December 14, 2010, 07:54:31 PM by CAB »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need help with Layout tab rename lisp
« Reply #1 on: December 14, 2010, 06:25:04 PM »
« Last Edit: December 14, 2010, 06:56:33 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SeanyB

  • Guest
Re: Need help with Layout tab rename lisp
« Reply #2 on: December 14, 2010, 07:06:31 PM »
cheers CAB ill have a look

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need help with Layout tab rename lisp
« Reply #3 on: December 14, 2010, 07:57:34 PM »
If you want to add "R" to the name use this:
Code: [Select]
(strcat "R" (vla-get-textstring att))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SeanyB

  • Guest
Re: Need help with Layout tab rename lisp
« Reply #4 on: December 15, 2010, 07:18:14 PM »
is there a specific place within the code to place it?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need help with Layout tab rename lisp
« Reply #5 on: December 15, 2010, 08:48:48 PM »
Try this. I'm too lazy to create & test on my own without a test DWG.

Code: [Select]
(defun c:layName (/ bNme aNme lay ss att e)
  (vl-load-com)
  (setq bNme "GHD_G_1002_T" ; Block Name
        aNme "GHD_REV_NO"   ; Attribute Tag name
  )

  ;;  Step through paperspace layouts
  ;;  get inserts with matching block name
  (vlax-for lay (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (if (and (not (eq "MODEL" (strcase (vla-get-name lay))))
             (setq ss (ssget "_X"
                             (list (cons 0 "INSERT")
                                   (cons 2 bNme)
                                   (cons 66 1)
                                   (cons 410 (vla-get-name lay))
                             ))))
      ;;  Step through the attributes
      ;;  look for match with Attribute Tag Name
      ;;  if found change the layout name to the attr string + R prefix
      (foreach att (vlax-invoke (vlax-ename->vla-object (ssname ss 0)) 'GetAttributes)
        (if (apply 'eq (mapcar 'strcase (list aNme (vla-get-tagstring att))))
          (if (vl-catch-all-error-p
                (setq e (vl-catch-all-apply 'vla-put-name
                          (list lay (strcat "R" (vla-get-textstring att)))))
              )
            ;; report any error
            (princ (strcat "\n** Error: " (vl-catch-all-error-message e) " **"))
          )
        )
      )
    )
  )

  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SeanyB

  • Guest
Re: Need help with Layout tab rename lisp
« Reply #6 on: December 15, 2010, 09:11:41 PM »
Thats awesome,

Thanks you so much has helped me out a heap.
The way its presented makes it easy to understand.

Thanks again for your help much appreciated  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need help with Layout tab rename lisp
« Reply #7 on: December 15, 2010, 10:21:44 PM »
You're quite welcome.  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.