add command and repeat

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

  1. Big 'D'

    Big 'D' Guest

    The attached code inserts a block called c:/zone. Then, it is supposed to ask user if I want to add c:/zone2, if yes, add and prompt for another c:/zone - until I say no - then it should end.
    I am missing something in the part where it prompts me for zone2. It stops clean after inserting zone. Anyone see the problem? Feel free to add any additional suggestions.

    ; Define the function (the program).
    (defun c:zn ( / 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*)
    (defun *error* (errmes)
    (princ (strcat "\nExecution of ADD halted by the following error: " ERRMES))
    (setvar "cmdecho" OLDCE)
    (setq *error* OLDERR)
    (prin1)
    )
    ;(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"
    "b1"
    ""
    )


    (command "insert" "C:/zone" PAUSE "1" "1" "0")

    );progn

    (command "osnap"
    "none"
    "osnap"
    "end"
    )
    );;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ;;; Additional zone for the same sheet
    ;;;
    ;;; Prompt for Additional zone for this sheet


    (initget "Yes No")
    (setq plugloc (getkword "\nDo you want an additional zone for this sheet [Y/N] <Yes>: "))
    (if (/= plugloc "No")

    (progn

    (command "insert" "C:/zone2" PAUSE "1" "1" "0")

    );progn

    )


    ;;; End of plug/receptacle additions to right side of equipment
    ;;;
    ;;;
    ;;;
    ;;; End of Additional zone for this sheet

    (command "osnap" "none")


    ; 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', Aug 19, 2004
    #1
  2. Big 'D'

    Big 'D' Guest

    Additionally, If I answer yes to adding zone2 (half of the size of rectangl of block 'zone' with no left side), I would also like for the block to automatically add to the bottom right corner of block 'zone' (which is a rectangle with text). Each additional addition of 'zone2' would be to the outer most bottom right corner. This may be so much easier to just be automatically prompted for an endpoint and have user select each time. Tell me what you think.

    Sorry for the added request.

    D
     
    Big 'D', Aug 19, 2004
    #2
  3. Big 'D'

    larry Guest

    (if (/= plugloc "No")


    ask user if I want to add c:/zone2, if yes, add and prompt for another
    c:/zone - until I say no - then it should end.
    clean after inserting zone. Anyone see the problem? Feel free to add any
    additional suggestions.
     
    larry, Aug 19, 2004
    #3
  4. Big 'D'

    Big 'D' Guest

    Thank you, Larry, for your help cleaning up the routine. I still have something off a bit. The routine is not inserting the second block (zone2). I changed the text 'plugloc' to read 'zoneloc'. I want the block to insert at the bottom right corner of 'zone' (if answered 'Yes') then at the corner of the added block 'zone2' until answer is 'No' (then stop command).
     
    Big 'D', Aug 19, 2004
    #4
  5. Big 'D'

    larry Guest

    can you send me the zone1 and zone2 dwg
    something off a bit. The routine is not inserting the second block (zone2).
    I changed the text 'plugloc' to read 'zoneloc'. I want the block to insert
    at the bottom right corner of 'zone' (if answered 'Yes') then at the corner
    of the added block 'zone2' until answer is 'No' (then stop command).
     
    larry, Aug 19, 2004
    #5
  6. Big 'D'

    Big 'D' Guest

    I revised the lisp. Now everythink works except for the repeat of adding zone2. I can just add several. But, If I do, invariably, someone will need one more no matter how many I add in the lisp.Here is the update:
    ; Define the function (the program).
    (defun c:zn ( / 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*)
    (defun *error* (errmes)
    (princ (strcat "\nExecution of ADD halted by the following error: " ERRMES))
    (setvar "cmdecho" OLDCE)
    (setq *error* OLDERR)
    (prin1)
    )
    ;(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"
    "b1"
    ""
    )


    (command "insert" "C:/ARINC/Standards/cadstd/Blocks/Reference/zone" PAUSE "1" "1" "0")

    (command "osnap"
    "none"
    "osnap"
    "end"
    )
    ;;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ;;; Additional zone for the same sheet
    ;;;
    ;;; Prompt for Additional zone for this sheet


    (initget "Yes No")
    (setq zoneloc (getkword "\nDo you want an additional zone for this sheet [Y/N] <Yes>: "))
    (if (/= zoneloc "No")


    (command "insert" "C:/ARINC/Standards/cadstd/Blocks/Reference/zone2" PAUSE "1" "1" "0")

    )


    ;;; End of Additional zone for this sheet

    (command "osnap" "none")


    ; 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', Aug 19, 2004
    #6
  7. Big 'D'

    larry Guest

    here it is
    let me know if this work for you


    (defun c:zn (/ 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*)
    (defun *error* (errmes)
    (princ
    (strcat "\nExecution of ADD halted by the following error: "
    ERRMES
    )
    )
    (setvar "cmdecho" OLDCE)
    (setq *error* OLDERR)
    (prin1)
    )
    ;(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"
    "b1"
    ""
    )


    (command "insert" "C:/zone" PAUSE "1" "1" "0")

    ;progn

    (command "osnap"
    "none"
    "osnap"
    "end"
    )

    (setq x 1)
    (if (or (= x "n") (= x "N"))
    (setq x nil)
    )
    (setq x (getstring "\nInsert another column N/<Y>?"))

    (while x
    (command "insert" "C:/zone2" PAUSE "1" "1" "0")
    (setq x (getstring "\nInsert another column N/<Y>?"))
    (if (or (= x "n") (= x "N"))
    (setq x nil)
    )
    )

    ;;; End of plug/receptacle additions to right side of equipment
    ;;;
    ;;;
    ;;;
    ;;; End of Additional zone for this sheet

    (command "osnap" "none")


    ; 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)
    )





    asked if I want zone2 inserted (if not - end command...if yes, insert zone2
    and ask if I want another one). zone2 wil continue to be added to the right
    of the last until I return 'no'.
     
    larry, Aug 19, 2004
    #7
  8. Big 'D'

    larry Guest

    I found an error this is an up date



    (defun c:zn (/ 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*)
    (defun *error* (errmes)
    (princ
    (strcat "\nExecution of ADD halted by the following error: "
    ERRMES
    )
    )
    (setvar "cmdecho" OLDCE)
    (setq *error* OLDERR)
    (prin1)
    )
    ;(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"
    "b1"
    ""
    )


    (command "insert" "C:/zone" PAUSE "1" "1" "0")

    ;progn

    (command "osnap"
    "none"
    "osnap"
    "end"
    )

    (setq x 1)

    (setq x (getstring "\nInsert another column N/<Y>?"))
    (if (or (= x "n") (= x "N"))
    (setq x nil)
    )
    (while x
    (command "insert" "C:/zone2" PAUSE "1" "1" "0")
    (setq x (getstring "\nInsert another column N/<Y>?"))
    (if (or (= x "n") (= x "N"))
    (setq x nil)
    )
    )

    ;;; End of plug/receptacle additions to right side of equipment
    ;;;
    ;;;
    ;;;
    ;;; End of Additional zone for this sheet

    (command "osnap" "none")


    ; 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)
    )
     
    larry, Aug 19, 2004
    #8
  9. Big 'D'

    Big 'D' Guest

    PERFECT!
    Thank you, Larry
     
    Big 'D', Aug 19, 2004
    #9
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.