Redundant lines reduced?

Discussion in 'AutoCAD' started by mnelson, Jul 30, 2004.

  1. mnelson

    mnelson Guest

    I’d like a tip on how to clean this up and reduce the redundant lines of code. I’ll need about 10 similar task (as per defun), but only the layer names change a bit. Having some trouble just making a defun c: just do the unique items and not having to repeat redundant items like (getvar "cvport).

    Thanks

    (defun c:trial3 ()
    (if (<= (getvar "cvport") 1)
    (alert "You must place the pointer/crosshair
    in a viewport to run this function"
    )
    )
    (if (= (getvar "tilemode") 1)
    (alert "You must be in a LAYOUT to run this function")
    )
    (if (and (>= (getvar "cvport") 2) (= (getvar "tilemode") 0))
    (progn
    (command "layer" "on" "*trial3*" "t" "*trial3*" "")
    (command "vplayer" "f" "fn-*" "" "f" "rm-*" "" "t" "*trial3*" "" "")
    (princ)
    )
    )
    )

    (defun c:trial4 ()
    (if (<= (getvar "cvport") 1)
    (alert "You must place the pointer/crosshair
    in a viewport to run this function"
    )
    )
    (if (= (getvar "tilemode") 1)
    (alert "You must be in a LAYOUT to run this function")
    )
    (if (and (>= (getvar "cvport") 2) (= (getvar "tilemode") 0))
    (progn
    (command "layer" "on" "*trial4*" "t" "*trial4*" "")
    (command "vplayer" "f" "fn-*" "" "f" "rm-*" "" "t" "*trial4*" "" "")
    (princ)
    )
    )
    )
     
    mnelson, Jul 30, 2004
    #1
  2. Hi mnelson

    Something like this:
    Code:
    (defun c:trial1 () (Trial 1))
    (defun c:trial2 () (Trial 2))
    (defun c:trial3 () (Trial 3))
    (defun c:trial4 () (Trial 4))
    ;----------------------------------------------------------------
    (defun Trial (Num / LayNme)
    (cond
    ((<= (getvar "cvport") 1)
    (alert
    (strcat "You must place the pointer/crosshair "
    "in a viewport to run this function."
    )
    )
    )
    ((= (getvar "tilemode") 1)
    (alert "You must be in a LAYOUT to run this function.")
    )
    (T
    (setq LayNme (strcat "*trial" (itoa Num) "*"))
    (command "_.layer" "_on" LayNme "_t" LayNme ""
    "_.vplayer" "_f" "fn-*,rm-*" "" "_t" LayNme "" ""
    )
    )
    )
    (princ)
    )
    
    Cheers
     
    Jürg Menzi, Jul 30, 2004
    #2
  3. mnelson

    mnelson Guest

    Very nice! Thanks for the help!
     
    mnelson, Jul 30, 2004
    #3
  4. mnelson

    Jürg Menzi Guest

    Glad to help you...¦-)

    Cheers
     
    Jürg Menzi, Jul 31, 2004
    #4
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.