Jump to content

Lisp to write the current (static) date to an attribute


itacad

Recommended Posts

Hello, I have seen many solutions to write the current date in a "dynamic" way, that is, it corrects itself every time the file is opened.

Instead I was looking for a lisp to write the current date (dd/mm/yyyy) in an attribute in a "static" way, that is, as a simple correction of the text...but I didn't find anything.

I also ask if there are key combinations for entering "known" texts for example in excel, the current date can be inserted with ctrl+alt+a

 

Greetings

Link to comment
Share on other sites

As a very simple example -

(defun c:mydate ( / ent obj )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (nentsel)))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (not (vlax-write-enabled-p (setq obj (vlax-ename->vla-object ent))))
                    (princ "\nObject is on a locked layer.")
                )
                (   (not (vlax-property-available-p obj 'textstring))
                    (princ "\nInvalid object selected.")
                )
                (   (vla-put-textstring obj (menucmd "m=$(edtime,0,dd/mo/yyyy)")))
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

You can change the formatting code to suit.

Link to comment
Share on other sites

I've similar but not as succinct as Lees - only comment I have is I added an option "select text or enter delimitator" to allow for dd/mm/yy, dd-mm-yy, dd.mm.yy, and yy or yyyy  etc. formats - clients can be fickle

 

Example for OP for formatting if necessary:

(menucmd "m=$(edtime,0,dd-mo-yyyy)"))

 

Link to comment
Share on other sites

For a long time I have been using a lisp to update the blocks called "DATA" selected in the drawing with the current date. You can use it as a standalone lisp or within another lisp.

 

Running the "DATA" command from the command line: You will be asked for 2 points, the CDATE value will be read and the string DATETIME will be created finally, the attribute containing the date will be updated, but only blocks with the name "DATA" found in the area of the 2 points box.

 

By giving RETURN to the request for the first point, the date is reset: the 2 points will then be requested all selected "DATA" blocks will become equal to: 00/00/00_00:00

 

Conversely, if the date is to be generated by another lisp (e.g. MYPRINT. LSP), the entry point In this LISP it will be:

(x11:DATA pt1 pt2)    ....  To update to the new date: provide the 2 points PT1 and PT2!

 

My version works both on Autocad and on GSTARCAD: the peculiar thing is that I had to make 2 versions, because with GSTACAD I always got the winter time... so wrong by 1 hour six months a year!

DATA.LSP

Link to comment
Share on other sites

Thank you all for your help!

 

I would like to take this opportunity to thank Mr. Lee Mac, whom I have known by reputation long before discovering this forum! With his lisps he has solved many problems for me!
I would like to point out a couple of topics I have opened regarding his lisps that I use daily

 

Thanks!

https://www.cadtutor.net/forum/topic/77190-count-attribute-values/

https://www.cadtutor.net/forum/topic/93061-macatt-global-attribute-extractorlayer-information/

 

Link to comment
Share on other sites

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...