;View State, UCS and Layer State with date,time stamp and user name. Upgrated by Igal Averbuh 2015

(defun C:ls (/ ss1 count emax en ed blkn found
thedate thetime plotby)
;define function and declare variables as local

(setvar "HIGHLIGHT" 0)
;switch off highlight

(setvar "CMDECHO" 0)
;switch off command echo

(setq ss1 (ssget "X" '((0 . "INSERT")(66 . 1))))
;filter for all blocks with attributes

(if ss1
;if any are found

(progn
;do the following

(setq count 0
;set the counter to zero

emax (sslength ss1)
;get the number of blocks

);setq

(while (< count emax)
;while the counter is less than the
;number of blocks

(setq en (ssname ss1 count)
;get the entity name

ed (entget en)
;get the entity list

blkn (dxf 2 ed)
;get the block name

);setq

(if (= "STAMP")
;if the block name is "STAMP"

(setq count emax
;stop the loop

found T
;set the flag

);setq

(setq count (1+ count))
;if not increment the counter

);end if

);while & if

(if found
;if the flag is set

(command "ERASE" en "")
;erase the block

);if

);progn

);if

(setvar "ATTDIA" 0)
;switch off dialogue boxes

(setq thedate (today))
;calculate and format date

(setq thetime (time))
;calculate and format time

(setq plotby (getvar "LOGINNAME"))
;get the users name

(layerstate-save (strcat "LS " thedate " " thetime " by " plotby) nil nil)

(command "ucs" "na" "s" (strcat "UCS " thedate " " thetime " by " plotby))

(command "-view" "s" (strcat "VS " thedate " " thetime " by " plotby))

(setq by (strcat "Updated by " plotby " " thedate " " thetime ))

(command "-layer" "n" by "")

()
;insert the block and fill in the attribute data

(setvar "ATTDIA" 1)
;switch the dialogues back on

(setvar "HIGHLIGHT" 1)
;switch Highlight On

(setvar "CMDECHO" 1)
;switch Cmdecho On

(princ)

);defun

;===============================================================
(defun dxf(code elist)

(cdr (assoc code elist))
;finds the association pair, strips 1st element

);defun
;===============================================================
(defun TODAY ( / d yr mo day)
(setq d (rtos (getvar "CDATE") 2 6)
yr (substr d 3 2)
mo (substr d 5 2)
day (substr d 7 2)
);setq
(strcat day "-" mo "-" yr)
);defun
;;;*-----------------------------------------------------------
(defun TIME ( / d hr m s)
(setq d (rtos (getvar "CDATE") 2 6)
hr (substr d 10 2)
m (substr d 12 2)
s (substr d 14 2)
);setq
(strcat hr "-" m "-" s)
);defun
;;;*------------------------------------------------------------
(princ)

Advertisements