Return default value?

Discussion in 'AutoCAD' started by Big 'D', Aug 18, 2004.

  1. Big 'D'

    Big 'D' Guest

    My code draws a section line with arrows. I have the default arrow size (.03) and pline width (0) set. I want the routine to auto return this default setting but cannot seem to get it to. I tries " " but it did not work (obviously not in the right location). I also want to reset to the previous layer after drawing the section line. How can I do that?
    Thanks for your expertise
    D

    (setvar "cmdecho" 0)
    (command "-layer" "s" "h1" "")

    (if (not asize) (setq asize 0.30)) ;initial default arrow size
    (if (not PThk) (setq PThk 0.000)) ; " " Pline width

    (defun GETR (val msg / tm)
    (setq tm (getreal (strcat msg " <" (rtos val 2 4) ">: ")))
    (cond ((= (type tm) 'REAL) (eval tm))
    ((= tm nil) (eval val))
    (t (princ "\007 *error* not a REAL") (eval val)) ) )

    (defun loop ()
    (cond ((setq p2 (getpoint p1 " To point: ")) (command p2)
    (setq p0 p1) (setq p1 p2) (loop))
    ( t (command "u" (polar p1 (angle p1 p0) asize)
    "w" (/ asize 3) 0.0 p1 ""))))

    (setq asize (getr asize " Arrow head size"))
    (setq PThk (getr PThk " Pline width"))
    (setq p1 (getpoint " From point: "))
    (command "pline" p1 "w" 0.0 0.0)
    (setq p2 (getpoint p1 " To point: "))
    (command "w" 0.0 (/ asize 3) (polar p1 (angle p1 p2) asize)
    "w" PThk PThk p2)
    (setq p1 p2)
    (loop)
    (command "change" "l" "" "p" "lt" "phantom" "")
    (eval "Done")
    )
     
    Big 'D', Aug 18, 2004
    #1
  2. Big 'D'

    T.Willey Guest

    At the beginning of your code do:
    (setq olay (getvar "clayer"))
    (setq opwid (getvar "plinewid"))
    These will get you the current layer and pline width default. At the end of your code, to reset them, put
    (setvar "clayer" olay)
    (setvar "plinewid" opwid)

    You may also want to set those two new variables as local within your routine. It escapes me what Acad system variable hold the default arrow size right now, maybe someone else will chime in.

    Hope this helps.
    Tim
     
    T.Willey, Aug 18, 2004
    #2
  3. Big 'D'

    Jim Claypool Guest

    I see the defaults when the routine runs.
    To reset the current layer add (setq clayer (getvar "clayer")) at the
    beginning of the routine and (setvar "clayer" clayer) at the end.

    (.03) and pline width (0) set. I want the routine to auto return this
    default setting but cannot seem to get it to. I tries " " but it did not
    work (obviously not in the right location). I also want to reset to the
    previous layer after drawing the section line. How can I do that?
     
    Jim Claypool, Aug 18, 2004
    #3
  4. Big 'D'

    Tom Smith Guest

    Not sure what you mean by auto return. The getr function works as it seems meant to -- if you hit a return, it returns the default value it was called with. If you'll clarify the problem, maybe somebody can help.

    My only comment is that getr is doing more checking than necessary. The getreal function returns a real number, or nil for a null response (hitting return). So you don't need to check whether the value was a real number -- getreal won't accept any input but a number, and it will return a real. All you need to check for a null response. Also, you don't need to force an eval to return a value.

    (defun GETR (val msg / tm)
    (cond
    ((getreal (strcat msg " <" (rtos val 2 4) ">: ")))
    (val)))
     
    Tom Smith, Aug 18, 2004
    #4
  5. Big 'D'

    Big 'D' Guest

    The defaults show up when the routine runs but, I have to hit return. If I knew how, this could even be set as a constant. Since I don't know how to do that, I was simply trying to put in an automatic return for the value. I always want the object drawn on h1 (and then return to whatever the previous layer was set to) and I want the arrow always the same size and the pline width the same.
    Does that explain a little better what I am trying to accomplish?
    Thanks for the input thus far,
    D
     
    Big 'D', Aug 18, 2004
    #5
  6. Why are you using (getr) if you don't want to pause for user input? Simply
    set the variables to the data you want with the (setq) statement.

    If you want to allow user input in some cases, but not in other cases, you
    will need to restructure your code similar to this sample:

    (defun I:MyWorkhorse (arg1 arg2)
    ;| do your stuff using arg1 |;
    ;| do your stuff using arg2 |;
    (princ))

    (defun C:MyUI (/ inp1 inp2)
    (setq inp1 (get...))
    (setq inp2 (get...))
    (I:MyWorkhorse inp1 inp2))

    [Sample NoUI]^C^C^P(I:MyWorkhorse "Hello?" "Is anybody out there?")
    [Sample UI]^C^CMyUI

    --
    R. Robert Bell


    The defaults show up when the routine runs but, I have to hit return. If I
    knew how, this could even be set as a constant. Since I don't know how to do
    that, I was simply trying to put in an automatic return for the value. I
    always want the object drawn on h1 (and then return to whatever the
    previous layer was set to) and I want the arrow always the same size and the
    pline width the same.
    Does that explain a little better what I am trying to accomplish?
    Thanks for the input thus far,
    D
     
    R. Robert Bell, Aug 18, 2004
    #6
  7. Big 'D'

    Jim Claypool Guest

    (setvar "cmdecho" 0)
    (setq clayer (getvar "CLAYER"));;Add this line to save the current layer
    (command "-layer" "s" "h1" "")

    (if (not asize) (setq asize 0.30)) ;initial default arrow size
    (if (not PThk) (setq PThk 0.000)) ; " " Pline width

    ;;(defun GETR (val msg / tm) ;;Remove this function if you don't want to
    change the size
    ;; (setq tm (getreal (strcat msg " <" (rtos val 2 4) ">: ")))
    ;; (cond ((= (type tm) 'REAL) (eval tm))
    ;; ((= tm nil) (eval val))
    ;; (t (princ "\007 *error* not a REAL") (eval val)) ) )

    (defun loop ()
    (cond ((setq p2 (getpoint p1 " To point: ")) (command p2)
    (setq p0 p1) (setq p1 p2) (loop))
    ( t (command "u" (polar p1 (angle p1 p0) asize)
    "w" (/ asize 3) 0.0 p1 ""))))

    ;;(setq asize (getr asize " Arrow head size")) ;;Remove this line since
    asize is already set
    ;;(setq PThk (getr PThk " Pline width")) ;;Remove this line since pthk is
    already set
    (setq p1 (getpoint " From point: "))
    (command "pline" p1 "w" 0.0 0.0)
    (setq p2 (getpoint p1 " To point: "))
    (command "w" 0.0 (/ asize 3) (polar p1 (angle p1 p2) asize)
    "w" PThk PThk p2)
    (setq p1 p2)
    (loop)
    (command "change" "l" "" "p" "lt" "phantom" "")
    (setvar "clayer" clayer);;Add this line to reset the current layer
    (eval "Done")

    I knew how, this could even be set as a constant. Since I don't know how to
    do that, I was simply trying to put in an automatic return for the value. I
    always want the object drawn on h1 (and then return to whatever the
    previous layer was set to) and I want the arrow always the same size and the
    pline width the same.
     
    Jim Claypool, Aug 18, 2004
    #7
  8. Big 'D'

    Big 'D' Guest

    GREAT! Exactly what I was trying to get it to do. Thank you Jim!
    Thanks to all who offered valuable input.
     
    Big 'D', Aug 19, 2004
    #8
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.