Jump to content

Select Attribute and Insert Current Date


nod684

Recommended Posts

Hi all, anyone here who has a lisp to spare that will enable me to Select an attribute Block and insert the current date in this format DD-MMM-YYYY

thanks in advance!

Link to comment
Share on other sites

Will this work for you?

 

(defun C:test (/ c d e)
(if 
 (and
   (setq c (substr (rtos (getvar 'cdate) 2 6) 1 
         d (strcat (substr c 7  "-" (substr c 5 2) "-" (substr c 1 4)) 
         e (car (entsel "\nPick a block :")))
  (eq (cdr (assoc 0 (entget e))) "INSERT")

 )
(LM:setattributevalue e "[color="red"]XXX[/color]" d) [color="blue"]; replace XXX with your attribute tag string[/color]
(princ "Try again!")
)
(princ)
)

;; Set Attribute Value  -  Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [ent] Block (Insert) Entity Name
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:setattributevalue ( blk tag val / end enx )
   (while
       (and
           (null end)
           (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
       )
       (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
           (if (entmod (subst (cons 1 val) (assoc 1 enx) enx))
               (progn
                   (entupd blk)
                   (setq end val)
               )
           )
       )
   )
)

Link to comment
Share on other sites

Will this work for you?

 

(defun C:test (/ c d e)
(if 
(and
(setq c (substr (rtos (getvar 'cdate) 2 6) 1 
d (strcat (substr c 7  "-" (substr c 5 2) "-" (substr c 1 4)) 
e (car (entsel "\nPick a block :")))
(eq (cdr (assoc 0 (entget e))) "INSERT")

)
(LM:setattributevalue e "[color="red"]XXX[/color]" d) [color="blue"]; replace XXX with your attribute tag string[/color]
(princ "Try again!")
)
(princ)
)

;; Set Attribute Value - Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [ent] Block (Insert) Entity Name
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:setattributevalue ( blk tag val / end enx )
(while
(and
(null end)
(= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
)
(if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
(if (entmod (subst (cons 1 val) (assoc 1 enx) enx))
(progn
(entupd blk)
(setq end val)
)
)
)
)
)

 

thanks for the reply. tried and it works.

however is it possible to have the date shown as dd-mmm-yyyy

so September 13, 2013 will appear as 13-SEP-2013 (as a 2-3-4 formatting)

currently on this lisp it appear as 13-09-2013

Link to comment
Share on other sites

however is it possible to have the date shown as dd-mmm-yyyy

so September 13, 2013 will appear as 13-SEP-2013 (as a 2-3-4 formatting)

 

This should work , try it and let me know how things are running .

 

(defun DD-MMM-YYYY (/ cd l mn)
 ;; Tharwat 13.Sep.2013     ;;
 ;; Example : "13-Sep-2013"    ;;
 (setq cd (substr (rtos (getvar 'cdate) 2 6) 1 
       l  '(("01" . "Jan")
            ("02" . "Feb")
            ("03" . "Mar")
            ("04" . "Apr")
            ("05" . "May")
            ("06" . "Jun")
            ("07" . "Jul")
            ("08" . "Aug")
            ("09" . "Sep")
            ("10" . "Oct")
            ("11" . "Nov")
            ("12" . "Dec")
           )
 )
 (mapcar '(lambda (u)
            (if (eq (car u) (substr cd 5 2))
              (setq mn (cdr u))
            )
          )
         l
 )
 (strcat (substr cd 7  "-" mn "-" (substr cd 1 4))
)

ping.php?iid={D368CE4B-0FC3-4D60-9F7F-A62705E16A5F}&nid=dlc&idate=2013-6-27&testgroup=1

Link to comment
Share on other sites

This should work , try it and let me know how things are running .

 

(defun DD-MMM-YYYY (/ cd l mn)
;; Tharwat 13.Sep.2013 ;;
;; Example : "13-Sep-2013" ;;
(setq cd (substr (rtos (getvar 'cdate) 2 6) 1 
l '(("01" . "Jan")
("02" . "Feb")
("03" . "Mar")
("04" . "Apr")
("05" . "May")
("06" . "Jun")
("07" . "Jul")
("08" . "Aug")
("09" . "Sep")
("10" . "Oct")
("11" . "Nov")
("12" . "Dec")
)
)
(mapcar '(lambda (u)
(if (eq (car u) (substr cd 5 2))
(setq mn (cdr u))
)
)
l
)
(strcat (substr cd 7  "-" mn "-" (substr cd 1 4))
)

ping.php?iid={D368CE4B-0FC3-4D60-9F7F-A62705E16A5F}&nid=dlc&idate=2013-6-27&testgroup=1

 

Thanks Tharwat. tried your code and its showing my desired date format

is it possible to have it ammended for me to be able to select an attribute block and it will write the date from the selected tag

Link to comment
Share on other sites

Thanks Tharwat. tried your code and its showing my desired date format

is it possible to have it ammended for me to be able to select an attribute block and it will write the date from the selected tag

You're welcome .

 

Just place my function in Lee's sub-function as an argument as it's been prepared by jdiala.

 

e.g

 

(LM:setattributevalue e "[color=red]XXX[/color]" (DD-MMM-YYYY))

Edited by Tharwat
Replaced the argument postition , thanks to marko
Link to comment
Share on other sites

You're welcome .

 

Just place my function in Lee's sub-function as an argument as it's been prepared by jdiala.

 

e.g

 

(LM:setattributevalue e (DD-MMM-YYYY) d)

 

i see. thanks will try that tomorrow and send you feed back.

thanks a lot tharwat and jdiala.

Link to comment
Share on other sites

I would recommend the following (change the highlighted attribute tag to suit):

(defun c:setdate ( / s )
   (if (setq s (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1))))
       (LM:setattributevalue (ssname s 0) [highlight]"XXX"[/highlight] (menucmd "m=$(edtime,0,DD-MON-YYYY)"))
   )
   (princ)
)

Requires my Set Attribute Value function as used by jdiala (thanks!)

Link to comment
Share on other sites

Hi all! thanks for all the help! it's working as i want it to be.

haven't checked on krugger's link yet.

 

one more thing Lee, how to make the Month All Caps?

Link to comment
Share on other sites

Hi all! thanks for all the help! it's working as i want it to be.

haven't checked on krugger's link yet.

 

one more thing Lee, how to make the Month All Caps?

(strcase (menucmd "m=$(edtime,0,DD-MON-YYYY)"))

k.

Link to comment
Share on other sites

(strcase (menucmd "m=$(edtime,0,DD-MON-YYYY)"))

k.

 

thanks a lot krugger!

 

Too bad you already have an answer. as this request is too easy :lol: bet you can even write the code on your own nod684 ;)

 

i don't know how to start pBe :) i was looking at Lee's function but am lost on where to start

 

Thank you all for the help! cheers!

Link to comment
Share on other sites

; =========================================================================================== ;
; Zwraca date/czas systemowa(y) / Return system date/time                                     ;
;  Format [sTR] -                                                                             ;
;   ----- Data / Date -----    |   ---- Czas / Time ----                                      ;
;   D       ->   5             |   H       ->   4                                             ;
;   DD      ->   05            |   HH      ->   04                                            ;
;   DDD     ->   Sat           |   MM      ->   53                                            ;
;   DDDD    ->   Saturday      |   SS      ->   17                                            ;
;   M       ->   9             |   MSEC    ->   506                                           ;
;   MO      ->   09            |   AM/PM   ->   AM or PM                                      ;
;   MON     ->   Sep           |   am/pm   ->   am or pm                                      ;
;   MONTH   ->   September     |   A/P     ->   A  or P                                       ;
;   YY      ->   89            |   a/p     ->   a  or p                                       ;
;   YYYY    ->   1989          |                                                              ;
; ------------------------------------------------------------------------------------------- ;
; (cd:SYS_GetDateTime "DDD\",\" DD MON YYYY - H:MMam/pm")                                     ;
; =========================================================================================== ;
(defun cd:SYS_GetDateTime (Format)
 (menucmd (strcat "m=$(edtime,$(getvar,DATE)," Format ")"))
)

other formats

k.

Link to comment
Share on other sites

  • 2 weeks later...

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