(Defun C:ESQ ()
; (setq InitLen (getreal (strcat "Would you kindly enter a length?("rtos InitLen 2 0)")))
; Reversal [and an extraneous quotation mark] -- you don't want the parenthesis in the prompt to the User, and AutoLisp functions all start with a left parenthesis followed immediately by the function name. Also, (getdist) is better than (getreal), because you have the option to give it by picking two points as well as typing it in in any valid format [including things like feet and inches and fractions when in Architectural units]:
(setq InitLen (getdist (strcat "Would you kindly enter a length?" (rtos InitLen 2 0))))
; But if InitLen does not yet exist, the (rtos) function will fail. I think you want to offer Len as the default, but only if it already exists, otherwise offer 4, and defaults are typically shown in pointy brackets:
(setq InitLen (getdist (strcat "Length <" (if Len (rtos Len 2 0) "4") ">: ")))
; (if Len (setq initLen Len)(setq Len 4))
; Checking for the wrong thing -- If the User supplied a length above [InitLen], use that, otherwise the prior value of Len if there is one, otherwise 4. I think you really mean:
(setq Len (cond (InitLen) (Len) (4)))
(While (setq user_point (getpoint "Select Desired End Point: "))
; (command "polygon, 4" user_point "L" Len "")
; Review the actual prompts and sequence when you do the command manually. Each entry must be its own [nothing like "polygon, 4"]; a number can be fed in as one, without quotes; the option is "Edge" [not L], and if using it, calling for it comes before giving a point;
(command "polygon" 4 "_edge" user_point .....)
; but then there's a problem.... you can't feed in Len for the length of the edge under the circumstances -- it's asking for the other end as a location. You can aim the cursor and type in a length, but a routine can't feed in your set Length at that point [how does it know when you've got it aimed in the direction you want, to feed it in?] You could add more steps by having it ask for an aim direction, with a (getangle) function, which it could then use to calculate where to put the other end of the edge. Or you could make it always orthogonal:
(command "polygon" 4 "_edge" user_point (polar user_point 0 Len))
in which case you could prompt for the desired Lower Left Corner. But consider whether you really want/need to do it by specifying the edge, rather than starting with the center in typical Polygon fashion.
) ; need closing parenthesis for (while) function
); defun
For a square, it would be much easier to build the things around the RECTANG command than POLYGON.
Also, do you really want to use (rtos InitLen 2 0)? That will display only whole numbers -- no squares of 2.5-unit edge length. If you really only use whole-number values, I would use (getint) rather than (getreal)/(getdist), and (itoa) instead of (rtos).
Kent Cooper, AIA