@omarsvn wrote:
.... most of the time I use 0.135 between polygons, so I want to store that distance and change it only when I need a different distance, somethig like when I store the radius, autoCAD store that distance so every time I call the fillet command I dont need to instert the radius distance
....
That way of handling the default [as FILLET does] means you don't need to answer a prompt for the distance [if there's a value set in it], but it just proceeds with the current value unless you specifically call for an option to set a value. [The other way, as OFFSET does it, is to ask you for a value every time, and offer you a default which you can accept with Enter/space, but you are still required to take the step of accepting it if you don't want to set a different value.]
Here's a way to do that FILLET-like approach [lightly tested]:
(defun C:Aligned (/ es en p1 p2 p3 p4 ang p5 p6)
(while (or (not es) (not (listp es))); didn't select something
(if *AO* (prompt (strcat "\nCurrent Aligned Offset distance: " (rtos *AO*) ".")))
(initget 4 "Offset"); no negative, allow "Offset" as option
(setq es (entsel "\nSource object or <Offset>: "))
(if (or (not *AO*) (= es "Offset")); no value yet, or chose option
(setq *AO* ; = Aligned-command Offset distance [global for default]
(cond
( (getdist
(strcat
"\nOffset distance <"
(if *AO* (rtos *AO*) "0.135")
; offer prior value as default if present, 0.135 default on first use
">: "
); strcat
); getdist
); User-input condition
(*AO*); current default [when present] on Enter
(0.135); initial default on Enter at first use
); cond
); setq
); if
); while
(setq
p1 (osnap (cadr es) "_end")
p3 (osnap (cadr es) "_nea")
en (entsel "\nDestination object: ")
p2 (osnap (cadr en) "_end")
p4 (osnap (cadr en) "_nea")
ang (angle p2 p4)
p5 (polar p2 (+ ang (/ pi 2)) *AO*)
p6 (polar p4 (+ ang (/ pi 2)) *AO*)
); setq
(command "_.align" es "" "_non" p1 "_non" p5 "_non" p3 "_non" p6 "" "_No")
(princ)
)
On first use, it asks for a source object or to call for the Offset option and set a value, and if you don't call for the option then, it asks for an Offset distance after selecting the source object, offering your typical value as an initial default that you can accept, or type in or pick on-screen what you want. On subsequent uses, it first reports the current Offset distance [also as FILLET reports its mode and radius], and asks for a source object or to call for the Offset option and set a value [or, if you then decide to, still keep the current one]. If you don't want to set a new value, all you do is select the source object and destination object. It always asks for the source object first, so the prompt for that can contain Offset as an option that you can call for or bypass.
It's otherwise your code, though I streamlined the (setq)ing of a lot of variables into one function.
Depending on surroundings, your Osnapping to set p1/p2 could find some other object's ENDpoint closer than the one you intend, if that other object is within Osnap APERTURE range. If that's a problem, it can be overcome by changing the APERTURE System Variable setting [temporarily] to match the PICKBOX setting, so the Osnap "window" doesn't reach out to other things. That would justify including *error* handling to ensure APERTURE gets reset, in which case setting OSMODE to 0 could also be included, to eliminate the "_non" Osnap calls, and Undo begin/end wrapping could be added.
Consider whether you want to allow an Offset distance of zero. If not, (initget 6 ...).
Kent Cooper, AIA