Search code examples
lispautocad

Return date and time in another format autocad


I have a little problem with my code. I want to disply the time and date in format from autocad is displayed. For example tdcreate command in autocad show 2458753.59648148 but this code show in the output file 26 September 2019 14:18:55:999. I don't know where is wrong. I want to appear 2458753.59648148 .

(progn
            (foreach item
               '(
                    ("Current time:"       "DATE"       "DD MONTH YYYY HH:MM:SS:MSEC")
                    ("Created:"            "TDCREATE"   "DD MONTH YYYY HH:MM:SS:MSEC")
                    ("Last updated:"       "TDUPDATE"   "DD MONTH YYYY HH:MM:SS:MSEC")
                    ("Total editing time:" "TDINDWG"    "HH:MM:SS:MSEC")
                    ("Elapsed timer:"      "TDUSRTIMER" "HH:MM:SS:MSEC")
                )
                (write-line
                    (strcat
                        (PadRight (car item) " " 24)
                        (apply 'FormatDate (cdr item))
                    )
                    openfile
                )
            )
            (close openfile)
            (startapp "notepad" filename)
        )
        (princ (strcat "\nUnable to Write to " filename))
    )
    (princ)
)

(defun PadRight ( string char lengtth )
    (if (< (strlen string) lengtth)
        (PadRight (strcat string char) char lengtth)
        string
    )
)

(defun GetUniqueFilename ( seed / count file flist )
    (if (findfile (setq file seed))
        (progn
            (setq count 1
                  flist (fnsplitl seed)
            )
            (while
                (findfile
                    (setq file
                        (strcat
                            (car   flist)
                            (cadr  flist)
                            "(" (itoa (setq count (1+ count))) ")"
                            (caddr flist)
                        )
                    )
                )
            )
        )
    )
    file
)

(defun FormatDate ( sysvar format )
    (menucmd (strcat "m=$(edtime,$(getvar," sysvar ")," format ")"))
)

Solution

  • In AutoCAD, the TDCREATE command is merely returning the value held by the TDCREATE system variable, which stores the Julian datetime value of when the drawing was created.

    The code that you have posted from my program is formatting this Julian datetime value using the DIESEL edtime function within a menu command expression.

    If you want the raw Julian value, you can simply use:

    (getvar 'tdcreate)
    

    Which could be formatted as a string using rtos, i.e.:

    (rtos (getvar 'tdcreate) 2 16)