Author Topic: Replace Copyright Year  (Read 6372 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Replace Copyright Year
« 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.


Quote
;;; 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!

Crank

  • Water Moccasin
  • Posts: 1503
Re: Replace Copyright Year
« Reply #1 on: December 29, 2006, 01:22:44 PM »
(setq newtext (strcat (substr (rtos (getvar "CDATE")) 1 4) " SNF CORPORATION"))
Vault Professional 2023     +     AEC Collection

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Replace Copyright Year
« Reply #2 on: December 29, 2006, 01:50:10 PM »
Thank you very much, Crank.

Works like a dream!

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Replace Copyright Year
« Reply #3 on: January 03, 2007, 10:44:08 AM »
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

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Replace Copyright Year
« Reply #4 on: January 03, 2007, 12:32:15 PM »
Guess I should mentions the ACAD2007 result was as follows:
"1672 SNF CORPORATION" instead of the expected "2007 SNF CORPORATION"

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Replace Copyright Year
« Reply #5 on: January 03, 2007, 12:52:42 PM »
Because your drawings unit type is something other than decimal. Change the line Crank gave to:
Code: [Select]
(setq newtext (strcat (substr (rtos (getvar "CDATE") 2 0) 1 4) " SNF CORPORATION"))

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Replace Copyright Year
« Reply #6 on: January 03, 2007, 02:46:48 PM »
Jeff. Looks like your modification did the trick.

Many thanks

VVA

  • Newt
  • Posts: 166
Re: Replace Copyright Year
« Reply #7 on: January 08, 2007, 05:53:42 AM »
LISP+DIESEL
Code: [Select]
(setq newtext (strcat (menucmd "M=$(edtime,$(getvar,date),YYYY)")  " SNF CORPORATION"))