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
(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 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.
That's covered in the first test by the (> ang1 270) part. (Sorry to jump in, Jim, but I was in the system....)
;; 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") "" "") )