Jump to content

How to update drawing property with the most current rev block number and rev date


kam1967

Recommended Posts

Hi guys,

I have one challenge that I need help with. I'm not sure how to go about doing this. And I'm not sure if lisp is able to determine the latest revision, if the block name is the same - REVBLOCKA. The revision number's tag is REV# and its date is REVDATE.

 

Lee helped with the routine to update using the drawing property using the titleblockA's attribute earlier. But if there is a multiple revision block, how does the routine decipher the most current version?

 

The only thing about the rev block is that it starts with A, the B, then C, then D, then 0, then 1, 2, 3, etc. Not all drawings would have the same revision number, unfortunately.

 

The revision blocks will be the same name, but the revision letter or number (A,B,C,D,0,1,2,3,4,5) would be in the block. So assuming that there's 3 blocks (all named RevblockA) and attribute tag "REV#" and revision date tag "REVDATE", how can I obtain the highest rev and date, if it exists and update the dwgprops field for KEYWORDS (for Rev #) and COMMENTS (For Rev Date), respectively?

 

Thanks in advance.

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • kam1967

    11

  • Lee Mac

    6

  • pBe

    3

  • BIGAL

    1

Top Posters In This Topic

You can read each block and just compare the answer form the attributes is this one gretaer than that one it will work for strings as well, else make a list and sort them this will give highest and lowest values. just thought max min of a list also.

Link to comment
Share on other sites

The thread were Lee Mac helped you out, start from there

really, ITS ALL THERE. :)

 

Now for the latest rev letter/number

Try something like this

 

 
(setq cnt 6) ; where 12 represents the first REV# Tag position
(while
   (not
     (eq "" (vla-get-textstring (nth (setq cnt (+ cnt 6)) attb)))))

in this example:

A | 15JAN11 | Description | DHL | CHK | APPV < where TAG# is number 12
B | 25FEB11 | Description | DLG | CHK | APPV < where TAG# is number 18
 |         |             |     |     |      < where TAG# is number 24

Check if its blank and continue until the statement is TRUE, in this case
24 is true (3rd run)

(vla-get-textstring (nth (-  cnt 6) attb))<-- this will be last [b]

Link to comment
Share on other sites

Hi pBe,

 

I'm not sure I understand. I see the A for rev number, and 15jan11 for date. These are the two information I need to do a comparison on. I'm not sure what means. Could you elaborate?

 

By the way, the bottom left corner of the Rev block starts point 30,5. The block is 0.25 in height. The first Rev block would be A, and rev B would be 0.5 higher than rev A at point 30,5.25 - if this makes sense.

 

I like your idea though, so I think it might work. Thanks.

Link to comment
Share on other sites

Can't test:

 

(defun c:test ( / data doc lst prop ss sum tags ) (vl-load-com)
 ;; © Lee Mac 2011

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
       sum (vla-get-SummaryInfo doc)
 )

 (setq tags
  '(
     ("REV#"    . keywords)
     ("REVDATE" . comments)
   )
 )

 (if (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "REVBLOCKA")))
   (progn
     (vlax-for block (setq ss (vla-get-ActiveSelectionSet doc))
       
       (foreach attrib (vlax-invoke block 'getattributes)
         (if (assoc (strcase (vla-get-TagString attrib)) tags)
           (setq data
             (cons
               (cons (vla-get-TagString attrib) (vla-get-TextString attrib)) data
             )
           )
         )
       )
       
       (if data (setq lst (cons data lst) data nil))
     )
     (vla-delete ss)

     (foreach item
       (car
         (vl-sort lst
           (function
             (lambda ( a b )
               (> (cdr (assoc "REV#" a)) (cdr (assoc "REV#" b)))
             )
           )
         )
       )
       (if (setq prop (cdr (assoc (car item) tags)))
         (vlax-put-property sum prop (cdr item))
       )
     )
   )
 )

 (princ)
)

Edited by Lee Mac
Link to comment
Share on other sites

Thanks, Lee. I have tried it, but it does not appear to do anything. I'm attaching the REVBLOCKA file.

 

However, after having tested this one routine you just wrote, I went ahead and loaded the original one that you've created for me earlier. Guess what? It updated it!! I'm a little baffled, but hats off to you, Lee - you're a genius!!! LOL

 

