Reference the largest variable

Reference the largest variable

jason.schmidtA4U2P
Explorer Explorer
1,119 Views
15 Replies
Message 1 of 16

Reference the largest variable

jason.schmidtA4U2P
Explorer
Explorer

On the left of my sample title block, you can see that I have 3 revisions and they are numbered 1, 2 and 3.  On the right side of my drawing title block,  I have an area that lists the current revision number.  I have about 20k+ drawings and about half of the bottom right "##" revision number areas are blank or outdated.  Is there a way that I can reference the largest revision number on the left to automatically update the area on the right?  OR... since I also have a spreadsheet with the most updated revision numbers, could I possibly search my drawings to see if that REV area of my drawing is blank, and if that area IS blank, then insert the revision number as text from my spreadsheet?  Ideally some sort of script since I have so many files to update would be best.  

 

I can currently see my revisions but I'm unsure how to reference the "max" or highest revision number in my list.  The script I'm using to view my revisions is:

 

(defun C:JSREV (/ blkss ent foundit att maximum); = block REV's Attributes
(vl-load-com)
(if (setq blkss (ssget "_X" '((2 . "PGREV401,PGREV301,PGREV003,PGREVD,PGREV006,PGREV008,PGREV202,PGREV203,PGREV302,PGREV303"))))

(progn ; then

(prompt "\nComments:")
(repeat (sslength blkss)

(setq ent (ssname blkss 0))
(while
(and
(not foundit)
(setq ent (entnext ent))
(= (cdr (assoc 0 (entget ent))) "ATTRIB")
); end and
(setq att (vlax-ename->vla-object ent))
(IF (=(vla-get-TagString att) "REVNO")
(progn
(setq foundit T)
(prompt (strcat "\n" (vla-get-TextString att)))
); progn
); IF
); while
(setq foundit nil)
(ssdel (ssname blkss 0) blkss)
); repeat

); progn
); if
(princ)
); defun

 

I know I have a mess with different title blocks amongst my 20k+ files, but for right now I just want to get one thing working at a time.  We have 40 years of drawings and everyone had their own ideas on how to do them and I've been tasked with getting them back in order so any suggestions or recommendations are appreciated.  Hopefully this all makes sense.

0 Likes
1,120 Views
15 Replies
Replies (15)
Message 2 of 16

ronjonp
Mentor
Mentor

Attaching a drawing would be better to troubleshoot this.

 

Here's an untested quick example of what I think you're trying to accomplish:

 

(defun c:jsrev (/ r s)			; = block REV's Attributes
  (vl-load-com)
  (if (setq s
	     (ssget
	       "_X"
	       '((2
		  .
		  "PGREV401,PGREV301,PGREV003,PGREVD,PGREV006,PGREV008,PGREV202,PGREV203,PGREV302,PGREV303"
		 )
		)
	     )
      )
    (progn (foreach e (mapcar 'cadr (ssnamex s))
	     ;; (setq r nil)
	     (foreach att (vlax-invoke (vlax-ename->vla-object e) 'getattributes)
	       (if (wcmatch (vla-get-tagstring att) "REV*")
		 (setq r (cons (vla-get-textstring att) r))
	       )
	     )
	   )
	   ;; This line will print your largest REV number
	   (print (apply 'max (mapcar 'atof r)))
    )
  )
  (princ)
)
(vl-load-com)
;; Example
;; (apply 'max (mapcar 'atof '("5" "12" "0" "##" "88")))

 

 

0 Likes
Message 3 of 16

devitg
Advisor
Advisor

@ronjonp Should it not be ?

(vla-get-tagstring "PGREV*") 

 

0 Likes
Message 4 of 16

ronjonp
Mentor
Mentor

@devitg wrote:

@ronjonp Should it not be ?

(vla-get-tagstring "PGREV*") 

 


Don't think so .. the (2 . "PGREV") are block names. This is why I asked for a sample drawing. 

 

If anything the filter could be shortened to this:

 

(setq s (ssget "_X" '((2 . "PGREV###,PGREVD"))))

 

Message 5 of 16

jason.schmidtA4U2P
Explorer
Explorer

Hopefully this drawing attachment comes though.  The only thing that seems to work on it so far is my original script for some reason.  I can see all the revision numbers, just can't seem to get it to post the max revision number only.  Perhaps there's some way to reference my highest revision via  a field but I can't seem to find that either.  Thanks for all of your help everyone... let me know if you can't view the dwg attachment and I'll try something else.

0 Likes
Message 6 of 16

dbroad
Mentor
Mentor

Perhaps the following function, which would return the highest integer revno for use in a calling function. If you have real numbers, than you would need atof instead of atoi. The function takes the argument of the block name variations in string form. In this case, it would seem to make sense to call with (MAXREVNO "PGREV*"). If your tagstring varies you could add a tag argument and use wcmatch instead of = to compare.

;;DCB2023-Return maximum revno in DWG
(defun maxrevno	 (blkname)
  (cond
    ((ssget "x" (list (cons 2  blkname)))
     (vlax-for n  (vla-get-activeselectionset
		    (setq doc (vla-get-activedocument (vlax-get-acad-object))))
       (if (vla-get-hasattributes n)
	 (progn	(setq atts (vlax-invoke n 'getattributes))
		(setq revno (atoi
			      (vl-some '(lambda	(att)
					  (if (= (setq ts (vla-get-tagstring att)) "REVNO")
					    (vla-get-textstring att)))
				       atts)))
		(setq revnos (cons revno revnos)))))))
  (if revnos
    (apply 'max revnos)
    0))

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 7 of 16

ronjonp
Mentor
Mentor

@jason.schmidtA4U2P  I updated the code above. Where are you "posting" the max number?

0 Likes
Message 8 of 16

jason.schmidtA4U2P
Explorer
Explorer

To a location IN the drawing.... I may also run a script to get the max revision of each file and bring it to a CSV file later but for now, I'd just like to reference it IN the drawing itself.  Every revision of a drawing is added with a new number and then at the bottom right corner of each drawing, there is a spot for the "current revision" and that's kind of where I'd like to reference the largest number revision so I don't have to update that area each time a revision is made... someone always forgets to update the current revision area when adding a new revision... it never fails.  Hope that makes sense.

 

0 Likes
Message 9 of 16

ronjonp
Mentor
Mentor

@jason.schmidtA4U2P Assuming you only have one titleblock to update per drawing then my code above should work with some slight mods.

If you post a more real world example rather than pieces I'm sure we could get you 100% there.

 

Why don't you have those REV attributes as part of the titleblock rather than PGREV### ?

0 Likes
Message 10 of 16

john.uhden
Mentor
Mentor

@ronjonp ,

It could be like my previous job (I have a new one; YAY!) where the revision block is separate.  You could leave a blank one above the title block and with each revision after the first you just copy the previous one up and change the entries.  You don't want to add a new revision block if there were no revisions to that sheet, but you might want to use SSM to update the title sheet showing the latest revision date for each sheet in the set.

John F. Uhden

0 Likes
Message 11 of 16

ronjonp
Mentor
Mentor

@john.uhden 

I still don't see why the OP would have umpteen blocks with different names that have the same information ? If these attributes were part of the same titleblock then it's simple to update the latest "REV". Then again I'm not a fan of duplicate information for this exact reason .. problems created by bad design.

0 Likes
Message 12 of 16

jason.schmidtA4U2P
Explorer
Explorer

The short answer to your question is this, this company has been in business for 40+ years and have over 100k+ drawings compiled over that time.  It should've had a document management system years ago but the last time they tried everyone was afraid of "the cloud".  Haha  Anyways, these drawing have been compiled from a variety of engineers and non-engineers alike so nothing was done a standard way, not to mention the fact that they also received files from a handful of engineering companies over the years and the title blocks were never changed or changed "in their own way".  So yes, this is a product of bad design from the day they started and poor follow through over the years.  My goal is to try to get them somewhat standardized so that eventually we can roll this into a document management system without a huge hassle.  On top of all of this, the company was recently sold and now all of the logos in the title blocks have changed as well as any information regarding the old company.  I know I have a huge mess but I'm trying to properly set up a decent title block that isn't going to cause problems down the road.  Many of these drawings are just scanned images of pages that were put into an old title block but that's going to be a whole other issue.  So to answer your question, I don't know why anyone did what they did either... I'm just here to try to fix it.... or at least try to get it under control.   If anyone has used a good CAD management program I'm open to suggestions.  I'd rather not hear sales pitches and would rather hear from people who've used the system.   Sorry for the long post, just trying to laydown the backstory for this so everyone is up to speed on where I'm sitting so that I can avoid the "why" questions..... WHY indeed!  LOL  Thanks everyone!

0 Likes
Message 13 of 16

pbejse
Mentor
Mentor

"But why male models?"

0 Likes
Message 14 of 16

john.uhden
Mentor
Mentor

@ronjonp ,

I believe Jason explained the bad decisions over the last 40+ years.  Our mission, should we decide to accept it, is to lead him toward a DWG management system including title block strategy that is simple but effective.

I'm wondering if his projects include multiple layouts within one dwg or multiple and whether SSM is part of the solution.  I think we may need Peter Graves to guide us.

John F. Uhden

0 Likes
Message 15 of 16

ronjonp
Mentor
Mentor

@john.uhden  He did explain and par usual picking up a **** show. I'm willing to help, I like to get a bit of context beforehand.

0 Likes
Message 16 of 16

Sea-Haven
Mentor
Mentor

We have a database and can look up dwgs since 1999 and open them, it is a custom database based on Access, so as its like Excel can be easy to use. It has like 20 items per record.

 

Anyway back to the problem. The title block used on old dwgs has a name so used a replace method to update to Todays title block, this has changed a little bit over time same company but different office address very simple to update, Important part is don't bother going back and updating old dwgs unless required. Why update 10 year old projects that are finished or even in our case not there any more. Multi story office where there was a carpark. Why update car park dwg does not exist anymore.

 

Yes have a good title block with all items in one title block ours had 22 attributes, 5 of revisions. As Ronjonp suggested, multi layouts and so on. Like 7 lisp programs that did something to the title block, 88 layouts in one dwg. 

 

Lastly can probably write multiple lisps to read old multi titles into the new one and erase old ones, save as new dwg.

0 Likes