;Rename file with addition of "Xref-" in a begining of the file and current date in the end of file
;with close current drawing, delete it and open renamed file in a one click ..by Igal Averbuh 2015
;Based on idea of Kerry Brown. See topic:
http://www.theswamp.org/index.php?topic=50551.msg556774#msg556774

(defun c:tpz (/ 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

()
;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

(setq file1 (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".dwg"))
(setq file (strcat (getvar 'dwgprefix) "XREF-" (vl-filename-base (getvar 'dwgname)) "-TPZ-" thedate ))
(if (findfile file)
(vl-cmdf "_Saveas" "2013" file )
(vl-cmdf "_Saveas" "2013" file "y")
)
;(command "_close" "n")

(vl-file-delete file1)

;(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 ))

;(setq by1 (strcat "NOPLOT - " " " thedate " " thetime ))

;(command "-layer" "filter" "N" "P" "" "PLOTTABLE==\"False\"" by1 "x" "")

;(command "-layer" "filter" "s" "All" "x" "")

;(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)

(c:tpz)

Advertisements