+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 30
  1. #1
    Full Member
    Using
    Architecture 2016
    Join Date
    Nov 2014
    Posts
    32

    Default HappyBirthday.lsp ==>Fun vs. prank

    Registered forum members do not see this ad.

    Hi together,

    I would like to play a trick on my draftsman colleagues and I needed some help.
    ...feel free to improve my poor coding...


    Code:
    (defun c:HappyBirthday (/ UserName User1 B-Day_Date R-age age ry)
    
    	(if ;list of users for the pop-ups
    		(setq UserName (strcase(getvar 'loginname)))
    		(progn
    			(cond
    ;						User Name						User						Birthday						retirement age
    				((equal UserName "MH019") (setq User1 "Michael"		B-Day_Date "19991003"			R-age 67))
    				((equal UserName "MH019") (setq User1 "Michael"		B-Day_Date "20180109"			R-age 67))
    				((equal UserName "MH019") (setq User1 "Michael"		B-Day_Date "20180110"			R-age 67))
    				(T		(princ "\n\nSorry, User not listed !!!"))
    			);_cond end
    		);_progn end
    	);_if end
    
    	(setq age (itoa (- (atoi (substr (rtos (fix (getvar 'CDATE))) 1 4)) (atoi (substr B-Day_Date 1 4)) ) ));calculating the age of the user
    	(setq ry	(itoa (- R-age (atoi age))));remaining years until retirement
    	
    	(alert
    		(strcat 
    			"Hello " User1 "!"
    			"\n\nHerzlichen Glückwunsch zum " age ". Geburtstag !!!"
    			"\n\nCongratulations on your " age "st/nd/rd/ th birthday !!!" ;here I need some help for the e.g. 21st, 22nd, 23rd, 24th.
    			"\n\n\n\nVon jetzt an, sind es nur noch " ry " Jahre bis zur Rente \n... Also hau rein ... :-)"
    			"\n\nFrom now on, there are only " ry "  years left to retirement \n... so get in there ... :-)"
    			"\n\n\nKeyuser Michael"
    			)
    	)
    	(princ)
    )
    
    ;original code from 06.01.2011/Lee Mac changed on my needs
    ;http://www.cadtutor.net/forum/showthread.php?55800-Differences-in-exiting-AutoCAD&p=378358&viewfull=1#post378358
    (if
    	(not
    		(and
    			(setq date (getenv "OnceAYear"))
    			(< (fix (getvar 'CDATE)) (atoi date))
    		);_end and
    	);_end not
    	(progn
    		(c:HappyBirthday)
    		(setenv "OnceAYear" (itoa (+ 10000 (fix (getvar 'CDATE)))))	;stored in windows registry [HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R19.1\ACAD-D004:409\FixedProfile\General]
    	);_end progn
    );_end if
    (princ)
    Thank you in advanced !!!

    kind regards
    Bluebird1973

  2. #2
    Full Member
    Using
    AutoCAD 2015
    Join Date
    Jun 2017
    Posts
    27

    Default

    here's one way to get the suffix

    Code:
    (setq suffix (chr (last (vl-string->list age))))
    (cond ((eq suffix "1") (setq suffix "st"))
          ((eq suffix "2") (setq suffix "nd"))
          ((eq suffix "3") (setq suffix "rd"))
          ( T (setq suffix "th"))
    )

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,595

    Default

    Quote Originally Posted by FranknBeans View Post
    here's one way to get the suffix

    Code:
    (setq suffix (chr (last (vl-string->list age))))
    (cond ((eq suffix "1") (setq suffix "st"))
          ((eq suffix "2") (setq suffix "nd"))
          ((eq suffix "3") (setq suffix "rd"))
          ( T (setq suffix "th"))
    )
    "13rd"

    Here's another possible way:
    Code:
    (defun ordinal ( n )
        (cond ((< 10 (rem n 100) 14) "th") ((nth (rem n 10) '(nil "st" "nd" "rd"))) ("th"))
    )
    Code:
    _$ (ordinal 13)
    "th"
    _$ (ordinal 21)
    "st"
    _$ (ordinal 123)
    "rd"
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,595

    Default

    How about something like this?
    Code:
    (   (lambda ( lst / age itm ord ret )
            (defun ord ( n ) (cond ((< 10 (rem n 100) 14) "th") ((nth (rem n 10) '(nil "st" "nd" "rd"))) ("th")))
            (cond
                (   (null (setq itm (assoc (strcase (getvar 'loginname)) lst)))
                    (princ "\nSorry, user not listed!")
                )
                (   (zerop (rem (setq age (- (fix (getvar 'cdate)) (caddr itm))) 10000))
                    (setq age (/ age 10000)
                          ret (- (cadddr itm) age)
                    )
                    (alert
                        (strcat 
                            "Hello " (cadr itm) "!"
                            "\n\nHerzlichen Glückwunsch zum " (itoa age) ". Geburtstag !!!"
                            "\n\nCongratulations on your " (itoa age) (ord age) " Birthday !!!"
                            "\n\n\n\nVon jetzt an, sind es nur noch " (itoa ret) " Jahre bis zur Rente \n... Also hau rein ... :-)"
                            "\n\nFrom now on, there are only " (itoa ret) " years left to retirement \n... so get in there ... :-)"
                            "\n\n\nKeyuser Michael"
                        )
                    )
                )
            )
            (princ)
        )
       '(
            ("MH019" "Michael" 19991003 67)
            ("MH019" "Michael" 20180109 67)
            ("MH019" "Michael" 20180110 67)
        )
    )
    Copy the above into your acaddoc.lsp
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Full Member
    Using
    AutoCAD 2015
    Join Date
    Jun 2017
    Posts
    27

    Default

    Quote Originally Posted by Lee Mac View Post
    "13rd"
    oops

  6. #6
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,474

    Default

    This made me wonder, why not write some generic function that uses one of the arguments:
    '(day week month year)

    Code:
    (defun RunOnceA ( sym func ) ...)
    
    (RunOnceA 'week '(lambda ( / ) <bla-bla>) )

  7. #7
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,715

    Default

    Hellooooo

    make sure speaker is on

    Code:
    (defun SpeakSapi ( s / sapi )
        (if (eq (type s) 'STR)
          (progn
            (setq sapi (vlax-create-object "Sapi.SpVoice"))
            (vlax-put sapi 'SynchronousSpeakTimeout 1)
            (vlax-invoke-method sapi 'WaitUntilDone 0)
            (vlax-invoke sapi "Speak" s 0)
            (vlax-release-object sapi)
          )
        )
    )
    (speaksapi "please remain seated during your Autocad session do not leave work area")
    (setq x 24)
    (setq ans (strcat "alan is " (rtos x 2 0)))
    (speaksapi ans)
    A man who never made mistakes never made anything

  8. #8
    Full Member
    Using
    Architecture 2016
    Join Date
    Nov 2014
    Posts
    32

    Default

    Hi together,

    Thanks to everyone, I appreciate that very much !

    @ Lee Mac

    I didn't get your code to run. I put it on my acaddoc.lsp but nothing happens.
    What I'm doing wrong?
    ... and I have problems to understand what's going on. Could you please add some comments/explanations for me?

    Quote Originally Posted by Lee Mac View Post
    How about something like this?
    Code:
    (   (lambda ( lst / age itm ord ret )
            (defun ord ( n ) (cond ((< 10 (rem n 100) 14) "th") ((nth (rem n 10) '(nil "st" "nd" "rd"))) ("th")))
            (cond
                (   (null (setq itm (assoc (strcase (getvar 'loginname)) lst)))
                    (princ "\nSorry, user not listed!")
                )
                (   (zerop (rem (setq age (- (fix (getvar 'cdate)) (caddr itm))) 10000))
                    (setq age (/ age 10000)
                          ret (- (cadddr itm) age)
                    )
                    (alert
                        (strcat 
                            "Hello " (cadr itm) "!"
                            "\n\nHerzlichen Glückwunsch zum " (itoa age) ". Geburtstag !!!"
                            "\n\nCongratulations on your " (itoa age) (ord age) " Birthday !!!"
                            "\n\n\n\nVon jetzt an, sind es nur noch " (itoa ret) " Jahre bis zur Rente \n... Also hau rein ... :-)"
                            "\n\nFrom now on, there are only " (itoa ret) " years left to retirement \n... so get in there ... :-)"
                            "\n\n\nKeyuser Michael"
                        )
                    )
                )
            )
            (princ)
        )
       '(
            ("MH019" "Michael" 19991003 67)
            ("MH019" "Michael" 20180109 67)
            ("MH019" "Michael" 20180110 67)
        )
    )
    Copy the above into your acaddoc.lsp

    @BIGAL

    This is a funny one.... but we have no speakers ...

    Quote Originally Posted by BIGAL View Post
    Hellooooo

    make sure speaker is on

    Code:
    (defun SpeakSapi ( s / sapi )
        (if (eq (type s) 'STR)
          (progn
            (setq sapi (vlax-create-object "Sapi.SpVoice"))
            (vlax-put sapi 'SynchronousSpeakTimeout 1)
            (vlax-invoke-method sapi 'WaitUntilDone 0)
            (vlax-invoke sapi "Speak" s 0)
            (vlax-release-object sapi)
          )
        )
    )
    (speaksapi "please remain seated during your Autocad session do not leave work area")
    (setq x 24)
    (setq ans (strcat "alan is " (rtos x 2 0)))
    (speaksapi ans)

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,595

    Default

    Quote Originally Posted by Bluebird1973 View Post
    @ Lee Mac

    I didn't get your code to run. I put it on my acaddoc.lsp but nothing happens.
    What I'm doing wrong?
    ... and I have problems to understand what's going on. Could you please add some comments/explanations for me?
    It will only run when there is a birthday to be celebrated!

    Try adding a new user to the list whose birthday is today
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Full Member
    Using
    Architecture 2016
    Join Date
    Nov 2014
    Posts
    32

    Default

    Registered forum members do not see this ad.

    Thank you Lee Mac !!!

    now I got it. ...but didn't understand the code


    is there a way to not pank my draftsman the whole day?
    ... 3 or 4 times would be enough ...

Similar Threads

  1. iPhone Photo Prank this Week
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 16th Jan 2015, 09:30 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts