Lisp routine help

Discussion in 'AutoCAD' started by charlieb, Nov 17, 2004.

  1. charlieb

    charlieb Guest

    I am trying to write a program that will insert a block at the end of a leader depending on which direction the leader is going. Here is the script Please HELP

    (Defun C:blb ()
    (SETQ OLDCMDECHO (GETVAR "CMDECHO"))
    (SETQ OLDLAYER (GETVAR "CLAYER"))
    (SETQ OLDATTREQ (GETVAR "ATTREQ"))
    (SETQ OLDATTMODE (GETVAR "ATTMODE"))
    (SETQ OLDOSMODE (GETVAR "OSMODE"))
    (SETQ OLDORTHO (GETVAR "ORTHOMODE"))
    (SETQ OLDATTDIA (GETVAR "ATTDIA"))


    (SETVAR "CMDECHO" 0)
    (SETVAR "ATTREQ" 1)
    (SETVAR "ATTMODE" 1)
    (SETVAR "ATTDIA" 1)

    (SETVAR "OSMODE" 512)

    (SETQ pt1 (GETPOINT "\n Pick location of symbol."))

    (COMMAND "INSERT" "A-DISCONE_P" pt1 (GETVAR "DIMSCALE") "" "" "")

    (COMMAND "QLEADER" pt1 (SETQ pt2 (GETPOINT "\n Pick location of Call-out.")) "" "" n)

    (SETQ ang1 (ANGLE pt1 pt2))

    (COND
    ((>= ang1 90)(COMMAND "INSERT"
    "TxA-Discone_NoDome-R" pt2 (GETVAR "DIMSCALE")
    ""
    ""
    ""))

    (< ang1 90)(> ang1 270)(COMMAND "INSERT"
    "TxA-Discone_NoDome-L" pt2
    (GETVAR "DIMSCALE")
    ""
    ""
    ""))
    ((< ang1 270)(COMMAND "INSERT"
    "TxA-Discone_NoDome-R" pt2
    (GETVAR "DIMSCALE")
    ""
    ""
    ""
    )
    )
    )
    (SETVAR "CLAYER" OLDLAYER)
    (SETVAR "ATTREQ" OLDATTREQ)
    (SETVAR "ATTMODE" OLDATTMODE)
    (SETVAR "ORTHOMODE" OLDORTHO)
    (SETVAR "OSMODE" OLDOSMODE)
    (SETVAR "CMDECHO" OLDCMDECHO)
    (SETVAR "ATTDIA" OLDATTDIA)
    (PRINC)
    )

    Charlie Bauer
     
    charlieb, Nov 17, 2004
    #1
  2. charlieb

    Jim Claypool Guest

    (COND
    ((or (< ang1 90)(> ang1 270))
    (COMMAND "INSERT"
    "TxA-Discone_NoDome-L" pt2
    (GETVAR "DIMSCALE")
    ""
    ""
    ""
    ))
    ((>= ang1 90)
    (COMMAND "INSERT"
    "TxA-Discone_NoDome-R" pt2 (GETVAR "DIMSCALE")
    ""
    ""
    ""
    ))
    )
     
    Jim Claypool, Nov 17, 2004
    #2
  3. [Jim Claypool beat me to some of this as I was writing it, but also missed
    some of the following:]

    You've got an extra "" in all your Insert commands.

    (ANGLE) is going to return radians, so you don't want to be checking
    relative to 90 & 270, unless you convert the radians to degrees as you save
    the ang1 value.

    Your middle angle comparison needs an (or) wrapped around the two angle
    tests. I also suspect you should combine the first one and the third one.
    If it's EITHER less than (/ pi 2) OR more than (* pi 1.5) [your second one],
    I'm guessing you want the block oriented one way, and if it's BOTH more than
    (/ pi 2) AND less than (* pi 1.5) [your first and third], you want it the
    other way. There are lots of orientations that would satisfy both the first
    and third of your conditions as now written.

    Actually, you could just do an (if) operation instead of a (cond). If it
    meets the first test, you do one thing, and you don't really need to make
    the second test, because if it doesn't meet the first one, in this kind of
    situation it has to meet the second.

    I hope that gets you started -- there may be other things to work on.
     
    Kent Cooper, AIA, Nov 17, 2004
    #3
  4. charlieb

    charlieb Guest

    How would I get this to work from 270 to 360?

    Thanks for your help.
     
    charlieb, Nov 17, 2004
    #4
  5. That's covered in the first test by the (> ang1 270) part. (Sorry to jump
    in, Jim, but I was in the system....)
     
    Kent Cooper, AIA, Nov 17, 2004
    #5
  6. charlieb

    charlieb Guest

    sorry for the ignorance, but you gentleman may have saved my job
     
    charlieb, Nov 17, 2004
    #6
  7. charlieb

    CAB2k Guest

    ;; one way is to catch the first TRUE test
    ;;
    (setq ang1 (* 180.0 (/ ang1 pi))); Convert Radians to Degrees
    (cond
    ((> ang1 270)
    (setq blkname "TxA-Discone_NoDome-R")
    )
    ((> ang1 90) ; anything >90 & <=270
    (setq blkname "TxA-Discone_NoDome-L")
    )
    (t ; anything <=90
    (setq blkname "TxA-Discone_NoDome-R")
    )
    )
    (COMMAND "INSERT" blkname pt2 (GETVAR "DIMSCALE") "" "")



    ;; or test the 90 to 270 range
    (if (and (> ang1 90) (< ang1 270))
    (COMMAND "INSERT" "TxA-Discone_NoDome-L" pt2 (GETVAR "DIMSCALE") "" "")
    (COMMAND "INSERT" "TxA-Discone_NoDome-R" pt2 (GETVAR "DIMSCALE") "" "")
    )
     
    CAB2k, Nov 18, 2004
    #7
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.