How can I select a corner of rectangle?

Discussion in 'AutoCAD' started by Big 'D', May 21, 2004.

  1. Big 'D'

    Big 'D' Guest

    Hey, I had some GREAT help with this routine (Thank you so much, you know who you are). I want to take this one step further. The routine asks for insertion point of text at the end. The insertion point is always going to be the lower left corner. How can I add this to my lisp?
    Do I have to label each corner of the rectangle as it is being created?
    Thanks once again,
    D
    ...Oh....and....Have a nice weekend!

    Code:
    (defun *error* (errmes)
    (princ (strcat "\nExecution of ADD halted by the following error: " ERRMES))
    (setvar "cmdecho" OLDCE)
    (setq *error* OLDERR)
    (prin1)
    )
    ;-----;
    (defun c:pb ( / OLDCE OLDERR OLDTE)
    ; Save the current value of cmdecho then redefine it.
    (setq OLDCE (getvar "cmdecho"))
    (setvar "cmdecho" 1)
    ; Save the current value of texteval then set it to 1
    (setq OLDTE (getvar "texteval"))
    (setvar "texteval" 1)
    ; Save the current value of the error handling subroutine then redefine it.
    (setq OLDERR *error*)

    ;(setq *error* nil)
    ; NOTE: to turn error handling off, erase the semicolon in the line above.

    ; Input to AutoCAD's command line.

    (command "layer" "s" "obj" "")

    (initget 1)
    (setq pt1 (getpoint "First corner: ")
    pt2 (cond ((getcorner pt1 "Opposite corner <@0.16,-1.0>: "))
    ((mapcar '+ pt1 '(0.16 -1.0))
    )
    )
    )

    (command "rectangle" pt1 pt2)

    (if (< (cadr pt1) (cadr pt2))
    (setq ybase (cadr pt1))
    (setq ybase (cadr pt2))
    )

    (setq xmidbase (/ (+ (car pt1)(car pt2)) 2)
    )

    (initget "Yes No")
    (setq breakanswer (getkword "\nDo you want a break [Yes/No] <Yes>: "))

    (if (/= breakanswer "No")

    (progn

    (command "break" (entlast) "non" (list (- xmidbase (/ 0.06 2)) ybase) "non" (list (+ xmidbase (/ 0.06 2)) ybase))

    (command "insert" "G:/Acad2000/cadstd/symlib/DC-10/bko" "non" (list xmidbase ybase) "1" "1" "0")

    );progn

    )

    (command "osnap" "none" "osnap" "end")
    (command
    "insert"
    "G:/Acad2000/cadstd/symlib/DC-10/equ" PAUSE
    "1"
    "1"
    "0"
    "explode"
    "last"
    "osnap"
    "none"
    )

    ; RUN LISP routine "C:SYMDATA" and store the result in RSLT.
    (setq RSLT (C:SYMDATA))

    ; Reset "cmdecho" to previous value.
    (setvar "cmdecho" OLDCE)
    ; Reset "texteval" to previous value.
    (setvar "texteval" OLDTE)
    ; Reset *error* to previous definition.
    (setq *error* OLDERR)
    ; Exit quietly (no return value.)

    (prin1)
    )
     
    Big 'D', May 21, 2004
    #1
  2. Big 'D'

    Big 'D' Guest

    Is this possible without too much trouble?
     
    Big 'D', May 21, 2004
    #2
  3. Big 'D'

    BillZ Guest

    D,

    Here is a way that I have used to determine xy of points.

    (foreach n (list pt1 pt2)
    (setq xlt (cons (car n) xlt) ;all x's
    ylt (cons (cadr n) ylt)) ;all y's
    )

    (setq mnx (apply 'min xlt) ;minimum x
    mny (apply 'min ylt) ;minimum y.
    mxx (apply 'max xlt) ;maximum x
    mxy (apply 'max ylt) ;
    ptll (list mnx mny) ;LL corner of area.
    ptur (list mxx mxy) ;upper right.
    )

    HTH
    Bill
     
    BillZ, May 21, 2004
    #3
  4. Big 'D'

    ECCAD Guest

    Bill,
    Clean. I like it.
    :)
    Bob
     
    ECCAD, May 21, 2004
    #4
  5. Big 'D'

    David Doane Guest

    Still playin' around. <g>

    (defun *error* (errmes)
    (princ (strcat "\nExecution of ADD halted by the following error: "
    ERRMES))
    (setvar "cmdecho" OLDCE)
    (setq *error* OLDERR)
    (prin1)
    )
    ;-----;
    (defun c:pb ( / OLDCE OLDERR OLDTE pt1 pt2 xbase ybase xrbase xmidbase
    breakanswer)
    ; Save the current value of
    cmdecho then redefine it.
    (setq OLDCE (getvar "cmdecho"))
    (setvar "cmdecho" 1)
    ; Save the current value of
    texteval then set it to 1
    (setq OLDTE (getvar "texteval"))
    (setvar "texteval" 1)
    ; Save the current value of the
    error handling subroutine then redefine it.
    (setq OLDERR *error*)

    ;(setq *error* nil)
    ; NOTE: to turn error handling
    off, erase the semicolon in the line above.

    ; Input to AutoCAD's command
    line.

    ;(command "layer" "s" "obj" "")

    (initget 1)
    (setq pt1 (getpoint "First corner: ")
    pt2 (cond ((getcorner pt1 "Opposite corner <@0.5,1.0>: "))
    ((mapcar '+ pt1 '(0.5 1.0))
    )
    )
    )

    (command "rectangle" pt1 pt2)

    (if (< (car pt1) (car pt2))
    (setq xbase (car pt1))
    (setq xbase (car pt2))
    )

    (if (< (cadr pt1) (cadr pt2))
    (setq ybase (cadr pt1))
    (setq ybase (cadr pt2))
    )

    (setq xrbase (list xbase ybase))

    (setq xmidbase (/ (+ (car pt1)(car pt2)) 2)
    )

    ; (command "donut" "0.0" "0.06" xrbase "")

    (initget "Yes No")
    (setq breakanswer (getkword "\nDo you want a break [Yes/No] <Yes>: "))

    (if (/= breakanswer "No")

    (progn

    (command "break" (entlast) "non" (list (- xmidbase (/ 0.06 2)) ybase)
    "non" (list (+ xmidbase (/ 0.06 2)) ybase))

    ;(command "insert" "G:/Acad2000/cadstd/symlib/DC-10/bko" "non" (list
    xmidbase ybase) "1" "1" "0")

    );progn

    )
    (princ)
    )
     
    David Doane, May 21, 2004
    #5
  6. Big 'D'

    ECCAD Guest

    D,
    I was playing around with your routine, tried BillZ's point calculations. Refined code a bit. Here is what I have now.

    (defun *error* (errmes)
    (princ (strcat "\nExecution of ADD halted by the following error: " ERRMES))
    (setvar "cmdecho" OLDCE)
    (setq *error* OLDERR)
    (prin1)
    )
    ;-----;
    (defun c:pb ( / OLDCE OLDERR OLDTE)
    ; Save the current value of cmdecho then redefine it.
    (setq OLDCE (getvar "cmdecho"))
    (setvar "cmdecho" 1)
    ; Save the current value of texteval then set it to 1
    (setq OLDTE (getvar "texteval"))
    (setvar "texteval" 1)
    ; Save the current value of the error handling subroutine then redefine it.
    (setq OLDERR *error*)

    ;(setq *error* nil)
    ; NOTE: to turn error handling off, erase the semicolon in the line above.

    ; Input to AutoCAD's command line.
    (if (tblsearch "layer" "obj")
    (command "layer" "s" "obj" "")
    )

    (initget 1)
    (setq pt1 (getpoint "First corner: ")
    pt2 (cond ((getcorner pt1 "Opposite corner <@0.16,-1.0>: "))
    ((mapcar '+ pt1 '(0.16 -1.0))
    )
    )
    )

    ;; Calculate all 4 points.. Note: not working ?
    ;(foreach n (list pt1 pt2)
    ;(setq xlt (cons (car n) xlt) ;all x's
    ;ylt (cons (cadr n) ylt)) ;all y's
    ;)

    ;(setq mnx (apply 'min xlt) ;minimum x
    ;mny (apply 'min ylt) ;minimum y.
    ;mxx (apply 'max xlt) ;maximum x
    ;mxy (apply 'max ylt) ;
    ;ptll (list mnx mny) ;LL corner of area.
    ;ptur (list mxx mxy) ;upper right.
    ;)

    ;; Calculate all 4 points..
    (setq x1 (car pt1) y1 (cadr pt1)); get x / y values point 1
    (setq x2 (car pt2) y2 (cadr pt2)); get x / y values point 2
    (setq pt3 (list x2 y1))
    (setq pt4 (list x1 y2))
    ;; establish lower left point..ptx
    (if (and (> y1 y2)(< x2 x1))
    (setq ptll pt2)
    )
    (if (and (> y1 y2)(> x2 x1))
    (setq ptll pt4)
    )
    (if (and (> y2 y1)(< x1 x2))
    (setq ptll pt1)
    )
    (if (and (> y2 y1)(> x1 x2))
    (setq ptll pt3)
    )
    ;;
    (command "rectangle" pt1 pt2)

    (if (< (cadr pt1) (cadr pt2))
    (setq ybase (cadr pt1))
    (setq ybase (cadr pt2))
    )

    (setq xmidbase (/ (+ (car pt1)(car pt2)) 2)
    )

    (initget "Yes No")
    (setq breakanswer (getkword "\nDo you want a break [Yes/No] <Yes>: "))

    (if (/= breakanswer "No")
    (progn
    (command "break" (entlast) "non" (list (- xmidbase (/ 0.06 2)) ybase) "non" (list (+ xmidbase (/ 0.06 2)) ybase))
    (command "insert" "G:/Acad2000/cadstd/symlib/DC-10/bko" "non" (list xmidbase ybase) "1" "1" "0")
    );progn
    )

    (command "osnap" "none" "osnap" "end")
    (command "insert" "G:/Acad2000/cadstd/symlib/DC-10/equ" PAUSE "1" "1" "0" "explode" "last" "osnap" "none")

    ;; Add some text..
    (setq mytext (strcase (getstring 1 "\nText to apply Lower Left Corner :")))
    (setq ts "0.125"); text height
    (command "_text" ptll ts "0" mytext)
    ;;

    ; RUN LISP routine "C:SYMDATA" and store the result in RSLT.
    ;(setq RSLT (C:SYMDATA))

    ; Reset "cmdecho" to previous value.
    (setvar "cmdecho" OLDCE)
    ; Reset "texteval" to previous value.
    (setvar "texteval" OLDTE)
    ; Reset *error* to previous definition.
    (setq *error* OLDERR)
    ; Exit quietly (no return value.)

    (prin1)
    )
     
    ECCAD, May 22, 2004
    #6
  7. Big 'D'

    BillZ Guest

    ;; Calculate all 4 points.. Note: not working ? <<

    Bob,
    Are you localizing xlt and ylt?


    (setq lt (list pt1 pt2)
    xlt (mapcar '(lambda (x)(car x)) lt) ;all x's
    ylt (mapcar '(lambda (y)(cadr y)) lt) ;all y's
    )

    (setq mnx (apply 'min xlt) ;minimum x
    mny (apply 'min ylt) ;minimum y.
    mxx (apply 'max xlt) ;maximum x
    mxy (apply 'max ylt) ;
    ptll (list mnx mny) ;LL corner of area.
    ptur (list mxx mxy) ;upper right.
    ptul (list mnx mxy) ;upper left
    ptlr (list mxx mny ;lower right
    )

    Minumum x + minimum y = lower left.

    Bill
     
    BillZ, May 24, 2004
    #7
  8. Big 'D'

    ECCAD Guest

    Bill,
    No. Just cut-paste the code, comment out my calc's, and
    allow yours and try it. I get text off in space to left.?

    Bob
     
    ECCAD, May 24, 2004
    #8
  9. Big 'D'

    BillZ Guest

    It crashes.


    Bill
     
    BillZ, May 24, 2004
    #9
  10. Big 'D'

    BillZ Guest

    Sorry,
    The insert was the problem here.

    Tried it and it works with my code.

    (defun *error* (errmes)
    (princ (strcat "\nExecution of ADD halted by the following error: " ERRMES))
    (setvar "cmdecho" OLDCE)
    (setq *error* OLDERR)
    (prin1)
    )
    ;-----;
    (defun c:pb ( / OLDCE OLDERR OLDTE)
    ; Save the current value of cmdecho then redefine it.
    (setq OLDCE (getvar "cmdecho"))
    (setvar "cmdecho" 1)
    ; Save the current value of texteval then set it to 1
    (setq OLDTE (getvar "texteval"))
    (setvar "texteval" 1)
    ; Save the current value of the error handling subroutine then redefine it.
    (setq OLDERR *error*)

    ;(setq *error* nil)
    ; NOTE: to turn error handling off, erase the semicolon in the line above.

    ; Input to AutoCAD's command line.
    (if (tblsearch "layer" "obj")
    (command "layer" "s" "obj" "")
    )

    (initget 1)
    (setq pt1 (getpoint "First corner: ")
    pt2 (cond ((getcorner pt1 "Opposite corner <@0.16,-1.0>: "))
    ((mapcar '+ pt1 '(0.16 -1.0))
    )
    )
    )

    ;; Calculate all 4 points.. Note: not working ?
    (foreach n (list pt1 pt2)
    (setq xlt (cons (car n) xlt) ;all x's
    ylt (cons (cadr n) ylt)) ;all y's
    )

    (setq mnx (apply 'min xlt) ;minimum x
    mny (apply 'min ylt) ;minimum y.
    mxx (apply 'max xlt) ;maximum x
    mxy (apply 'max ylt) ;
    ptll (list mnx mny) ;LL corner of area.
    ptur (list mxx mxy) ;upper right.
    )

    ;; Calculate all 4 points..
    (setq x1 (car pt1) y1 (cadr pt1)); get x / y values point 1
    (setq x2 (car pt2) y2 (cadr pt2)); get x / y values point 2
    (setq pt3 (list x2 y1))
    (setq pt4 (list x1 y2))
    ;; establish lower left point..ptx
    ;(if (and (> y1 y2)(< x2 x1))
    ;(setq ptll pt2)
    ;)
    ;(if (and (> y1 y2)(> x2 x1))
    ;(setq ptll pt4)
    ;)
    ;(if (and (> y2 y1)(< x1 x2))
    ;(setq ptll pt1)
    ;)
    ;(if (and (> y2 y1)(> x1 x2))
    ;(setq ptll pt3)
    ;)
    ;;
    (command "rectangle" pt1 pt2)

    (if (< (cadr pt1) (cadr pt2))
    (setq ybase (cadr pt1))
    (setq ybase (cadr pt2))
    )

    (setq xmidbase (/ (+ (car pt1)(car pt2)) 2)
    )

    (initget "Yes No")
    (setq breakanswer (getkword "\nDo you want a break [Yes/No] <Yes>: "))

    (if (/= breakanswer "No")
    (progn
    (command "break" (entlast) "non" (list (- xmidbase (/ 0.06 2)) ybase) "non" (list (+ xmidbase (/ 0.06 2)) ybase))
    (command "insert" "G:/Acad2000/cadstd/symlib/DC-10/bko" "non" (list xmidbase ybase) "1" "1" "0")
    );progn
    )

    (command "osnap" "none" "osnap" "end")
    (command "insert" "G:/Acad2000/cadstd/symlib/DC-10/equ" PAUSE "1" "1" "0" "explode" "last" "osnap" "none")

    ;; Add some text..
    (setq mytext (strcase (getstring 1 "\nText to apply Lower Left Corner :")))
    (setq ts "0.125"); text height
    (command "_text" ptll ts "0" mytext)
    ;;

    ; RUN LISP routine "C:SYMDATA" and store the result in RSLT.
    ;(setq RSLT (C:SYMDATA))

    ; Reset "cmdecho" to previous value.
    (setvar "cmdecho" OLDCE)
    ; Reset "texteval" to previous value.
    (setvar "texteval" OLDTE)
    ; Reset *error* to previous definition.
    (setq *error* OLDERR)
    ; Exit quietly (no return value.)

    (prin1)
    )


    Bill
     
    BillZ, May 24, 2004
    #10
  11. Big 'D'

    ECCAD Guest

    Ok,
    Noted:
    :)
    Bob
     
    ECCAD, May 24, 2004
    #11
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.