Jump to content

Recommended Posts

Posted

I have a block which has a value I would like to modify using lisp. Its a revision triangle and what I'm looking to do to set the revision number based upon the highest number of all the other revision triangles currently on the title block. In otherwords, if the highest revision number is 8 I would like for the lisp to read that and add 1 to it and apply that number (9) to the revision triangle I'm putting on the title block.

 

Heres the code I use right now where I was using sslength to gather up the total number of revision triangles in the drawing and modify the "REV" value with that number, but that didn't account for a few and now I'm a bit stuck.

 

Oh, "REV" is the tag I'm looking to modify and the block's name is "revtri"

 

Thanks.

 

(defun c:revtri (/ time year month date ss1 count)
 (command "-LAYER" "S" "G-GENL-TEXT" "")                                          
 (setq time (rtos (getvar "CDATE") 2 )                                        
 (setq year (substr time 3 2))                                                   
 (setq day (substr time 5 2))                                                    
 (setq month (substr time 7 2))                                                    
 (setq date (strcat day "-" month "-" year))                                       
 (command "insert" "revtri" "rotate" "90" pause "" "" "01-01-03" "RECORD SET" "0")
 (setq ss1 (ssget "_X" '((0 . "insert") (2 . "revtri"))))                          
 (sssetfirst nil ss1)        
 (setq count (sslength ss1))    
 (command "._attedit" "_N" "_N" "REVTRI" "DATE:" "*" "01-01-03" date "graphscr")  
 (command "._attedit" "_N" "_N" "REVTRI" "REV" "*" "0" count "graphscr")  
 (princ)
 )

Posted

Welcome to CADTutor Dustin.

 

Consider the following quickly written code:

([color=BLUE]defun[/color] c:revtri ( [color=BLUE]/[/color] att bfn blk cmd cnt ent enx inc nme obj sel )
   ([color=BLUE]setq[/color] blk [color=MAROON]"revtri"[/color] [color=GREEN];; Block name[/color]
         blk ([color=BLUE]strcase[/color] blk)
   )    
   ([color=BLUE]if[/color] ([color=BLUE]or[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"BLOCK"[/color] ([color=BLUE]setq[/color] bfn blk)) ([color=BLUE]setq[/color] bfn ([color=BLUE]findfile[/color] ([color=BLUE]strcat[/color] blk [color=MAROON]".dwg"[/color]))))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] att ([color=BLUE]getvar[/color] 'attreq)
                 cmd ([color=BLUE]getvar[/color] 'cmdecho)
                 ent ([color=BLUE]entlast[/color])
                 cnt 0
           )
           ([color=BLUE]setvar[/color] 'attreq  0)
           ([color=BLUE]setvar[/color] 'cmdecho 0)
           ([color=BLUE]princ[/color] [color=MAROON]"\nSpecify Insertion Point: "[/color])
           ([color=BLUE]vl-cmdf[/color] [color=MAROON]"_.-insert"[/color] bfn [color=MAROON]"_S"[/color] 1.0 [color=MAROON]"_R"[/color] 90.0 [color=MAROON]"\\"[/color])
           ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]eq[/color] ent ([color=BLUE]setq[/color] ent ([color=BLUE]entlast[/color]))))
               ([color=BLUE]progn[/color]
                   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"INSERT"[/color]) ([color=BLUE]cons[/color] 2 ([color=BLUE]strcat[/color] [color=MAROON]"`*U*,"[/color] blk)))))
                       ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] inc ([color=BLUE]sslength[/color] sel))
                           ([color=BLUE]setq[/color] obj ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] inc ([color=BLUE]1-[/color] inc)))))
                           ([color=BLUE]if[/color] ([color=BLUE]vlax-property-available-p[/color] obj 'effectivename)
                               ([color=BLUE]setq[/color] nme ([color=BLUE]vla-get-effectivename[/color] obj))
                               ([color=BLUE]setq[/color] nme ([color=BLUE]vla-get-name[/color] obj))
                           )
                           ([color=BLUE]if[/color] ([color=BLUE]=[/color] ([color=BLUE]strcase[/color] nme) blk)
                               ([color=BLUE]setq[/color] cnt ([color=BLUE]1+[/color] cnt))
                           )
                       )
                   )
                   ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color]  ent))
                   ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] '(8 . [color=MAROON]"G-GENL-TEXT"[/color]) ([color=BLUE]assoc[/color] 8 enx) enx))
                   ([color=BLUE]setq[/color] ent ([color=BLUE]entnext[/color] ent)
                         enx ([color=BLUE]entget[/color]  ent)
                   )
                   ([color=BLUE]while[/color] ([color=BLUE]=[/color] [color=MAROON]"ATTRIB"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 enx)))
                       ([color=BLUE]cond[/color]
                           (   ([color=BLUE]=[/color] [color=MAROON]"DATE:"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 enx)))
                               ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 1 ([color=BLUE]menucmd[/color] [color=MAROON]"m=$(edtime,$(getvar,date),DD-MO-YY)"[/color])) ([color=BLUE]assoc[/color] 1 enx) enx))
                           )
                           (   ([color=BLUE]=[/color] [color=MAROON]"REV"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 enx)))
                               ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 1 ([color=BLUE]itoa[/color] cnt)) ([color=BLUE]assoc[/color] 1 enx) enx))
                           )
                       )
                       ([color=BLUE]setq[/color] ent ([color=BLUE]entnext[/color] ent)
                             enx ([color=BLUE]entget[/color]  ent)
                       )
                   )
               )
           )
           ([color=BLUE]setvar[/color] 'cmdecho cmd)
           ([color=BLUE]setvar[/color] 'attreq  att)
       )
       ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\n"[/color] blk [color=MAROON]" block not found."[/color]))
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

The above accounts for whether REVTRI is a dynamic block.

I have also assumed 90 degree block rotation based on your code.

Posted

First off, thanks for the code, its very much appreciated.....but it doesn't quite work. What its doing right now seems to be just reading the number of revision triangles in the drawing and modifying the "REV" attribute's value to that number and then increasing it by 1. I could very well be wrong on what exactlyis going on but when I add my 5th revision triangle for example it changes the value to 5 even if the value of revision triangle #4 is 6 to where I was looking for it change the value of the revision triangle #5 to 7 in that case. Another thing is the date comes in as day-month-year instead of month-day-year, but thats easy enough to fix. Great code though, it works much better than the one I had written beacuse it doesn't have to open the attribute editor and close it two different times, I hated having to do that because it looked sloppy having a dialog box flash twice on the screen like that every time you inserted that block.

Posted (edited)

Try this quick modification:

([color=BLUE]defun[/color] c:revtri ( [color=BLUE]/[/color] att bfn blk cmd cnt ent enx inc lst nme obj sel tag )
   ([color=BLUE]setq[/color] blk [color=MAROON]"revtri"[/color] [color=GREEN];; Block name[/color]
         blk ([color=BLUE]strcase[/color] blk)
   )    
   ([color=BLUE]if[/color] ([color=BLUE]or[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"BLOCK"[/color] ([color=BLUE]setq[/color] bfn blk)) ([color=BLUE]setq[/color] bfn ([color=BLUE]findfile[/color] ([color=BLUE]strcat[/color] blk [color=MAROON]".dwg"[/color]))))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] att ([color=BLUE]getvar[/color] 'attreq)
                 cmd ([color=BLUE]getvar[/color] 'cmdecho)
                 ent ([color=BLUE]entlast[/color])
                 cnt 0
           )
           ([color=BLUE]setvar[/color] 'attreq  0)
           ([color=BLUE]setvar[/color] 'cmdecho 0)
           ([color=BLUE]princ[/color] [color=MAROON]"\nSpecify Insertion Point: "[/color])
           ([color=BLUE]vl-cmdf[/color] [color=MAROON]"_.-insert"[/color] bfn [color=MAROON]"_S"[/color] 1.0 [color=MAROON]"_R"[/color] 90.0 [color=MAROON]"\\"[/color])
           ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]eq[/color] ent ([color=BLUE]setq[/color] ent ([color=BLUE]entlast[/color]))))
               ([color=BLUE]progn[/color]
                   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"INSERT"[/color]) ([color=BLUE]cons[/color] 2 ([color=BLUE]strcat[/color] [color=MAROON]"`*U*,"[/color] blk)) '(66 . 1))))
                       ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] inc ([color=BLUE]sslength[/color] ([color=BLUE]ssdel[/color] ent sel)))
                           ([color=BLUE]setq[/color] obj ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] inc ([color=BLUE]1-[/color] inc)))))
                           ([color=BLUE]if[/color] ([color=BLUE]vlax-property-available-p[/color] obj 'effectivename)
                               ([color=BLUE]setq[/color] nme ([color=BLUE]vla-get-effectivename[/color] obj))
                               ([color=BLUE]setq[/color] nme ([color=BLUE]vla-get-name[/color] obj))
                           )
                           ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] ([color=BLUE]strcase[/color] nme) blk)
                                   ([color=BLUE]setq[/color] att
                                       ([color=BLUE]vl-some[/color]
                                           ([color=BLUE]function[/color]
                                               ([color=BLUE]lambda[/color] ( x )
                                                   ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"REV"[/color] ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-tagstring[/color] x)))
                                                       ([color=BLUE]atoi[/color] ([color=BLUE]vla-get-textstring[/color] x))
                                                   )
                                               )
                                           )
                                           ([color=BLUE]vlax-invoke[/color] obj 'getattributes)
                                       )
                                   )
                               )
                               ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] att lst))
                           )
                       )
                   )
                   ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ent))
                   ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] '(8 . [color=MAROON]"G-GENL-TEXT"[/color]) ([color=BLUE]assoc[/color] 8 enx) enx))
                   ([color=BLUE]foreach[/color] att ([color=BLUE]vlax-invoke[/color] ([color=BLUE]vlax-ename->vla-object[/color] ent) 'getattributes)
                       ([color=BLUE]setq[/color] tag ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-tagstring[/color] att)))
                       ([color=BLUE]cond[/color]
                           (   ([color=BLUE]=[/color] [color=MAROON]"DATE:"[/color] tag)
                               ([color=BLUE]vla-put-textstring[/color] att ([color=BLUE]menucmd[/color] [color=MAROON]"m=$(edtime,$(getvar,date),MO-DD-YY)"[/color]))
                           )
                           (   ([color=BLUE]=[/color] [color=MAROON]"REV"[/color] tag)
                               ([color=BLUE]vla-put-textstring[/color] att ([color=BLUE]itoa[/color] ([color=BLUE]1+[/color] ([color=BLUE]apply[/color] '[color=BLUE]max[/color] lst))))
                           )
                       )
                   )
               )
           )
           ([color=BLUE]setvar[/color] 'cmdecho cmd)
           ([color=BLUE]setvar[/color] 'attreq  att)
       )
       ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\n"[/color] blk [color=MAROON]" block not found."[/color]))
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Edited by Lee Mac
Posted

That one works exactly as I need it to, the only thing is that the first revision triangle comes in with the REV value being 2 instead of 1. My guess is because its seeing itself as an existing revtri when its the only one existing in the drawing and then adding 1 to its own value?

Posted
Perfect! Thanks for your help.

 

You're welcome; if you have any questions about the code, just ask.

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...