Jump to content

Recommended Posts

Posted

Hi!

I have this code that i found here in the forum it was created by @rlx.

 

My question is how to add an automatic current date and time to the end of the file when im saving it.

 

Many thanks! xoxo

(defun c:foo (/ _dir F NF P SF SH)

 (defun _dir (msg path / sh folder out)

   (or (vl-file-directory-p path) (setq path (getvar 'dwgprefix)))

   (cond ((and  (setq sh (vlax-get-or-create-object "Shell.Application"))

  (setq folder (vlax-invoke-method sh 'browseforfolder 0 msg "&H2000" path))

   )

   (setq out (vlax-get-property (vlax-get-property folder 'self) 'path))

   (setq out (strcat (vl-string-right-trim "\\" out) "\\"))

  )

   )

   (and sh (vlax-release-object sh))

   out

 )

 (if (setq p (_dir "Pick a directory yo!" "E:\\Autocad Files\\SSC\\North Region\\SNE\\"))

   (progn

     (setq f (getvar 'dwgname))

     (setq sf "Plans")

     (setq nf (strcat p sf "\\" f))

     (cond

((cond

   ((findfile nf) (print "File exists...") nil)

   ((vl-file-directory-p (strcat p sf)) (vl-file-copy (strcat (getvar 'dwgprefix) f) nf) t)

   ((vl-mkdir (strcat p sf)) (vl-file-copy (strcat (getvar 'dwgprefix) f) nf) t)

 )

 (setq sh (vlax-get-or-create-object "Shell.Application"))

 (vlax-invoke-method sh 'open nf)

 (vlax-release-object sh)

)

     )

   )

 )

 (princ)

)

(vl-load-com)
Posted (edited)

This is what I use

(menucmd "M=$(edtime, $(getvar,date),DD-MO-YYYY - HH:MM:SS AM/PM)")


--edit

For file name replaced the / with -  in the date so it won't error

Edited by mhupp
  • Like 1
Posted

I have a field %<\AcVar SaveDate \f "M/d/yyyy">% with Date all my drawing are saved in all my title blocks.

While I've never added the date to a file name I'd probably keep it as short as possible if I had to. The 20 in 2022 shouldn't matter for anyone doing cad now in their lifetime so I'd cut that off as well.

Posted (edited)
21 minutes ago, tombu said:

I have a field %<\AcVar SaveDate \f "M/d/yyyy">% with Date all my drawing are saved in all my title blocks.

Same here 👍

 

With a bit more info:
 

"File: %<\\AcVar Filename \\f \"%tc3%fn7\">% printed by %<\\AcVar Login>% on %<\\AcVar PlotDate \\f \"M/d/yyyy h:mm:ss tt\">% using AutoCAD Version: %<\\AcVar acadver>%"

 

Edited by ronjonp
  • Like 1
Posted
46 minutes ago, mhupp said:
(menucmd "M=$(edtime, $(getvar,date),DD-MO-YYYY - HH:MM:SS AM/PM)")

@mhupp No need for AM/PM, the results are returned in military time. 

Posted

Thanks!

 

I am very new to LISP can someone help me where to put the "(menucmd "M=$(edtime, $(getvar,date),DD-MO-YYYY - HH:MM:SS AM/PM)")"?

 

Do i need to assign it to a variable and then strcat them or how?

 

THANKS

Posted
2 hours ago, donat768 said:

Thanks!

I am very new to LISP can someone help me where to put the "(menucmd "M=$(edtime, $(getvar,date),DD-MO-YYYY - HH:MM:SS AM/PM)")"?

Do i need to assign it to a variable and then strcat them or how?

THANKS

 

UPDATE LINE

(setq nf (strcat p sf "\\" f))
TO
(setq nf (strcat p sf "\\" (menucmd "M=$(edtime, $(getvar,date),DD-MO-YYYY - HH:MM:SS AM/PM)") "-" f))

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...