@Kent1Cooper wrote:
@Anonymous wrote:
I'm trying to add the feet, for example I press the command and then i click the point to start the line. Then I type in 62' and it cancels the command and doesn't allow me to write the distance I want the line at. Is there a way to get that functionality in it?
I'll have to think about that.... maybe this evening.
Well, I think this does it:
(defun C:LL45I (/ cmde done cur pt); = Lines Locked to 45-degree angle Increments
(setq cmde (getvar 'cmdecho))
(command "_.line" pause)
(setvar 'cmdecho 0)
(prompt "\nNext point or <exit>: ")
(while (not done)
(setq cur (grread T 12 0))
(cond
((= (car cur) 5); move cursor
(setvar 'snapang ; nearest 45-degree increment to cursor location
(* (/ pi 4) (fix (+ (/ (angle (getvar 'lastpoint) (cadr cur)) (/ pi 4)) 0.5)))
); setvar
(redraw); eliminate previous rubber-band
(grdraw ; rubber-band
(getvar 'lastpoint) ; from
(setq pt
(inters
(getvar 'lastpoint) (polar (getvar 'lastpoint) (getvar 'snapang) 1)
(cadr cur) (polar (cadr cur) (+ (getvar 'snapang) (/ pi 2)) 1)
nil
); inters
); setq
(cdr (assoc 62 (tblsearch "layer" (getvar 'clayer)))); current Layer's color
); grdraw
); cur=5 condition
((= (car cur) 3) (command pt)); picked a point -- use Ortho-ized one
((= (car cur) 2) ; keyboard entry
(cond
((member (cadr cur) '(13 32)); Enter or space
(command "") (redraw) (setq done T); finish
); Enter/space condition
((< 48 (cadr cur) 58); 1 to 9
; [assuming distance entry will not start with 0, nor be negative]
(command
"_none"
(polar
(getvar 'lastpoint)
(getvar 'snapang)
(distof (strcat (chr (cadr cur)) (getstring (chr (cadr cur)))))
); polar
); command
); numerical character condition
(T (prompt "\nInvalid input.")); go back to (while)
); cond [which character]
); keyboard-entry condition
); cond [which input method]
(prompt "\nNext point or <exit>: ")
); while
(setvar 'snapang 0); return to normal
(setvar 'cmdecho cmde)
(princ)
); defun
There's a little quirky aspect to it when you type in a distance. The (grread) reacts immediately upon striking any keyboard character, and it knows what that one character is. It then uses that single character as a prompt, so you see it again at the command line, and you continue to type [if additional character(s)], and it puts together that first character with what you typed subsequently, and converts that overall string into the distance. But something about that operation means that there's a little bit of a half-space-ish width after the first character as prompt, before whatever more you type in [if anything]. Don't be thrown by that -- it seems to work correctly.
I also had it turn off command echoing, and provide the shortened next-point prompt, so you don't see the Undo/Close options of LINE's standard prompt. The oddity about that is that every time you move the cursor even a little, (grread) kicks in again, and that prompt is put up again. So if you type something other than Enter or space or a non-zero number, the Invalid-input prompt goes in, but with any movement of the cursor, it moves up and quickly out of view. So if you hit a key that's invalid, you may not notice the prompt to that effect fly by, but carry on. Maybe later I'll think about having it recognize U and C for Undo and Close options.
As usual, it could use *error* handling to ensure resetting the System Variables, but that can be added easily enough if it works for you otherwise.
Kent Cooper, AIA