Use a lisp program to identify the revision number within a title block and increment it by 1

Use a lisp program to identify the revision number within a title block and increment it by 1

gv6823otG42ZL
Enthusiast Enthusiast
726 Views
10 Replies
Message 1 of 11

Use a lisp program to identify the revision number within a title block and increment it by 1

gv6823otG42ZL
Enthusiast
Enthusiast

I am very new to lisp programming so any help would be greatly appreciated!. I am attempting to write a program that goes into a title block and locates the tag "REV" From there I want it to locate the REV number and then increment it by one. So far I have the program listed below. Any ideas or help would be awesome!

 

(defun c:TBLOCK (/ ss i ename)
(if (setq ss (ssget "_X" '((0 . "insert") (2 . "Tid22") (66 . 1))))
(repeat (setq i (sslength ss))
(setq en (ssname ss (setq i (1- i))))
(setpropertyvalue en "REV" "1+REV")))
(princ)
)

0 Likes
727 Views
10 Replies
Replies (10)
Message 2 of 11

devitg
Advisor
Advisor

You have to get rev to be number, (atoi REV)   then add 1 , (setq rev ( 1+ rev)) then retrieve rev to string (itoa rev)

and 

 

0 Likes
Message 3 of 11

Sea-Haven
Mentor
Mentor

Be careful the "X" will find all blocks and update we only updated the relevant sheet not all but that may be your company standard.

 

There is lots of add revision lisps out there so you can see for each sheet the revision history. 

SeaHaven_0-1668124435108.png

 

And yes there is bump revisions when full.

 

0 Likes
Message 4 of 11

gv6823otG42ZL
Enthusiast
Enthusiast

So for our title block. I just need the revision number to be incremented by 1. The revision blocks are a little different. We have 6 slots for revision blocks numbered one through 6. Each one has room for the date, 3 descriptions , drawn by and checked by. Is there a script that will take user defined information for these and automatically update the next available revblock? When all 6 have been filled out, we delete the first revblock, move all of the existing revision blocks down one, and then copy a revblock over to the new slot, and then update that new revision block with the rev number and then all the information described above. Would there be a script that could copy that action? 

0 Likes
Message 5 of 11

gv6823otG42ZL
Enthusiast
Enthusiast

So for our title block. I just need the revision number to be incremented by 1. The revision blocks are a little different. We have 6 slots for revision blocks numbered one through 6. Each one has room for the date, 3 descriptions , drawn by and checked by. Is there a script that will take user defined information for these and automatically update the next available revision block? When all 6 have been filled out, we delete the first revblock, move all of the existing revision blocks down one, and then copy a revblock over to the new slot, and then update that new revision block with the rev number and then all the information described above. Would there be a script that could copy that action? 

0 Likes
Message 6 of 11

paullimapa
Mentor
Mentor

try this:

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/use-a-lisp-program-to-identify-the-revision-number-within-a/m-p/11544838#M439286
(defun c:TBLOCK (/ blkname chg en i sed sen ss tagname txt)
 (setq blkname "Tid22" chg 0 tagname "REV")
 (if(setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname) '(66 . 1))))
  (progn
   (repeat (setq i (sslength ss))
    (setq en (ssname ss (setq i (1- i))))  
    (setq sen (entnext en))                           ; get attributes
    (while sen
     (setq sed (entget sen))          
     (if (/= (cdr(assoc 0 sed)) "SEQEND") 
       (if(eq tagname (cdr(assoc 2 (entget sen))))
          (progn
           (setq txt(getpropertyvalue sen "TextString")) ; get current value
           (setq txt(itoa(1+ (atoi txt)))) ; increase # by 1
           (setpropertyvalue sen "TextString" txt) ; set updated value
           (setq sen nil chg (1+ chg))
          ) ; progn
          (setq sen (entnext sen))
       ) ; if found tag
       (setq sen nil)             
     ) ; if more attributes
    ) ; while attributes
   ) ; repeat
   (princ(strcat"\nTotal of [" (itoa chg) "] [" blkname "] Blocks with Tag [" tagname "] Updated."))
  ) ; progn
  (princ"\nNo Matching Block Objects Found.")
 ) ; if
  (princ)
) ; defun

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 11

gv6823otG42ZL
Enthusiast
Enthusiast

That worked!!. Thank you very much! Now here is my next issue which could use some input. Is there a lisp program that will take user defined information and fill in this information automatically? I would need the program to put the information on the next available revision Block. When all of them all full, the program will delete the first revision block, move the rest down one, and then copy a revision block over into the new slot and update it with the user defined information as well as the new revision number. for example, when all 6 of the rev blocks are filled out below, Revision one would be deleted, and then 2-6 would be moved down one, and a new revision block 7 would be inserted with the user defined information.

gv6823otG42ZL_1-1668126668938.png

 

gv6823otG42ZL_0-1668126631512.png

 

0 Likes
Message 8 of 11

paullimapa
Mentor
Mentor

Let me try and understand at least the first part of your question which is the information to fill out in your:

Block named = RevAtt ...which currently according to your screen shot has the following entries:

REVNO = 1

DATE = 11/10/2022 - assuming this is the format you want vs Nov 10, 2022 or a different order / combination of these

REVISION1 = ..... I assume you would want these to be limited in length and ok to be left empty?

REVISION2 =

REVISION3 =

REVBY = Paul Li or PLI or PAUL LI or some kind of combination again limited in length?

APPDBY = Paul Li or PLI or PAUL LI or some kind of combination again limited in length?

 

So instead of a dialog window (Enhanced Attribute Editor) presented for users to fill out, you prefer to have them enter all of these at the command line? Or are you thinking of running a Script file for these Attributes to just automatically be filled in?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 11

gv6823otG42ZL
Enthusiast
Enthusiast

Here is an example. What would be nice is when I am doing as-builts for 130 drawings, I could enter this once and have it populate to all of the drawings I am working on. the issue is when it comes to all 6 revision blocks being used and the first revision block needs to be deleted so the other revision blocks can slide down one and then a new revision block can be copied over and then updated with the new revision number and the information listed below

gv6823otG42ZL_0-1668127916248.png

 

0 Likes
Message 10 of 11

paullimapa
Mentor
Mentor

Assuming your 130 drawings each have the same Title Block as an Xref, then it would be simple to just add this information in the parent Title Block drawing and then all 130 drawings would reflect the change.

Now if you don't have the Title Block as an xreference, then you can actually run a routine like Lee Mac's Script Writer http://www.lee-mac.com/scriptwriter.html to open all the 130 drawings assuming they're under the same folder and Attach the drawing with the Attributes.  Again, the purpose is to make the change once and then all 130 drawings will automatically reflect this.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 11

Sea-Haven
Mentor
Mentor

Yes I do have a bump revs when its full and need to add a new one. Need a dwg to see what is going on regarding attribute tag names etc if attributes are made in an order then can do simply as do not need tag names.

 

Another similar to Paulli is I have fill in one title block in a layout and copy to all other layouts, usually use this as a 1st step. 

 

Do the 130 dwg's have multiple layouts or is it 1 dwg 1 layout ?

0 Likes