Author Topic: Updating revision attributes  (Read 4212 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
Updating revision attributes
« on: April 27, 2007, 12:40:38 PM »
Hello guys,

We have several macros for updating revision attributes with the current date
We have 2 attributes in our title block one that's formatted like mm/day/yr and the other mm/day.
The macro calls 2 lisp routines we have in our acad.lsp file for the formatting (see below)

They work but only one layout at a time and drawing at a time which is becoming a real pain to use as our jobs are huge now.

What I am looking for is a way to update these attributes across mulltiple layouts and files. What I was trying to propose to my boss is that we make the attribute values unique then we could use another program we have scroll down to bottom of this topic to update them in one shot.
She doesn't like this method because she still wants the date to be aquired from the system rather than the user having to input it. I was also thinking of putting this macro into a script but not sure how to run it across multiple layout tabs. So I'm wondering if anyone can help me with this or has another method I can try because this is killing me at this point. Thanks

ZOOM
EXTENTS
_.TEXTEVAL
1
-ATTEDIT
_Y
*
REV_DATE
*
_C
(GETVAR "EXTMIN")
(GETVAR "EXTMAX")
_V
_R
(UPTODAY)
_N
_V
_R
(TODAY)
_N
ZOOM
PREVIOUS

Code: [Select]
;This function is to get the current date in format mm/day/yr
;to use in date attribute updating
(defun today ( / -d yr mo day)
   (setq d (rtos (getvar "CDATE") 2 6)
         yr (substr d 3 2)
         mo (substr d 5 2)
         day (substr d 7 2)
   )
      (strcat mo "/" day "/" yr)
);defun

;This function is to get the current date in format mm/day
;to use in date attribute updating
(defun uptoday ( / -d mo day)
   (setq d (rtos (getvar "CDATE") 2 6)
         mo (substr d 5 2)
         day (substr d 7 2)
   )
      (strcat mo "/" day)
);defun
« Last Edit: April 27, 2007, 12:44:14 PM by Eloquintet »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating revision attributes
« Reply #1 on: April 27, 2007, 12:51:54 PM »
Do your attributes have specific tags?  If so then it will be easy to do what you want.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ELOQUINTET

  • Guest
Re: Updating revision attributes
« Reply #2 on: April 27, 2007, 02:22:13 PM »
Tim both of the attributes are called REV_DATE at this point but I would like to changed the shortened one to REV_DATE
_ABBRV so they can be updated independently. You have an idea of how I can do this? I need to utilize this like now actually  :-(

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating revision attributes
« Reply #3 on: April 27, 2007, 03:18:44 PM »
One way if both have the same tag, then you can go by order.  The first put one and the other put the other.  Would this work?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

terrycadd

  • Guest
Updating revision attributes
« Reply #4 on: April 27, 2007, 03:22:02 PM »
See if these functions meet your requirements.  I also added PutBlkAttrib and GetBlkAttrib as they're a related set.  If you're not sure of the blocks' attribute names, you can explode it and then press "U" to undo the explode.  There may be another way, but that works for me.
Terry Cadd  :kewl:
Code: [Select]
;-------------------------------------------------------------------------------
; c:PutDates - Updates the date attributes on all tabs
;-------------------------------------------------------------------------------
(defun c:PutDates (/ Ctab$ Layout$)
  (setq Ctab$ (getvar "CTAB"))
  (foreach Layout$ (layoutlist)
    (command "LAYOUT" "S" Layout$)
    ;Replace the following with your blocknames and attribute tags
    (PutBlkAttrib "11x17" "DATE" (Today))
    (PutBlkAttrib "Revision" "REV_DATE" (UpToday))
  );foreach
  (setvar "CTAB" Ctab$)
  (princ)
);defun c:PutDates
;-------------------------------------------------------------------------------
; PutBlkAttrib - Put Block Attribute value
; Arguments: 3
;   BlkOrEntity = Block or entity name
;   AttrTag$ = Tag label of attribute
;   AttrVal$ = New Value for attribute
; Returns: Changes attribute value.
; If BlkOrEntity is a block name, it changes only the first block found.
;-------------------------------------------------------------------------------
(defun PutBlkAttrib (BlkOrEntity AttrTag$ AttrVal$ / EntAttr$ EntList@ EntName^
  EntTag$ EntType$ First Passed SS&)
  (if (= (type BlkOrEntity) 'ENAME)
    (progn
      (setq EntName^ BlkOrEntity
            EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
      );setq
      (if (and (= EntType$ "INSERT") (assoc 66 EntList@))
        (setq Passed t First t)
      );if
    );progn
    (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(0 . "INSERT")'(66 . 1)(cons 2 BlkOrEntity)(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
      (setq EntName^ (ssname SS& (1- (sslength SS&)))
            EntList@ (entget EntName^)
            Passed t First t
      );setq
    );if
  );if
  (if Passed
    (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
      (setq EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
            EntTag$  (cdr (assoc 2 EntList@))
      );setq
      (if (= EntType$ "ATTRIB")
        (if (and (= EntTag$ (strcase AttrTag$)) First)
          (progn
            (entmod (subst (cons 1 AttrVal$) (assoc 1 EntList@) EntList@))
            (entupd EntName^)
            (setq First nil)
          );progn
        );if
      );if
      (setq EntName^ (entnext EntName^))
    );while
  );if
  (princ)
);defun PutBlkAttrib
;-------------------------------------------------------------------------------
; GetBlkAttrib - Get Block Attribute value
; Arguments: 2
;   BlkOrEntity = Block or entity name
;   AttrTag$ = Tag label of attribute
; Returns: Attribute value
; If BlkOrEntity is a block name, it gets the attribute of the first block found.
;-------------------------------------------------------------------------------
(defun GetBlkAttrib (BlkOrEntity AttrTag$ / AttrVal$ EntAttr$ EntList@ EntName^
  EntTag$ EntType$ Passed SS&)
  (if (= (type BlkOrEntity) 'ENAME)
    (progn
      (setq EntName^ BlkOrEntity
            EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
      );setq
      (if (and (= EntType$ "INSERT") (assoc 66 EntList@))
        (setq Passed t)
      );if
    );progn
    (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(0 . "INSERT")'(66 . 1)(cons 2 BlkOrEntity)(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
      (setq EntName^ (ssname SS& (1- (sslength SS&)))
            EntList@ (entget EntName^)
            Passed t
      );setq
    );if
  );if
  (if Passed
    (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
      (setq EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
            EntAttr$ (cdr (assoc 1 EntList@))
            EntTag$  (cdr (assoc 2 EntList@))
      );setq
      (if (= EntType$ "ATTRIB")
        (if (= EntTag$ (strcase AttrTag$)) (setq AttrVal$ EntAttr$))
      );if
      (setq EntName^ (entnext EntName^))
    );while
  );if
  AttrVal$
);defun GetBlkAttrib

ELOQUINTET

  • Guest
Re: Updating revision attributes
« Reply #5 on: April 27, 2007, 04:10:02 PM »
will,

theoretically yes that would work. terry i will play with yours when i get a moment (who knows when that will be yikes). terry i know for a fact that both tags are REV_DATE. I suppose if I had to I could run this through a batch processor on multiple files but it would be ideal if this worked out of the box on multiple files. I have hurricane so I could run it on multiples but others would have to open all the files which could be up to 50  :-o Thanks guys for the input

ELOQUINTET

  • Guest
Re: Updating revision attributes
« Reply #6 on: April 27, 2007, 04:38:45 PM »
Terry never thought I'd say this to a newt but "YOU RULE" I had to play with it for a bit til the logic sank in cause my brain is fried right now but I got it doing exactly what I want. Now the bonus will be if this can run across mulitple files. I know there was some talk on here awhile ago about developing some kind of multiple file interface anyone ever do something? Thanks Terry we'll pick this up again next week. Virtual beer on me,

Dan

ELOQUINTET

  • Guest
Re: Updating revision attributes
« Reply #7 on: May 30, 2007, 05:19:44 PM »
Terry,

I need a little additional help with this routine. I forgot that we have an attribute in our first revision block which just puts the revision number by the job name. When I get to revision 2 and update it I need to also look for the Rev 1 block name which is Revtitle and change the REV_NUM tag to 2. I tried to add an additional line(see below) but it's not working. How can I acheive this?


Code: [Select]
;-------------------------------------------------------------------------------
; c:Rev2 - Updates the date attributes on all tabs
;-------------------------------------------------------------------------------
(defun c:Rev2 (/ Ctab$ Layout$)
  (setq Ctab$ (getvar "CTAB"))
  (foreach Layout$ (layoutlist)
    (command "LAYOUT" "S" Layout$)
    ;Replace the following with your blocknames and attribute tags
    (PutBlkAttrib "Revtitl2" "REV2__DATE_ABBRV" (UpToday))
    (PutBlkAttrib "Revtitl2" "REV2__DATE" (Today))
    (PutBlkAttrib "revtitle" "REV_NUM" 2)
    );foreach
  (setvar "CTAB" Ctab$)
  (princ)
);defun c:Rev2
;-------------------------------------------------------------------------------
; PutBlkAttrib - Put Block Attribute value
; Arguments: 3
;   BlkOrEntity = Block or entity name
;   AttrTag$ = Tag label of attribute
;   AttrVal$ = New Value for attribute
; Returns: Changes attribute value.
; If BlkOrEntity is a block name, it changes only the first block found.
;-------------------------------------------------------------------------------
(defun PutBlkAttrib (BlkOrEntity AttrTag$ AttrVal$ / EntAttr$ EntList@ EntName^
  EntTag$ EntType$ First Passed SS&)
  (if (= (type BlkOrEntity) 'ENAME)
    (progn
      (setq EntName^ BlkOrEntity
            EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
      );setq
      (if (and (= EntType$ "INSERT") (assoc 66 EntList@))
        (setq Passed t First t)
      );if
    );progn
    (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(0 . "INSERT")'(66 . 1)(cons 2 BlkOrEntity)(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
      (setq EntName^ (ssname SS& (1- (sslength SS&)))
            EntList@ (entget EntName^)
            Passed t First t
      );setq
    );if
  );if
  (if Passed
    (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
      (setq EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
            EntTag$  (cdr (assoc 2 EntList@))
      );setq
      (if (= EntType$ "ATTRIB")
        (if (and (= EntTag$ (strcase AttrTag$)) First)
          (progn
            (entmod (subst (cons 1 AttrVal$) (assoc 1 EntList@) EntList@))
            (entupd EntName^)
            (setq First nil)
          );progn
        );if
      );if
      (setq EntName^ (entnext EntName^))
    );while
  );if
  (princ)
);defun PutBlkAttrib
;-------------------------------------------------------------------------------
; GetBlkAttrib - Get Block Attribute value
; Arguments: 2
;   BlkOrEntity = Block or entity name
;   AttrTag$ = Tag label of attribute
; Returns: Attribute value
; If BlkOrEntity is a block name, it gets the attribute of the first block found.
;-------------------------------------------------------------------------------
(defun GetBlkAttrib (BlkOrEntity AttrTag$ / AttrVal$ EntAttr$ EntList@ EntName^
  EntTag$ EntType$ Passed SS&)
  (if (= (type BlkOrEntity) 'ENAME)
    (progn
      (setq EntName^ BlkOrEntity
            EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
      );setq
      (if (and (= EntType$ "INSERT") (assoc 66 EntList@))
        (setq Passed t)
      );if
    );progn
    (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(0 . "INSERT")'(66 . 1)(cons 2 BlkOrEntity)(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
      (setq EntName^ (ssname SS& (1- (sslength SS&)))
            EntList@ (entget EntName^)
            Passed t
      );setq
    );if
  );if
  (if Passed
    (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
      (setq EntList@ (entget EntName^)
            EntType$ (cdr (assoc 0 EntList@))
            EntAttr$ (cdr (assoc 1 EntList@))
            EntTag$  (cdr (assoc 2 EntList@))
      );setq
      (if (= EntType$ "ATTRIB")
        (if (= EntTag$ (strcase AttrTag$)) (setq AttrVal$ EntAttr$))
      );if
      (setq EntName^ (entnext EntName^))
    );while
  );if
  AttrVal$
);defun GetBlkAttrib

GDF

  • Water Moccasin
  • Posts: 2081
Re: Updating revision attributes
« Reply #8 on: May 30, 2007, 05:39:16 PM »
See if these functions meet your requirements.  I also added PutBlkAttrib and GetBlkAttrib as they're a related set.  If you're not sure of the blocks' attribute names, you can explode it and then press "U" to undo the explode.  There may be another way, but that works for me.
Terry Cadd  :kewl:
Code: [Select]
;-------------------------------------------------------------------------------
; c:PutDates - Updates the date attributes on all tabs
;-------------------------------------------------------------------------------

Terry

Command: PutDates
; error: no function definition: TODAY

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

terrycadd

  • Guest
Re: Updating revision attributes
« Reply #9 on: May 30, 2007, 05:40:45 PM »
Gary,
His functions "today" and "uptoday" are in his first post in this thread. I didn't re-copy them into the example you tested, but you can get them there to test.

Eloquintet,
Thanks for the compliment. But here at the Swamp I'm no more than a small measly Newt creature.
Here is what you need to adjust in your code.
Terry

(PutBlkAttrib "revtitle" "REV_NUM" 2);<-- This needs to be (itoa 2) as follows:
(PutBlkAttrib "revtitle" "REV_NUM" (itoa 2))

Code: [Select]
(defun c:Rev2 (/ Ctab$ Layout$)
  (setq Ctab$ (getvar "CTAB"))
  (foreach Layout$ (layoutlist)
    (command "LAYOUT" "S" Layout$)
    ;Replace the following with your blocknames and attribute tags
    (PutBlkAttrib "Revtitl2" "REV2__DATE_ABBRV" (UpToday))
    (PutBlkAttrib "Revtitl2" "REV2__DATE" (Today))
    (PutBlkAttrib "revtitle" "REV_NUM" (itoa 2)) ; This line changed
  );foreach
  (setvar "CTAB" Ctab$)
  (princ)
);defun c:Rev2
« Last Edit: May 30, 2007, 05:50:57 PM by Terry Cadd »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating revision attributes
« Reply #10 on: May 30, 2007, 05:45:07 PM »

(PutBlkAttrib "revtitle" "REV_NUM" 2);<-- This needs to be (itoa 2) as follows:
(PutBlkAttrib "revtitle" "REV_NUM" (itoa 2))

<snip>
Dan,

This is because the value needs to be a string.  You can only put string values into text hold properties, which is what the routine is doing.

/interruption
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ELOQUINTET

  • Guest
Re: Updating revision attributes
« Reply #11 on: May 31, 2007, 09:21:20 AM »
ahhh works great terry and thanks will for explaining the reason. I appreciate the help guys.

terrycadd

  • Guest
Re: Updating revision attributes
« Reply #12 on: May 31, 2007, 10:48:12 AM »
Actually you could do the same thing by just simply making the 2 into a string by putting quotes around it.
(PutBlkAttrib "revtitle" "REV_NUM" "2")
At some point you or someone else is going to have a situation where they have several attribute blocks on the same layout. This might be something like a BOM block of one line in a Bill of Materials.  i.e. [ Item | Part Num | Description ] etc.
The following function c:UpdateItemNums shows how you can use the entity name option with the PutBlkAttrib function to update attribute blocks based upon their location, from highest to lowest insertion point. The GetBlkAttrib function may be used in the same way to get the information in a certain order.  If someone wants to write a shorter and faster version of these functions, please do so.  That’s how I learn how to code better, by your examples.
Code: [Select]
;-------------------------------------------------------------------------------
; c:UpdateItemNums - Updates Item numbers in BOM blocks
;-------------------------------------------------------------------------------
(defun c:UpdateItemNums (/ Cnt#)
  (setq Cnt# 1)
  (foreach EntName^ (SortBlkEntnames "BOM_LINE");<-- Replace "BOM_LINE" with your block name
    (PutBlkAttrib EntName^ "ITEM" (itoa Cnt#));<-- Replace "ITEM" with your tag name
    (setq Cnt# (1+ Cnt#))
  );foreach
  (princ)
);defun c:UpdateItemNums
;-------------------------------------------------------------------------------
; SortBlkEntnames - Sorts Block entity names from highest to lowest insertion point.
; Arguments: 1
;   BlkName$ = Block name
; Returns: List of sorted Block entity names based upon insertion point.
;-------------------------------------------------------------------------------
(defun SortBlkEntnames (BlkName$ / Cnt# EntList@ EntName^ EntNames@ Pt SS& Ypt Ypts@)
  (if (setq SS& (ssget "x" (list '(-4 . "<AND")(cons 2 BlkName$)(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
    (progn
      (setq Cnt# 0)
      (repeat (sslength SS&)
        (setq EntName^ (ssname SS& Cnt#))
        (setq EntList@ (entget EntName^))
        (setq Ypt (caddr (assoc 10 EntList@)))
        (setq Ypts@ (cons Ypt Ypts@))
        (setq Cnt# (1+ Cnt#))
      );repeat
      (setq Ypts@ (reverse (number_sort Ypts@)))
      (foreach Ypt Ypts@
        (setq Cnt# 0)
        (repeat (sslength SS&)
          (setq EntName^ (ssname SS& Cnt#))
          (setq EntList@ (entget EntName^))
          (setq Pt (caddr (assoc 10 EntList@)))
          (if (and (= Pt Ypt)(not (member EntName^ EntNames@)))
            (setq EntNames@ (append EntNames@ (list EntName^)))
          );if
          (setq Cnt# (1+ Cnt#))
        );repeat
      );foreach
    );progn
  );if
  EntNames@
);defun SortBlkEntnames
;-------------------------------------------------------------------------------
; number_sort - Sorts list of numbers
; Arguments: 1
;   List@ = List of numbers
; Returns: List of sorted numbers
;-------------------------------------------------------------------------------
(defun number_sort (List@ / High~ Item~ List1@ List2@ Low~ NewList@ Passed Swap~)
  (setq Passed t)
  (if (= (type List@) 'LIST)
    (foreach Item~ List@ (if (not (numberp Item~)) (setq Passed nil)))
    (setq Passed nil)
  );if
  (if (not Passed)
    (progn (princ "\nUsage: (number_sort <list of numbers>)") (exit))
  );if
  (repeat (/ (length List@) 2)
    (setq Low~ (car List@) High~ nil NewList@ nil)
    (foreach Item~ (cdr List@)
      (and (< Item~ Low~) (setq Swap~ Low~ Low~ Item~ Item~ Swap~))
      (and (> Item~ High~) (setq Swap~ High~ High~ Item~ Item~ Swap~))
      (setq NewList@ (cons Item~ NewList@))
    );foreach
    (setq List1@ (cons Low~ List1@) List2@ (cons High~ List2@) List@ (cdr (reverse NewList@)))
  );repeat
  (append (reverse List1@) List@ List2@)
);defun number_sort
;-------------------------------------------------------------------------------

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Updating revision attributes
« Reply #13 on: June 01, 2007, 09:12:14 AM »
How about this Terry? Sort is in reverse order to yours. Left to right, Bottom to top, but you can change that easy.
Not sure if it's faster.

Code: [Select]
;;  Needs PutBlkAttrib.lsp
(defun c:UpdateItemNums (/ Cnt#)
  (setq BlkName "NumTest" ;<-- Replace "BOM_LINE" with your block name
        Tag     "Num" ;<-- Replace "ITEM" with your tag name
  )
  (if (setq SS (ssget "x" (list (cons 2 BlkName) (cons 410 (getvar "CTAB")))))
    (progn
      (setq Target (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
      (setq Index (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) Target))
      ;;  sort Target List based on Point List
      (setq Target (mapcar '(lambda (x) (nth x Target))
                           (vl-sort-i Index
                                      '(lambda (e1 e2)
                                         (if (= (cadr e1) (cadr e2))
                                           (< (caddr e1) (caddr e2))
                                           (< (cadr e1) (cadr e2))
                                         )))))
      (setq Cnt# 1)
      (foreach EntName Target
        (PutBlkAttrib EntName Tag (itoa Cnt#))
        (setq Cnt# (1+ Cnt#))
      )
    )
  )
  (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.