Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change to today date

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
377-83869076
1339 Views, 5 Replies

Change to today date

Hi guys hav a GooD dAy...!!

 

i want to paste the today date over the selected text after that zoom extent the screen automatically by lisp ...

i attached files for ur reference.

Plz help me this bcz the same change i hav to do 40 files per day...

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: 377-83869076

Something like this perhaps.

 

(vl-load-com)
(defun c:demo (/ cd day dte mth obj ss txt yer)
  (prompt "\nSelect Text text to place current date: ")
  (if (setq ss (ssget "_+.:E:S:L" '((0 . "TEXT,MTEXT"))))
    (progn
      (or *acad*
	  (setq *acad* (vlax-get-acad-object))
      )
      (setq obj	(vlax-ename->vla-object (ssname ss 0))
	    cd	(getvar "CDATE")
	    dte	(rtos cd 2 4)
	    yer	(substr dte 1 4)
	    mth	(substr dte 5 2)
	    day	(substr dte 7 2)
	    txt	(strcat day "." mth "." yer)
      )
      (vlax-put obj 'TextString txt)
      (vla-zoomextents *acad*)
    )
  )
  (princ)
)

 

HTH

Henrique

EESignature

Message 3 of 6
Lee_Mac
in reply to: 377-83869076

Here are two options, the first uses a Field (i.e. the text will automatically update to display the current date), the second uses plain text:

 

(defun c:test1 ( / ent )
    (while
        (progn (setvar 'errno 0) (setq ent (car (nentsel "\nSelect text, mtext or attribute: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent) nil)
                (   (not (wcmatch (cdr (assoc 0 (entget ent))) "TEXT,MTEXT,ATTRIB"))
                    (princ "\nInvalid object selected.")
                )
                (   (vla-put-textstring (vlax-ename->vla-object ent) "%<\\AcVar Date \\f \"dd.MM.yyyy\">%"))
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

 

(defun c:test2 ( / ent )
    (while
        (progn (setvar 'errno 0) (setq ent (car (nentsel "\nSelect text, mtext or attribute: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent) nil)
                (   (not (wcmatch (cdr (assoc 0 (entget ent))) "TEXT,MTEXT,ATTRIB"))
                    (princ "\nInvalid object selected.")
                )
                (   (vla-put-textstring (vlax-ename->vla-object ent) (menucmd "m=$(edtime,0,dd.mo.yyyy)")))
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Message 4 of 6
377-83869076
in reply to: 377-83869076

Thanks its work .... Man Very Happy ( hmsilva )

Message 5 of 6
hmsilva
in reply to: 377-83869076


@377-83869076 wrote:

Thanks its work .... Man Very Happy ( hmsilva )


You're welcome!
Glad I could help

 

Henrique

EESignature

Message 6 of 6
rshortacad
in reply to: 377-83869076

I modified hmsilva's lisp lines and made them bold.

-Changed .'s to /'s

-Changed Month/Day/Year

-Added string to omit the zero in front of the months with 01-09 number months.

 

(vl-load-com)
(defun c:cd (/ cd day dte mth obj ss txt yer)
  (prompt "\nSelect Text text to place current date: ")
  (if (setq ss (ssget "_+.:E:S:L" '((0 . "TEXT,MTEXT"))))
    (progn
      (or *acad*
   (setq *acad* (vlax-get-acad-object))
      )
      (setq obj (vlax-ename->vla-object (ssname ss 0))
     cd (getvar "cdate")
     dte (rtos cd 2 4)
     yer (substr dte 3 2)
     mth (itoa(atoi(substr dte 5 2)))
       day (substr dte 7 2)
       txt (strcat mth "/" day "/" yer)
      )
      (vlax-put obj 'TextString txt)
    )
  )
  (princ)
)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost