IF and Then functions in Autolisp

Discussion in 'AutoCAD' started by VikCAD04, Sep 11, 2004.

  1. VikCAD04

    VikCAD04 Guest

    I'm kind of new to the whole lisp language, and not even sure if this will be possible, but i think it should be.
    Here's what I'm doing:
    I have 2 parts to the lisp, and a need a function in there that would go and check one of the variables, if it finds a certain value it will go to part 1 of the lisp, if it finds a different value it will go to the other part. I tried messing with IF function but either i'm not doing it right or it's not the solution i'm looking for
    Thanks for any help.

    Viktor.
     
    VikCAD04, Sep 11, 2004
    #1
  2. VikCAD04

    Doug Broad Guest

    Viktor,
    You're on the right track

    (if (= val value) (do-part-one)(do-part-two))

    where (defun do-part-one....) and (defun do-part-two ....) are
    two functions

    or
    (if (= val value)
    (progn
    .........steps you want in the first case
    )
    (progn
    .........steps to do if val <> value
    )
    )


    value it will go to part 1 of the lisp, if it finds a different value it will go to the other part. I tried messing with IF function
    but either i'm not doing it right or it's not the solution i'm looking for
     
    Doug Broad, Sep 11, 2004
    #2
  3. VikCAD04

    CAB2k Guest

    Or use the cond function

    [cond](cond
    ((= val value)
    (do-part-one)
    )
    (T ; always executed if part one is false
    (do-part-two))
    )

    )[/cond]

    This one will give you more choices of action,
    The cond will execute the first True condition and skip the rest
    of the test.

    [cond](cond
    ((= val value)
    (do-part-one)
    )
    ((= val value2)
    (do-part-two))
    )
    (T ; skip if part 1 or 2 is true
    (do-this-if-failed) ; part 1 & 2 failed
    )
    )[/cond]
     
    CAB2k, Sep 12, 2004
    #3
  4. VikCAD04

    VikCAD04 Guest

    Thanks for both replies, i tried them and both worked, although i find the COND function suit me better.
    Thanks again,
    Viktor
     
    VikCAD04, Sep 13, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.