guitarguy1685 Posted December 23, 2014 Posted December 23, 2014 So I know how to get the date from autocad using CDATE. And I know how to parse that info to get 12/23/14. But how can I, for example, get the 12 to be "DEC". Do I need to make a multiple if statement for that part of the string? Quote
hanhphuc Posted December 23, 2014 Posted December 23, 2014 So I know how to get the date from autocad using CDATE. And I know how to parse that info to get 12/23/14. But how can I, for example, get the 12 to be "DEC". Do I need to make a multiple if statement for that part of the string? you can use.. (cond (1 "JAN")(2 "FEB")....) my example using mapcar (defun mth ( m / i l) ;hanhphuc 24/12/2014 (setq i 13 ) (eval (cons 'cond (mapcar '(lambda (a b /) (list (eval (cons '= (list m 'a))) b)) (repeat 12 (setq l (cons (setq i (1- i)) l))) '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEPT" "OCT" "NOV" "DEC") ) ;_ end of mapcar ) ;_ end of cons ) ;_ end of eval ) functional call: (mth 12) ; returns "DEC" since you know coding, so the rest try it yourself using string function strcat , substr , vl-string-search etc.. p/s: i'm ibanez fan merry X'mas donate to CADtutor Quote
ymg3 Posted December 24, 2014 Posted December 24, 2014 guitarguy1685, Alternatively, simply create an assoc list like so: (setq month '((1 . "JAN")(2 . "FEB")(3 . "MAR")(4 . "APR") (5 . "MAY")(6 . "JUN")(7 . "JUL")(8 . "AUG") (9 . "SEP")(10 . "OCT")(11 . "NOV")(12 . "DEC")) ) Now whenever you need the month just issue: (cdr (assoc 3 month)) will return "MAR" etc. ymg Quote
hanhphuc Posted December 24, 2014 Posted December 24, 2014 Now whenever you need the month just issue: (cdr (assoc 3 month)) will return "MAR" etc. ymg 1+ season greetings: ymg, i'd like to take this opportunity to credit some of your sub-functions i used in this forum. thank you merry X'mas hanhphuc Quote
ymg3 Posted December 24, 2014 Posted December 24, 2014 (edited) hanhphuc, Season's greeting ! to you too and all the best. ymg Edited December 24, 2014 by ymg3 Quote
Tharwat Posted December 24, 2014 Posted December 24, 2014 Another , (nth (1- 12) '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEP" "OCT" "NOV" "DEC")) Quote
AIberto Posted December 25, 2014 Posted December 25, 2014 ;;date-->cdate ;;;;http://bbs.mjtd.com/thread-112484-1-1.html (defun Date->CDate (date / s) (setq s (strcat "M=$(edtime," (rtos date 2 ",YYYYMODD.HHMMSS)")) (atof (menucmd s)) ) ;defun ;;cdate-->date ;;;;http://bbs.mjtd.com/thread-112484-1-1.html (defun CDate->Date (cdate / Round Time Diff cd dt i0 i n s) (defun Round (x) (if (>= x 0) (fix (+ x 0.5)) (fix (- x 0.5)) ) ;if ) ;defun (defun Time (dt / x h m s) (setq x (Round (rem (* dt 1E6) 1E6))) (setq h (/ x 10000) m (/ (rem x 10000) 100) s (rem x 100) ) (/ (+ (* 3600 h) (* 60 m) s) 8.64E4) ) ;defun (defun Diff (cd1 cd2 / y1 y2 m1 m2 d1 d2 n) (cond ((= cd1 cd2) (setq n 0)) ((setq y1 (/ cd1 10000) m1 (rem (/ cd1 100) 100) d1 (rem cd1 100) y2 (/ cd2 10000) m2 (rem (/ cd2 100) 100) d2 (rem cd2 100) n (Round (+ (* 366 (- y1 y2)) (* 30.5 (- m1 m2)) (- d1 d2))) ) (and (= n 0) (setq n nil)) ) ) ;cond n ) ;defun (setq cd (fix cdate) dt -47130101 i0 0 n 0 ) (while (and (setq i (Diff cd dt)) (/= i 0) (/= 0 (+ i i0))) (setq n (+ n i) s (strcat "M=$(edtime," (itoa n) ",YYYYMODD)") dt (atoi (menucmd s)) i0 i ) ) ;while (if (or (not i) (= 0 (+ i i0))) (setq n nil) ) ;if (and n (setq n (+ n (Time cdate)))) n ) ;defun Quote
hanhphuc Posted December 25, 2014 Posted December 25, 2014 (edited) Another , (nth (1- 12) '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEP" "OCT" "NOV" "DEC")) Thanks Tharwat. simple & clean This similar but it index nth in a string (menucmd (strcat "M=$(index, " (itoa (1- i)) ; i= integer " ,\"JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEPT,OCT,NOV,DEC\")" ) ) Edited December 25, 2014 by hanhphuc Quote
Tharwat Posted December 25, 2014 Posted December 25, 2014 Thanks Tharwat. simple & clean You are welcome anytime Quote
pBe Posted December 26, 2014 Posted December 26, 2014 Another , (nth [b](1- 12)[/b] '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEP" "OCT" "NOV" "DEC")) That would be (1- n) Be mindful of the index number, or (0-11) nth 0 is the first element, it might confused the OP. Quote
hanhphuc Posted December 26, 2014 Posted December 26, 2014 That would be (1- n) Be mindful of the index number, or (0-11) nth 0 is the first element, it might confused the OP. pBe actually Tharwat applied decrease , (1- n) ie: (1- 12) =11 th but it also looks like (1 - 12), OP maybe confused if not coloured tag Quote
pBe Posted December 26, 2014 Posted December 26, 2014 pBe actually Tharwat applied decrease , (1- n) ie: (1- 12) =11 th but it also looks like (1 - 12), OP maybe confused if not coloured tag Oh i see, its must be my eyes.. Thank you for clarifying hanhphuc. kudos to Tharwat Personally i prefer an association list to avoid confusion such as the one above. Quote
Tharwat Posted December 26, 2014 Posted December 26, 2014 Thank you hanhphuc for the clarifications , appreciated alot Thank you for clarifying hanhphuc. kudos to Tharwat Thank you pBe Quote
hmsilva Posted December 28, 2014 Posted December 28, 2014 So I know how to get the date from autocad using CDATE. And I know how to parse that info to get 12/23/14. But how can I, for example, get the 12 to be "DEC". Do I need to make a multiple if statement for that part of the string? Hi guitarguy1685, a different approach, not using 'CDATE' but also getting the date format as your exemple '23DEC13' (menucmd "m=$(edtime,0,ddmonyy)") ;; returns "28Dec14" ;; if uppercase is required (strcase(menucmd "m=$(edtime,0,ddmonyy)")) ;; returns "28DEC14" I hope this helps Henrique Quote
Lee Mac Posted December 29, 2014 Posted December 29, 2014 (strcase(menucmd "m=$(edtime,0,ddmonyy)")) ;; returns "28DEC14" This is the method I would have suggested Nice one Henrique Quote
hmsilva Posted December 29, 2014 Posted December 29, 2014 This is the method I would have suggested Nice one Henrique Thank you, Lee Cheers Henrique 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.