PDA

View Full Version : How we can set last entered value as default value



prasanthbalu
2013-09-13, 10:06 AM
Hi all,

I am just new to Auto lisp .I have created a lisp routine for offset command as below. My intention is to show last entered cover value as default for offset distance. if we press enter it should accept the last entered value. somebody could help me to rearrange the lisp pattern. Thank you.

(defun c:cr()

(SETQ lyr (TBLSEARCH "LAYER" "COVER"))
(IF
(= lyr NIL)
(COMMAND "-LAYER" "M" "COVER" "C" "6" "" "P" "N" "" "")
(COMMAND "-LAYER" "S" "COVER" "P" "N" "" "")
);IF


(WHILE

(setq pt(getreal "\n Enter cover :"))

(setq so (entsel "\n Select Object To Offset"))

(setq pt1 (getpoint "\n Pick The Point To Offset"))

(command "OFFSET" pt so pt1 "")

);WHILE



(princ)

);DEFUN

Tom Beauford
2013-09-13, 11:37 AM
My intention is to show last entered cover value as default for offset distance. if we press enter it should accept the last entered value. somebody could help me to rearrange the lisp pattern. Thank you.

(WHILE (setq pt(getreal "\n Enter cover :"))
(setq so (entsel "\n Select Object To Offset"))
(setq pt1 (getpoint "\n Pick The Point To Offset"))
(command "OFFSET" pt so pt1 "")
);WHILE

Problem is the while condition will only loop as long as a new value is entered for cover. Try using the "Object To Offset" as the while condition and use getdist for coverNew afterwards. if coverNew is not nil set pt to coverNew. You should also localize your variables:
(defun c:cr(/ lyr pt so pt1)
Good luck, you're off to a good start!

hasancad
2013-09-15, 06:40 AM
check out this

(defun c:cr ( / LYR PT PT1 SO )

(if (not *cvr) (setq *cvr 25)) ; Cover
(IF (TBLSEARCH "LAYER" "COVER")
(COMMAND "-LAYER" "M" "COVER" "C" "6" "" "P" "N" "" "")
(COMMAND "-LAYER" "S" "COVER" "P" "N" "" "")) ;IF

(WHILE
(setq *cvr (getint (strcat "\Enter cover " (itoa *cvr) " mm "))) ; Cover
(setq so (entsel "\n Select Object To Offset"))
(setq pt1 (getpoint "\n Pick The Point To Offset"))
(command "OFFSET" pt so pt1 "")
) ;WHILE
(princ)
) ;DEFUN

Tharwat
2013-09-15, 10:39 AM
Try this ...



(defun c:Test (/ *error c s p)
;; Tharwat 15. Sep. 2013 ;;
(defun *error* (u)
(if c
(setvar 'CLAYER c)
)
(princ "\n*Cancel*")
)
(setq c (getvar 'CLAYER))
(if (tblsearch "LAYER" "COVER")
(setvar 'clayer "COVER")
(command "_.-LAYER" "_M" "COVER" "_C" "6" "" "_P" "N" "" "")
)
(if (progn
(initget 6)
(setq
*val* (cond ((getreal (strcat "\nSpecify cover distance <"
(rtos (cond (*val*)
((setq *val* 1.0))
)
)
">: "
)
)
)
(*val*)
)
)
)
(while
(and
(setq
s (entsel
(strcat "\n Select Object To Offset [ "
(rtos *val* 2 2)
" ] :"
)
)
)
(setq p (getpoint "\n Pick The Point To Offset"))
)
(command "_.OFFSET" "_L" "_C" *val* s p "")
)
)
(setvar 'CLAYER c)
(princ)
)