Allow or prevent a 'nil' response to getdist.

Discussion in 'AutoCAD' started by Casey, Jul 9, 2004.

  1. Casey

    Casey Guest

    I'm trying to modify a routine to allow the user to enter an 'x' distance
    and then prompt for a 'y' distance. If the user presses enter for the 'y'
    distance, the 'x' value is used. It isn't working for me.. Any suggestions
    or guidance?

    Here's what I have so far. (it may be a little convoluted but c'est la vie)

    (defun C:RCC ()
    (setq ptc (GETPOINT "\nPick Center Of Rectangle : ")
    wide (getdist "\nEnter Rectangle X Dimension ? :")
    (if (= wide nil)(exit))
    high (getdist (strcat "\nEnter Rectangle Y Dimension ?<" (rtos wide 2 0)
    "> :")) ; this is where I get the error 'numberp nil'
    (if (= high nil)(setq high wide))
    hwide (/ wide 2.0)
    hhigh (/ high 2.0)
    ptll (list (- (car ptc) hwide) (- (cadr ptc) hhigh))
    ptur (list (+ (car ptll) wide) (+ (cadr ptll) high))
    )
    (setvar "plinewid" 0.0)
    (setq osm (getvar "OSMODE"))
    (setvar "OSMODE" 0)
    (command ".PLINE" ptll "W" "0" "0" ".X" ptur ".Y" ptll ptur ".X" ptll ".Y"
    ptur "C")
    (setvar "OSMODE" osm)
    )
     
    Casey, Jul 9, 2004
    #1
  2. I'm guessing it's the (if... function interrupting the (setq... series. You
    might need to do this:

    (setq ptc (GETPOINT "\nPick Center Of Rectangle : ")
    wide (getdist "\nEnter Rectangle X Dimension ? :")) ; <-- another
    right parenthesis to end the first setq function before the if line
    (if (= wide nil)(exit))
    (setq high (getdist (strcat "\nEnter Rectangle Y Dimension ?<" (rtos wide 2
    0) "> :"))) ; <-- start a new setq

    Or it might be that you're short a right parenthesis just before your "this
    is where..." remark. If it's allowable to put that (if) function in the
    middle of a series of setq's, then you're still inside setq after the (if)
    line, and as I count, you haven't finished it with enough right parentheses;
    you've only got enough to finish defining "high", but you need one more to
    close out the (setq).

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Jul 9, 2004
    #2
  3. Casey

    Jürg Menzi Guest

    Hi Casey

    This should work...
    See comments in the code:

    (defun C:RCC ( / ptc wide high ptll ptur plw osm cmd) ;localize vars's
    (cond
    ;avoid an error if the user press 'enter':
    ((not (setq ptc (getpoint "\nPick Center Of Rectangle: "))))
    ;avoid an error if the user press 'enter' or zero:
    ((or
    (initget 2)
    (not (setq wide (getdist "\nEnter Rectangle X Dimension: ")))
    )
    )
    ;else all user input ok:
    (T
    (initget 2) ;avoid zero input
    (setq high (getdist
    (strcat "\nEnter Rectangle Y Dimension <" (rtos wide 2) ">: ")
    )
    high (cond (high) (wide)) ;returns 'wide' if user press 'enter'
    ;don't waste var names:
    ptll (list (- (car ptc) (/ wide 2.0)) (- (cadr ptc) (/ high 2.0)))
    ptur (list (+ (car ptll) wide) (+ (cadr ptll) high))
    plw (getvar "PLINEWID")
    osm (getvar "OSMODE")
    cmd (getvar "CMDECHO")
    )
    (setvar "CMDECHO" 0) ;supress command prompts
    (setvar "OSMODE" 0)
    (setvar "PLINEWID" 0)
    ;width option is not necessary because you've set 'PLINEWID' to 0 and
    ;use international support '_' because of my german AutoCAD:
    (command "_.PLINE" ptll ".X" ptur ".Y" ptll ptur ".X" ptll ".Y" ptur "_CLO")
    ;reset all sysvars:
    (setvar "PLINEWID" plw)
    (setvar "OSMODE" osm)
    (setvar "CMDECHO" cmd)
    )
    )
    (princ) ;supress return value
    )

    Cheers
     
    Jürg Menzi, Jul 10, 2004
    #3
  4. Casey

    CAB2k Guest

    Yet another way to do it.

    Code:
    (defun c:rcc ()
    ;;  get point AND distance
    (if (and (setq ptc (getpoint "\nPick Center Of Rectangle : "))
    (setq wide (getdist "\nEnter Rectangle X Dimension ? :"))
    )
    (progn
    (if (null ; test input of high
    (setq high
    (getdist (strcat "\nEnter Rectangle Y Dimension ?<"
    (rtos wide 2 0) "> :"
    ))))
    (setq high wide) ; go no high so use wide
    ); endif
    (setq  hwide (/ wide 2.0)
    hhigh (/ high 2.0)
    ptll (list (- (car ptc) hwide) (- (cadr ptc) hhigh))
    ptur (list (+ (car ptll) wide) (+ (cadr ptll) high))
    )
    ;;  use NON to temporarly turn off the osmode
    ;;  rectangle has it's own width control
    (command "._rectangle" "W" "0" "non" ptll "non" ptur)
    ); progn
    (prompt "\n*-* User Quit *-*")
    ); endif
    ); defun
    
     
    CAB2k, Jul 11, 2004
    #4
  5. Casey

    Casey Guest

    Thanks all for your input... works great.
     
    Casey, Jul 13, 2004
    #5
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.