However, if you still want to see why this last routine didn't seem to function, the block is attached also. Thanks again!

REVBLOCKA.dwg

Edited by kam1967
Link to comment
Share on other sites

However, after having tested this one routine you just wrote, I went ahead and loaded the original one that you've created for me earlier. Guess what? It updated it!! I'm a little baffled, but hats off to you, Lee - you're a genius!!! LOL

 

All works absolutely fine for me - first time of running it, with three RevBlockA's in the drawing, the correct Revision and Date is updated.

 

Bear in mind that both programs have the same command syntax (I used the other code as a base for this and forgot to change the command name). Hence if my original code is loaded after the code in this thread, it will overwrite the function definition of the code in this thread, and hence will be run instead when the command is called, perhaps giving the illusion that nothing has happened.

 

To avoid confusion I have renamed the program in this thread - I'll leave you to call it something more meaningful...

Link to comment
Share on other sites

I see now. REVBLOCKA is an individual block. The approach i suggested works if the Rev tags is inside one Titleblock

 

Lee Mac's code does exactly what you requested

Edited by pBe
Link to comment
Share on other sites

pBe - I do come across drawings the revision block that is incorporated in the titleblock. However, the rev tags are named REV01,DATE01;REV01,DATE01, etc. Does your programming address different tag names in the rev block or does it handle the tags that have the same rev tag name - like REV#, regardless of the revision number or letter?

 

I see now. REVBLOCKA is an individual block. The approach i suggested works if the Rev tags is inside one Titleblock

 

Lee Mac's code does exactly want you requested

Link to comment
Share on other sites

pBe - I do come across drawings the revision block that is incorporated in the titleblock. However, the rev tags are named REV01,DATE01;REV01,DATE01, etc. Does your programming address different tag names in the rev block or does it handle the tags that have the same rev tag name - like REV#, regardless of the revision number or letter?

 

Yes it does, as it deals with the position (nth x x) of the attribute tag and not by Tagname

Link to comment
Share on other sites

Lee - I tested it after I unloaded your first routine and it worked. I'm curious because your previous routine does seem to update whenever the rev block is copied and changed to another rev number and date, what is the difference between the two? Should I use the second one, instead of the first? Thanks again for writing this up, Lee.

 

All works absolutely fine for me - first time of running it, with three RevBlockA's in the drawing, the correct Revision and Date is updated.

 

Bear in mind that both programs have the same command syntax (I used the other code as a base for this and forgot to change the command name). Hence if my original code is loaded after the code in this thread, it will overwrite the function definition of the code in this thread, and hence will be run instead when the command is called, perhaps giving the illusion that nothing has happened.

 

To avoid confusion I have renamed the program in this thread - I'll leave you to call it something more meaningful...

Link to comment
Share on other sites

Lee - I tested it after I unloaded your first routine and it worked. I'm curious because your previous routine does seem to update whenever the rev block is copied and changed to another rev number and date, what is the difference between the two? Should I use the second one, instead of the first? Thanks again for writing this up, Lee.

 

Looking back at your previous thread, my first program was geared to update different fields based on titleblock information, and this program sources information on revision blocks (i.e. completely different blocks), so I don't see how to two could interfere.

 

I think there may be some confusion when running the two programs - probably not helped by the bad command naming on my part.

Link to comment
Share on other sites

Thanks, pBe. I'm not exactly sure how to use your code. I do have a rev block that has different tag name for each date and for each rev number. Once I get to those types of drawings, if Lee's routine does not handle those also, I will see if I get yours incorporated.

Yes it does, as it deals with the position (nth x x) of the attribute tag and not by Tagname
Link to comment
Share on other sites

  • 2 months later...

Lee - is it possible to make it so that if the revision block or REVBLOCK A is on a frozen layer, the program would only use information from the one that is not frozen?

 

Thanks a lot.

 

Kameron

 

 

Can't test:

 

(defun c:test ( / data doc lst prop ss sum tags ) (vl-load-com)
;; © Lee Mac 2011

(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
sum (vla-get-SummaryInfo doc)
)

(setq tags
'(
("REV#" . keywords)
("REVDATE" . comments)
)
)

