TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: SeanyB on December 14, 2010, 06:16:18 PM

Title: Need help with Layout tab rename lisp
Post by: SeanyB 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))
Title: Re: Need help with Layout tab rename lisp
Post by: CAB on December 14, 2010, 06:25:04 PM
Take a look here:
http://www.theswamp.org/index.php?topic=3079.msg38380#msg38380


Also here:
---------------  Layout / Tab Sort  -------------------
http://www.theswamp.org/index.php?topic=30262.0  LeeMac
http://www.theswamp.org/index.php?topic=6511.0  CAB
Title: Re: Need help with Layout tab rename lisp
Post by: SeanyB on December 14, 2010, 07:06:31 PM
cheers CAB ill have a look
Title: Re: Need help with Layout tab rename lisp
Post by: CAB 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))
Title: Re: Need help with Layout tab rename lisp
Post by: SeanyB on December 15, 2010, 07:18:14 PM
is there a specific place within the code to place it?
Title: Re: Need help with Layout tab rename lisp
Post by: CAB 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)
)
Title: Re: Need help with Layout tab rename lisp
Post by: SeanyB 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  :-)
Title: Re: Need help with Layout tab rename lisp
Post by: CAB on December 15, 2010, 10:21:44 PM
You're quite welcome.  8-)