nod684 Posted September 13, 2013 Posted September 13, 2013 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! Quote
jdiala Posted September 13, 2013 Posted September 13, 2013 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) ) ) ) ) ) Quote
nod684 Posted September 13, 2013 Author Posted September 13, 2013 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 Quote
Tharwat Posted September 13, 2013 Posted September 13, 2013 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)) ) Quote
nod684 Posted September 13, 2013 Author Posted September 13, 2013 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)) ) 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 Quote
Tharwat Posted September 13, 2013 Posted September 13, 2013 (edited) Thanks Tharwat. tried your code and its showing my desired date formatis 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 September 13, 2013 by Tharwat Replaced the argument postition , thanks to marko Quote
nod684 Posted September 13, 2013 Author Posted September 13, 2013 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. Quote
marko_ribar Posted September 13, 2013 Posted September 13, 2013 Tharwat, shouldn't it be : (LM:setattributevalue e "[color=red]XXX[/color]" (DD-MMM-YYYY)) M.R. Quote
Tharwat Posted September 13, 2013 Posted September 13, 2013 Tharwat, shouldn't it be : (LM:setattributevalue e "[color=red]XXX[/color]" (DD-MMM-YYYY)) M.R. Thanks Marko . You're right . Quote
Lee Mac Posted September 13, 2013 Posted September 13, 2013 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!) Quote
Guest kruuger Posted September 17, 2013 Posted September 17, 2013 http://apps.exchange.autodesk.com/ACD/pl/Detail/Index?id=appstore.exchange.autodesk.com%3aapplycurrentdate%3aen or http://forum.cad.pl/cadpl-pack-v1-lsp-t78161.html kruuger Quote
nod684 Posted September 18, 2013 Author Posted September 18, 2013 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? Quote
Guest kruuger Posted September 18, 2013 Posted September 18, 2013 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. Quote
pBe Posted September 18, 2013 Posted September 18, 2013 Too bad you already have an answer. as this request is too easy bet you can even write the code on your own nod684 Quote
nod684 Posted September 19, 2013 Author Posted September 19, 2013 (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 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! Quote
Guest kruuger Posted September 19, 2013 Posted September 19, 2013 ; =========================================================================================== ; ; 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. Quote
Lee Mac Posted October 1, 2013 Posted October 1, 2013 I was looking at Lee's function but am lost on where to start Here is a reference for the DIESEL edtime function: http://exchange.autodesk.com/autocad/enu/online-help/browse#WS73099cc142f4875513fb5cd10c4aa30d6b-7afe.htm You're welcome! Quote
Recommended Posts
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.