(if (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "REVBLOCKA")))
(progn
(vlax-for block (setq ss (vla-get-ActiveSelectionSet doc))

(foreach attrib (vlax-invoke block 'getattributes)
(if (assoc (strcase (vla-get-TagString attrib)) tags)
(setq data
(cons
(cons (vla-get-TagString attrib) (vla-get-TextString attrib)) data
)
)
)
)

(if data (setq lst (cons data lst) data nil))
)
(vla-delete ss)

(foreach item
(car
(vl-sort lst
(function
(lambda ( a b )
(> (cdr (assoc "REV#" a)) (cdr (assoc "REV#" b)))
)
)
)
)
(if (setq prop (cdr (assoc (car item) tags)))
(vlax-put-property sum prop (cdr item))
)
)
)
)

(princ)
)

Link to comment
Share on other sites

Updated to exclude blocks on frozen layers:

 

([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] data def doc frz lst prop ss sum tags ) ([color=BLUE]vl-load-com[/color])
 [color=GREEN];; © Lee Mac 2011[/color]

 ([color=BLUE]setq[/color] doc ([color=BLUE]vla-get-ActiveDocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))
       sum ([color=BLUE]vla-get-SummaryInfo[/color] doc)
 )

 ([color=BLUE]while[/color] ([color=BLUE]set[/color] def ([color=BLUE]tblnext[/color] [color=MAROON]"LAYER"[/color] ([color=BLUE]null[/color] def)))
   ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]logand[/color] 1 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 70 def))))
     ([color=BLUE]setq[/color] frz ([color=BLUE]cons[/color] [color=MAROON]","[/color] ([color=BLUE]cons[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 def)) frz)))
   )
 )

 ([color=BLUE]setq[/color] tags
  '(
     ([color=MAROON]"REV#"[/color]    . keywords)
     ([color=MAROON]"REVDATE"[/color] . comments)
   )
 )

 ([color=BLUE]if[/color]
   ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color]
     ([color=BLUE]append[/color] '((0 . [color=MAROON]"INSERT"[/color]) (66 . 1) (2 . [color=MAROON]"REVBLOCKA"[/color]))
       ([color=BLUE]if[/color] frz
         ([color=BLUE]list[/color] '(-4 . [color=MAROON]"<NOT"[/color]) ([color=BLUE]cons[/color] 8 ([color=BLUE]apply[/color] '[color=BLUE]strcat[/color] ([color=BLUE]cdr[/color] frz))) '(-4 . [color=MAROON]"NOT>"[/color]))
       )
     )
   )
   ([color=BLUE]progn[/color]
     ([color=BLUE]vlax-for[/color] block ([color=BLUE]setq[/color] ss ([color=BLUE]vla-get-ActiveSelectionSet[/color] doc))
       
       ([color=BLUE]foreach[/color] attrib ([color=BLUE]vlax-invoke[/color] block 'getattributes)
         ([color=BLUE]if[/color] ([color=BLUE]assoc[/color] ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-TagString[/color] attrib)) tags)
           ([color=BLUE]setq[/color] data
             ([color=BLUE]cons[/color]
               ([color=BLUE]cons[/color] ([color=BLUE]vla-get-TagString[/color] attrib) ([color=BLUE]vla-get-TextString[/color] attrib)) data
             )
           )
         )
       )
       
       ([color=BLUE]if[/color] data ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] data lst) data [color=BLUE]nil[/color]))
     )
     ([color=BLUE]vla-delete[/color] ss)

     ([color=BLUE]foreach[/color] item
       ([color=BLUE]car[/color]
         ([color=BLUE]vl-sort[/color] lst
           ([color=BLUE]function[/color]
             ([color=BLUE]lambda[/color] ( a b )
               ([color=BLUE]>[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] [color=MAROON]"REV#"[/color] a)) ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] [color=MAROON]"REV#"[/color] b)))
             )
           )
         )
       )
       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] prop ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] ([color=BLUE]car[/color] item) tags)))
         ([color=BLUE]vlax-put-property[/color] sum prop ([color=BLUE]cdr[/color] item))
       )
     )
   )
 )

 ([color=BLUE]princ[/color])
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...