;; Last Modification Logging Utility - Lee Mac
;; Stores the username/date/command as xdata attached to every modified object.
;; Saved from: http://www.cadtutor.net/forum/showthread.php?89950-xdata-to-save-info-who-last-modified-objects&p=615831&viewfull=1#post615831

;; Type 'LASTMODON' to enable modification logging, and 'LASTMODOFF' to disable logging.

;; Type 'LASTMOD' to view the last modification data for an object.

;; Type 'LASTMODCLEAR' to remove the logged modification data for a set of objects.

(setq lastmod:appid "LMAC_lastmod")

(defun c:lastmod ( / ent lst )
(while
(progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect object to view modification data : ")))
(cond
( (= 7 (getvar 'errno))
(princ "\nMissed, try again.")
)
( (null ent) nil)
( (null (setq lst (mapcar 'cdr (cdadr (assoc -3 (entget ent (list lastmod:appid)))))))
(princ "\nSelected object does not contain modification data.")
)
( (princ (strcat "\nObject last modified by " (car lst) " at " (cadr lst) " using the " (caddr lst) " command.")))
)
)
)
(princ)
)
(defun c:lastmodclear ( / idx sel )
(if (setq sel (ssget "_:L" (list (list -3 (list lastmod:appid)))))
(repeat (setq idx (sslength sel))
(entmod (append (entget (ssname sel (setq idx (1- idx)))) (list (list -3 (list lastmod:appid)))))
)
)
(princ)
)
(defun c:lastmodon nil
(lastmod:remove)
(vlr-command-reactor "lastmod"
'(
(:vlr-commandwillstart . lastmod:com:start)
(:vlr-commandended . lastmod:com:ended)
(:vlr-commandcancelled . lastmod:com:clear)
(:vlr-commandfailed . lastmod:com:clear)
)
)
(setq lastmod:obj:rtr
(vlr-object-reactor
( (lambda ( sel / idx lst )
(if sel
(repeat (setq idx (sslength sel))
(setq lst (cons (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) lst))
)
)
)
(ssget "_X")
)
"lastmod"
'(
(:vlr-modified . lastmod:obj:modified)
(:vlr-subobjmodified . lastmod:obj:modified)
)
)
)
(regapp lastmod:appid)
(princ "\nObject modification logging enabled.")
(princ)
)
(defun c:lastmodoff nil
(lastmod:remove)
(princ "\nObject modification logging disabled.")
(princ)
)
(defun lastmod:remove nil
(foreach obj (apply 'append (mapcar 'cdr (vlr-reactors :vlr-object-reactor :vlr-command-reactor)))
(if (= "lastmod" (vlr-data obj)) (vlr-remove obj))
)
(setq lastmod:obj:rtr nil
lastmod:entlast nil
lastmod:objlist nil
)
)
(defun lastmod:obj:modified ( obj rtr arg )
(setq lastmod:objlist (cons obj lastmod:objlist))
(princ)
)
(defun lastmod:com:start ( rtr com / tmp )
(setq lastmod:entlast (entlast))
(while (setq tmp (entnext lastmod:entlast))
(setq lastmod:entlast tmp)
)
(princ)
)
(defun lastmod:com:ended ( rtr com / ent obj )
(setq com (strcase (car com))
ent (if lastmod:entlast (entnext lastmod:entlast) (entnext))
)
(foreach obj lastmod:objlist
(lastmod:addxdata (vlax-vla-object->ename obj) com)
)
(while ent
(if (vlax-write-enabled-p (setq obj (vlax-ename->vla-object ent)))
(progn
(lastmod:addxdata ent com)
(vlr-owner-add lastmod:obj:rtr obj)
)
)
(setq ent (entnext ent))
)
(setq lastmod:objlist nil
lastmod:entlast nil
)
(princ)
)
(defun lastmod:clear ( rtr arg )
(setq lastmod:objlist nil
lastmod:entlast nil
)
(princ)
)
(defun lastmod:addxdata ( ent com / enx )
(if (and (= 'ename (type ent))
(setq enx (entget ent))
(not (wcmatch (cdr (assoc 0 enx)) "VERTEX,ATTRIB,SEQEND"))
)
(entmod
(append (entget ent)
(list
(list -3
(list lastmod:appid
(cons 1000 (getvar 'loginname))
(cons 1000 (menucmd "m=$(edtime,0,yyyy-mo-dd hh:mm:ss)"))
(cons 1000 com)
)
)
)
)
)
)
)
(vl-load-com) (princ)

Advertisements