@gv6823otG42ZL hi,
check this AUTOMOD (Auto Modify) command but hey, do not rush 😀 read all the instructions first.
for your requests 1+2+3 the command answer them very easily. request 4 was not easy challenge. in order it to work you need to specify the user defined information for revattr block, so this is implement as a lsp file which it content is like this:
(setq newRevData
'( ("revno" . "") ; place holder
("date" . "6-10")
("revision1" . "revision1")
("revision2" . "revision2")
("revision3" . "revision3")
("revby" . "revby")
("appdby" . "appdby")
); list
); setq
first open notepad than copy & paste this content in and save it in your document folder by the name of revdata.lsp you can save it with any name you like as long it's type must be lsp. (remember that name)
the data format is a list of dotted pairs items. each item holds 2 data strings, the first is TAG name and the second is the tag VALUE. the 2 strings are separate by dot "." (that's what dotted pairs means) you need to fill only the second data strings with the new revattr info. make sure you do not mess the format every character is important here. each data string must start and end with double apostrophe. the first dot pair ("revno" . "") is just place holder do not fill or delete it.
in your script program you need to load revdata.lsp along with automod.lsp each drawing you open.
the command starts with defining some constant variables, i'm talking about your blocks names the title block the P.E block, revattr block and the layer "rev current".
; define const for blocks name
(setq TITLEBLK "tad15")
(setq PEBLK "Certification MN-Appd")
(setq REVBLK "revattr")
; const for revision layer
(setq REVLAY "rev current")
; get attribute tag from block definition
(setq TAGS (get_attrib_def))
if in future you need to change these names, you can easily change them here and the command will still work.
also there is a TAGS variable which holds a list of tags name. these tag name is read directly from the block (revattr) definition. in future if you decide to add more attribute or change some, automod will read these changes and still work. note that you will have to sync these change with the content (tag names) in revdata.lsp.
now for the script:
two weeks ago a member of this forum ask about scripts i suggest you to look at it >> HERE << message #6 of 11
also look at @paullimapa advice on how to create the script.
enjoy
Moshe
(vl-load-com) ; load ActiveX support
; auto modifications
(defun c:automod (/ _dat get_attrib_def getAttribValue setAttribValue process_data ; local functions
upadte_revision_data shift_attribute_data update_revision_blocks ; local functions
TITLEBLK PEBLK REVBLK REVLAY TAGS ss ent rev data^)
; anonymous function
(setq _dat (lambda () (mapcar (function (lambda (d) (cdr d))) newRevData)))
(defun get_attrib_def (/ blocks lst)
(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for AcDbEntity (vla-item blocks REVBLK)
(if (eq (vla-get-objectName AcDbEntity) "AcDbAttributeDefinition")
(setq lst (cons (vla-get-tagString AcDbEntity) lst))
)
(vlax-release-object AcDbEntity)
); vlax-for
(vlax-release-object blocks)
(reverse lst)
); get_attrib_def
(defun getAttribValue (ent tag / val)
(if (not
(vl-catch-all-error-p
(setq val (vl-catch-all-apply 'getPropertyValue (list ent tag)))
)
); not
val
); if
); getAttribValue
(defun setAttribValue (ent tag val)
(not
(vl-catch-all-error-p
(vl-catch-all-apply 'setPropertyValue (list ent tag val))
)
); not
); setAttribValue
(defun process_data ()
(vl-sort
(mapcar
(function
(lambda (ename / lst)
(reverse
(cons
ename
(foreach tag TAGS
(setq lst (cons (getAttribValue ename tag) lst))
)
); cons
); reverse
); lambda
); function
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
); mapcar
(function (lambda (e0 e1) (< (car e0) (car e1))))
); vl-sort
); process_data
(defun upadte_revision_data (/ _nrd _fnd ; local function
orec nrec)
; anonymous functions
(setq _nrd (lambda () (mapcar (function (lambda (tag dat) (cons tag (cdr dat)))) TAGS newRevData)))
(setq _fnd (lambda () (vl-some (function (lambda (rev) (if (eq (cadr rev) "") rev))) data^)))
(if (setq orec (_fnd))
(progn
(setq nrec (cons (car orec) (append (cdr (_dat)) (list (last orec)))))
(foreach dotpair (subst (cons "revno" (car orec)) (assoc "revno" (_nrd)) (_nrd))
(setAttribValue (last orec) (car dotpair) (cdr dotpair))
)
(setq data^ (subst nrec orec data^))
); progn
); if
); upadte_revision_data
(defun shift_attribute_data ()
(reverse
(append
(list (cons (itoa (1+ (atoi (car (last data^))))) (append (cdr (_dat)) (list (last (last data^))))))
(mapcar
(function
(lambda (e0 e1)
(append (reverse (cdr (reverse e0))) (list (last e1)))
); lambda
); function
(reverse (cdr data^)) (cdr (reverse data^))
); mapcar
); append
); reverse
); shift_attribute_data
(defun update_revision_blocks ()
(vl-every
(function
(lambda (rev)
(vl-every
(function
(lambda (tag val)
(setAttribValue (last rev) tag val)
)
); function
TAGS rev
); vl-every
); lambda
); function
data^
); vl-every
); update_revision_blocks
; here start (c:automod)
; define const for blocks name
(setq TITLEBLK "tad15")
(setq PEBLK "Certification MN-Appd")
(setq REVBLK "revattr")
; const for revision layer
(setq REVLAY "rev current")
; get attribute tag from block definition
(setq TAGS (get_attrib_def))
; 1 + 2 - delete rev clouds + P.E stamp
(if (setq ss (ssget "_X" (list '(-4 . "<OR")
'(-4 . "<AND") '(0 . "lwpolyline") (cons '8 REVLAY) '(-4 . "AND>")
'(-4 . "<AND") '(0 . "insert") (cons '8 REVLAY) (cons 2 PEBLK) '(66 . 1) '(-4 . "AND>")
'(-4 . "OR>")
); list
); ssget
); setq
(foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
(entdel ent) ; delete revision clouds
)
); if
; 3 - increment revision cloud
(if (setq ss (ssget "_X" (list '(0 . "insert") (cons '2 TITLEBLK) '(66 . 1))))
(progn
(setq ent (ssname ss 0))
(if (setq rev (getAttribValue ent "rev"))
(setattribValue ent "rev" (itoa (1+ (atoi rev))))
)
; 4 - insert revision data
(if (setq ss (ssget "_X" (list '(0 . "insert") (cons '2 REVBLK)))) ; select revision slots
(progn
(setq data^ (process_data))
(if (not (upadte_revision_data)) ; revision slots is full
(setq data^ (shift_attribute_data))
); if
(update_revision_blocks)
); progn
); if
); progn
); if
(princ)
); c:automod