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

    Default IF - condition (I need an additional LISP lesson)

    Registered forum members do not see this ad.

    Hi,

    could anyone please help me out with this?

    Code:
    (if (= "UserName" (strcase (getvar 'loginname)))
    ...
    I would like to add here some other UserNames

    Code:
    (if (= (or "UserName1" "UserName2" "...") (strcase (getvar 'loginname)))
    but this didn't work.

    How could I handle this?

    kind regards
    Bluebird1973

  2. #2
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    534

    Default

    Code:
    (cond ((wcmatch (strcase (getvar 'loginname)) "USERNAME,USERNAME1,USERNAME2,USERNAME3"))
          (code)
    )
    Be aware that = and wcmatch are case sensitive, so your example above will never work using strcase on the login name.

  3. #3
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,531

    Default

    You could also use ( member ) but it is case sensitive as well
    Code:
    (if (member (strcase (getvar 'loginname)) 
               '("USERNAME" "USERNAME1" "USERNAME2" "USERNAME3"))
        (YadaYada))
    -David
    R12 (Dos) - A2K

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,071

    Default

    Or ...

    Code:
    (if (vl-position (strcase (getvar 'loginname)) '("USERNAME" "USERNAME1" "USERNAME2"))
       (...)
    )

  5. #5
    Full Member
    Using
    Architecture 2016
    Join Date
    Nov 2014
    Posts
    25

    Default

    Thank you guys !!!

    GAP CLOSED!

    ... and of course ronjonp and David ... case sensitive ... USERNAME not UserName ...

    kind regards
    Bluebird1973

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,350

    Default

    If you really wanted to use OR, per your original example:
    Code:
    (setq usr (strcase (getvar 'loginname)))
    (if (or (= "USER1" usr)
            (= "USER2" usr)
            (= "USER3" usr)
        )
        ...
    )
    But I would also likely use member/wcmatch in this scenario.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  7. #7
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,819

    Default

    Had a bit of fun with the guys here so I used a cond as each user got a different response, the wcmatch would just give an answer of match found.
    A man who never made mistakes never made anything

  8. #8
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    534

    Default

    Quote Originally Posted by BIGAL View Post
    Had a bit of fun with the guys here so I used a cond as each user got a different response, the wcmatch would just give an answer of match found.
    You could also accomplish that with ASSOC like so:
    Code:
    (print
      (cdr (assoc "USERNAME2"
    	      '(("USERNAME1" . "Message1") ("USERNAME2" . "Message2") ("USERNAME3" . "Message3"))
           )
      )
    )

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

    Default

    Or with a recursive or, which works the same as vl-some:
    Code:
    (defun _or ( f L ) (if L (if (not (f (car L))) (_or f (cdr L)) t)))
    Code:
    (_or '((x) (= "User2" x)) '("User1" "User2" "User3"))

    BTW this is one is shorter, but I tried avoiding or:
    Code:
    (defun _or ( f L ) (if L (or (f (car L)) (_or f (cdr L)))))

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,350

    Default

    Registered forum members do not see this ad.

    How about:
    Code:
    (defun _or ( f l )
        (cond ((not l) nil) ((f (car l))) ((_or f (cdr l))))
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

Similar Threads

  1. I need an additional LISP lesson
    By Bluebird1973 in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 20th Oct 2017, 02:16 pm
  2. Rename Layout LISP. Need to add additional. Please Help.
    By tmelancon in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 8th Dec 2015, 02:58 am
  3. How to get this LISP to add an additional 90 degrees to its rotate
    By msirois in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 7th Dec 2015, 08:03 am
  4. lisp for multi trim and extend with condition
    By trunglupin in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 28th Aug 2014, 04:04 am
  5. if condition in lisp
    By vivekgrs in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 29th Jul 2006, 05:40 am

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