sheck angle

Discussion in 'AutoCAD' started by spencer1971, Oct 5, 2004.

  1. spencer1971

    spencer1971 Guest

    I am trying to check a set angle within a lisp file to see if it is greater than 90 and less than 270 and if it is the add 180 to it (for inserting text) I have done this so far but it is definately not right and I am sure it can be done in less commands

    (cond (< ang1 90) (setq test 1))
    (cond (> ang1 270) (setq test1 1))
    (if (= test nil) (setq test 2))
    (if (= test1 nil) (setq test1 2))
    (if (= test test1) (setq ang1 (+ 180 ang1)))
    (command "text" pt1 tscale ang1 pipefin)

    Any help would be appreciated

    Spence
     
    spencer1971, Oct 5, 2004
    #1
  2. Try this -
    (cond
    ((< ang1 90) (setq ang2 180)) ; check if less than 90, then set ang2 to
    180
    ((> ang1 270) (setq ang2 180)) ; check if greater than 270, then set ang2
    to 180
    (T (setq ang2 0)) ; neither so set to 0
    )
    (command "text" Pt1 tscale (+ ang1 ang2) pipefin)

    another alternative -
    (if (< 90 ang1 270)
    (command "text" Pt1 tscale ang1 pipefin)
    (command "text" Pt1 tscale (+ ang1 180) pipefin)
    )

    greater than 90 and less than 270 and if it is the add 180 to it (for
    inserting text) I have done this so far but it is definately not right and I
    am sure it can be done in less commands
     
    Alan Henderson @ A'cad Solutions, Oct 5, 2004
    #2
  3. spencer1971

    Paul Turvill Guest

    (if (< 90 ang1 270) (setq ang1 (+ ang1 180)))

    And this assumes, of course that ang1 is correctly expressed in degrees, not
    radians.

    ___

    greater than 90 and less than 270 and if it is the add 180 to it (for
    inserting text) I have done this so far but it is definately not right and I
    am sure it can be done in less commands
     
    Paul Turvill, Oct 5, 2004
    #3
  4. spencer1971

    spencer1971 Guest

    Thank you all for your help. Ive sussed it now, It was a problem with my radian - degree converting,

    Final routine as below..

    Spencer

    (defun rtd (a) (* 180.0 (/ a pi)))

    (defun MyExit (strErr)
    (setvar "orthomode" oldorth)
    (setvar "clayer" clay)
    (setvar "osmode" oldos)
    (setvar "luprec" oldunits)
    (princ)
    )

    (defun c:f-drain (/ lpt1 lpt2 lpt3 lpt4 dsc1 ang tscale ang1)
    (setq *ERROR* MyExit)
    (setq clay (getvar "clayer"))
    (setq oldos (getvar "osmode"))
    (setq oldunits (getvar "luprec"))
    (setq oldorth (getvar "orthomode"))
    (setvar "luprec" 0)
    (setq dsc1 (getvar "dimscale"))
    (setq lpt1 (getpoint "\nselect start of drain"))
    (setq lpt2 (getpoint lpt1 "\nselect end of drain"))
    (setq
    lpt3 (polar lpt1 (angle lpt1 lpt2) (/ (distance lpt1 lpt2) 2.0))
    )
    (setq ang (angle lpt1 lpt2))
    (command "-layer" "m" "DRAINAGE_FOUL" "")
    (command "-layer" "c" "magenta" "" "")
    (command "-LAYER" "LT" "PHANTOM2" "" "")
    (command "line" lpt1 lpt2 "")
    (command "insert" "drainarrow" lpt3 dsc1 dsc1 (+ (rtd ang) -90) )
    (setq ang1 (rtd ang))
    (if (< 90 ang1 270)
    (setq ang1 (+ ang1 180))
    )
    (setq tscale (* 2.5 dsc1))

    (if (< BRSC 1)
    (setq brsc 150)
    )
    (setq brsc (cond
    ((getint (strcat "\npipe size <" (rtos brsc) ">: ")))
    (brsc)
    )
    )
    (setq pipefin (strcat (rtos brsc) "%%c"))
    (command "-layer" "m" "025txt" "")
    (command "-layer" "c" "yellow" "" "")
    (command "text" lpt3 tscale ang1 pipefin)
    (setvar "osmode" 0)
    (command "move" "l" "" lpt3 pause)
    (setvar "orthomode" oldorth)
    (setvar "clayer" clay)
    (setvar "osmode" oldos)
    (setvar "luprec" oldunits)
    (princ)
    )
     
    spencer1971, Oct 6, 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.