TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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
(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))
-
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
-
cheers CAB ill have a look
-
If you want to add "R" to the name use this:
(strcat "R" (vla-get-textstring att))
-
is there a specific place within the code to place it?
-
Try this. I'm too lazy to create & test on my own without a test DWG.
(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)
)
-
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 :-)
-
You're quite welcome. 8-)