Updating Revision number of multiple block placed in model space
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Everyone,
I am trying to write a code to update the title block revision number for rev up. Since I have multiple title block to do the rev up. I am writing a lisp code, but its not working. I placed the codes in local folder name UpdateRev.lsp and used Appload to call. but call is not working for some reason.
any suggestion. Attached is the code:
(defun c:UpdateRev ()
(setq blkName "TB000000") ; The block name containing the revision attribute
(setq attrName "AB_REV") ; The attribute tag you want to update
;; Get all instances of the block in model space
(setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 blkName) (cons 410 "Model"))))
;; Check if any blocks were found
(if ss
(progn
(princ (strcat "\nFound " (itoa (sslength ss)) " instances of block " blkName))
;; Iterate over each block instance
(setq i 0)
(while (< i (sslength ss))
(setq ent (ssname ss i))
(setq entData (entget ent))
(princ (strcat "\nProcessing block instance #" (itoa i)))
;; Find all attributes of the block
(setq attList (vl-remove-if-not '(lambda (x) (eq (car x) 100)) (entget ent)))
(foreach att attList
(setq attEnt (entget (cdr (assoc -1 att))))
(if (and (eq (cdr (assoc 0 attEnt)) "ATTRIB") (eq (cdr (assoc 2 attEnt)) attrName))
(progn
(setq currentVal (cdr (assoc 1 attEnt)))
(princ (strcat "\nFound attribute " attrName " with value " currentVal))
(setq newVal (format "%02d" (1+ (atoi currentVal))))
(setq attEnt (subst (cons 1 newVal) (assoc 1 attEnt) attEnt))
(entmod attEnt)
(princ (strcat "\nUpdated revision from " currentVal " to " newVal))
)
(princ (strcat "\nAttribute " attrName " not found in this instance"))
)
)
(setq i (1+ i))
)
)
(princ "\nNo instances of block found.")
)
(princ)
)
(princ "\nType 'UpdateRev' to increment the revision number.")
(princ)