GRREAD problem

Discussion in 'AutoCAD' started by Rabbit, Nov 15, 2004.

  1. Rabbit

    Rabbit Guest

    In the following code <ugly as it is>, if I make the direction for the
    transition to the right <zero degrees WCS>, it works fine, all 3 of my
    transition types show up ghosted. But, if I make the transition to the left
    <180 degrees WCS>, then only two of the transition types show up. I know
    it's a problem with doing the math, but I can't seem to figure it out. Any
    help?

    ;;;------------------------------------------------------------------------------------------------
    (defun *HVAC*SetupSave ()
    (if (not (tblsearch "ltype" "hidden2"))
    (progn
    (setq lin "C:/Cad Standards/Linetypes/acad.lin")
    (command "-linetype" "l" "hidden2" lin "")
    );progn
    );if
    (setvar "cmdecho" 0)
    (setq Clay (getvar "clayer"))
    (setq CeCol (getvar "cecolor"))
    (setq CeLType (getvar "celtype"))
    (setq DimScl (getvar "dimtxt"))
    (setq OrthoMode (getvar "orthomode"))
    (setq OsMode (getvar "osmode"))
    (setq TextStyle (getvar "textstyle"))
    (setq TextSize (getvar "textsize"))
    (while (not DuctTextHeight) (setq DuctTextHeight (getreal "Text Height:
    ")))
    (if (not (tblsearch "STYLE" "DUCTTEXT")) (command "-style" "DUCTTEXT"
    "ROMANS" DuctTextHeight "0.8" "0" "N" "N" "N") (setvar "textstyle"
    "DUCTTEXT"))
    (setvar "orthomode" 1)
    (setvar "OsMode" 0)
    (if (not (setq LinerWidth (xgetdist nil "\nEnter Liner Width: "
    'LinerWidth))) (setq LinerWidth 0.0))
    )

    (defun *HVAC*SetupRestore ()
    (setvar "cmdecho" 1)
    (setvar "clayer" Clay)
    (setvar "cecolor" CeCol)
    (setvar "celtype" CeLType)
    (setvar "dimtxt" DimScl)
    (setvar "orthomode" OrthoMode)
    (setvar "osmode" OsMode)
    (setvar "textsize" TextSize)
    (redraw)
    )
    ;;;------------------------------------------------------------------------------------------------
    (defun *ERROR* (Msg)
    (if
    (not
    (member Msg
    '("console break" "Function cancelled" "quit / exit abort")
    )
    )
    (princ (strcat "\nError: " Msg))
    )
    (*HVAC*SetupRestore)
    (princ)
    )

    ;;;------------------------------------------------------------------------------------------------
    ;;;Written by Jamie Myers
    ;;;Layername = String of layer's name
    ;;;LayColor = String of layer's color
    ;;;Layer changing utility
    (defun LayerSet (Layname LayColor /)
    (if (= (tblsearch "layer" Layname) NIL)
    (command "-layer" "n" Layname "c" LayColor Layname "s" Layname "")
    (setvar "clayer" Layname)))

    ;;;------------------------------------------------------------------------------------------------
    ;;;Tony Tanzillo's solution
    (defun xgetdist (basept msg dflt / d promptstr res)
    (if (eq (type dflt) 'sym) (setq d (eval dflt)) (setq d dflt))
    (setq promptstr (strcat msg (if d (strcat " <" (rtos d) ">: ") ": ")))
    (setq res (cond
    ((if basept (getdist basept promptstr) (getdist promptstr)
    ))
    (t d)
    ))
    (if (eq (type dflt) 'sym) (set dflt res)) res)

    ;;;------------------------------------------------------------------------------------------------
    (defun MidPnt (p1 p2)
    (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2)
    )

    ;;;------------------------------------------------------------------------------------------------
    ;;;Duct transitions
    (defun c:Tran ()
    (*HVAC*SetupSave)
    (setq TransStartPnt (cadr (grread T)))
    (while (not (setq TransWidth (xgetdist nil "\nTransition starting width"
    'TransWidth))))
    (setvar "orthomode" 1)
    (setq TransEndPnt (getpoint TransStartPnt "\nDirection of Transition: "))
    (setq TrueTransAngle (angle TransStartPnt TransEndPnt))
    (command ".line" (polar TransStartPnt (+ TrueTransAngle (* pi 0.5)) (* 0.5
    TransWidth)) (polar TransStartPnt (- TrueTransAngle (* pi 0.5)) (* 0.5
    TransWidth)) "")
    (setq TransPnt1 (polar TransStartPnt (+ TrueTransAngle (* pi 0.5)) (* 0.5
    TransWidth)))
    (setq TransPnt2 (polar TransStartPnt (- TrueTransAngle (* pi 0.5)) (* 0.5
    TransWidth)))


    (setq TransStartMid (MidPnt TransPnt1 TransPnt2))
    (if (= TransWidth nil) (setq TransWidth (distance TransPnt1 TransPnt2)))
    (setvar "orthomode" 0)
    (setq OtherDist (- TransWidth 2.0))
    (while (not (setq OtherDist (xgetdist nil "\nEnter new duct width: "
    'OtherDist))))
    (setq TransStart TransStartMid)
    (prompt "\nPick side for transiton type: ")
    (while (/= (car (setq Transgrread (grread 'T 1 0))) 3)
    (redraw)
    (grdraw TransStartMid (cadr Transgrread) -1 1)
    (setq GrreadAngle (angle TransStartMid (cadr Transgrread)))
    (cond
    ((or;for straight transition
    (<= GrreadAngle (+ TrueTransAngle (* pi 0.125)));45
    (>= GrreadAngle (+ TrueTransAngle (* pi 1.875)));315
    (= GrreadAngle TrueTransAngle))
    (progn
    (setq OtherCen (polar TransStartMid TrueTransAngle 12))
    (setq TransPnt3 (polar OtherCen (+ TrueTransAngle (* pi 0.5)) (*
    OtherDist 0.5)))
    (setq TransPnt4 (polar OtherCen (- TrueTransAngle (* pi 0.5)) (*
    OtherDist 0.5)))
    );end progn
    );end test
    ((or; for offset transition to the RIGHT of duct
    (> GrreadAngle (+ TrueTransAngle (* pi 1.875)));315
    (< GrreadAngle (+ TrueTransAngle (* pi 1.5))));270
    (progn
    (setq TransPnt3 (polar TransPnt1 TrueTransAngle 12))
    (setq TransPnt4 (polar TransPnt3 (- TrueTransAngle (* pi 0.5))
    OtherDist))
    );end progn
    );end test
    ((or;for offset transition to the LEFT of duct
    (< GrreadAngle (+ TrueTransAngle (* pi 0.125)));45
    (> GrreadAngle (+ TrueTransAngle (* pi 0.5))));90
    (progn
    (setq TransPnt4 (polar TransPnt2 TrueTransAngle 12))
    (setq TransPnt3 (polar TransPnt4 (+ TrueTransAngle (* pi 0.5))
    OtherDist))
    );end progn
    );end test
    (T nil)
    );cond
    (grdraw TransPnt1 TransPnt3 -1 1)
    (grdraw TransPnt3 TransPnt4 -1 1)
    (grdraw TransPnt4 TransPnt2 -1 1)
    (repeat 7500 t)
    (setq Transgrread nil)
    );end while
    (redraw)
    (command ".line" TransPnt1 TransPnt3 "")
    (command ".line" TransPnt3 TransPnt4 "")
    (setq TransEndLine (entlast))
    (command ".line" TransPnt4 TransPnt2 "")
    (if (> LinerWidth 0.0)
    (progn
    (if (= (tblsearch "layer" "M-DUCT-LINER") NIL)
    (command "-layer" "n" "M-DUCT-LINER" "c" "Red" "M-DUCT-LINER" "l"
    "hidden2" "M-DUCT-LINER" "s" "M-DUCT-LINER" "")
    (setvar "clayer" "M-DUCT-LINER")
    );if
    (command ".line" (polar TransPnt1 (+ TrueTransAngle (* pi 1.5))
    LinerWidth) (polar TransPnt3 (+ TrueTransAngle (* pi 1.5)) LinerWidth) "")
    (setq LinerLine3 (entlast))
    (command ".line" (polar TransPnt4 (+ TrueTransAngle (* pi 0.5))
    LinerWidth) (polar TransPnt2 (+ TrueTransAngle (* pi 0.5)) LinerWidth) "")
    (setq LinerLine4 (entlast))
    (LayerSet "M-HVAC-DUCT" "5")
    );progn
    );if
    ;;;set Duct start point
    (setq DuctStartPnt (MidPnt TransPnt3 TransPnt4))
    (*HVAC*SetupRestore)
    );defun
     
    Rabbit, Nov 15, 2004
    #1
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.