TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Biscuits on December 29, 2006, 12:55:51 PM
-
Happy New Year to everyone!
I hope Christmas was a good one!
Using ACAD2002 (for now)
This routine finds any attribute within any and all titleblocks in our drawing files. It finds attributes with the tag "COPYRIGHT" OR "COPYRIGHTYEAR" and then updates the attribute value to read "2007 SNF CORPORATION".
at the beginning of each new year, this lisp routine is modified to reflect the new year. An easy task I admit. I was wondering if anyone knew of a way to modify this routine so we would not have to update this file every year.
All our existing drawings have to have the copyright year updated when they are opened for modification. We have this routine run automatically and it works great as is. Just trying to make everything a smidge better. Besides... I'm lazy.
;;; Updates copyright year attributes in all titleblocks
;;
(defun c:CRupdate (/ ss ent obj attributes att)
(vl-load-com)
(setq newtext "2007 SNF CORPORATION")
(setq ss (ssget "_X" '((0 . "INSERT"))))
(setq i -1)
(if ss
(while (setq ent (ssname ss (setq i (1+ i))))
(if (and (setq obj (vlax-ename->vla-object ent))
(= (vla-get-objectname obj) "AcDbBlockReference")
(= (vla-get-hasattributes obj) :vlax-true)
)
(progn
(setq attributes (vlax-invoke obj 'getattributes))
(foreach att attributes
(if (or (= "COPYRIGHT" (vla-get-tagstring att))
(= "COPYRIGHTYEAR" (vla-get-tagstring att))
)
(progn
(vla-put-textstring att newtext)
(vla-update att)
)
)
)
)
)
)
)
(or *doc* (setq *doc* (vla-get-activedocument (vlax-get-acad-object))))
(if (< 0 (vla-get-count (setq blks (vla-get-blocks *doc*))))
(progn
(vlax-for blk blks
(if (/= (vla-get-name blk) "*Model_Space")
(vlax-for ent blk
(if (and (vlax-property-available-p ent 'hasattributes)
(= (vla-get-hasattributes ent) :vlax-true)
)
(progn
(setq attributes (vlax-invoke ent 'getattributes))
(foreach att attributes
(if (or (= "COPYRIGHT" (vla-get-tagstring att))
(= "COPYRIGHTYEAR" (vla-get-tagstring att))
)
(progn
(vla-put-textstring att newtext)
)
)
)
)
)
)
)
)
(vla-regen *doc* acactiveviewport)
)
)
(princ)
)
(prompt "\nCopyright Update Loaded, Enter cupdate to run.")
(princ)
Thanks to SWAMP and all who have help me over the years!
-
(setq newtext (strcat (substr (rtos (getvar "CDATE")) 1 4) " SNF CORPORATION"))
-
Thank you very much, Crank.
Works like a dream!
-
Thanks again, Crank.
Any ideas out there as to why this routine works on ACAD2002 and not on Acad 2007?
What do I need to do to make it work?
Thanks
-
Guess I should mentions the ACAD2007 result was as follows:
"1672 SNF CORPORATION" instead of the expected "2007 SNF CORPORATION"
-
Because your drawings unit type is something other than decimal. Change the line Crank gave to:
(setq newtext (strcat (substr (rtos (getvar "CDATE") 2 0) 1 4) " SNF CORPORATION"))
-
Jeff. Looks like your modification did the trick.
Many thanks
-
LISP+DIESEL
(setq newtext (strcat (menucmd "M=$(edtime,$(getvar,date),YYYY)") " SNF CORPORATION"))