@Kent1Cooper wrote:
@ВeekeeCZ 's routine has angle-determination code with more capability than it needs, because it comes out of my Bisector.lsp routine which requires you to pick two straight objects, and sets variables related to the two of them separately, which is not needed here. I also have an AlignSnap.lsp routine which uses the same checking on a single selected object to get its angle, to which I have added the Leader part here:
(defun C:ALLA ; = Align Leader Landing Angle
(/ snang apert esel edata etype picknear path)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg))
); if
(setvar 'aperture apert)
(setvar 'snapang snang)
(setvar 'orthomode orth)
); defun
(setq snang (getvar 'snapang))
(setq apert (getvar 'aperture))
(setq orth (getvar 'orthomode))
(setvar 'aperture (getvar 'pickbox)); less likely to snap to wrong object
(while
(not
(and
(setq esel (entsel "\nSelect object to Align Leader landing angle with: "))
(setq
edata (entget (car esel))
etype (cdr (assoc 0 edata))
); setq
(wcmatch etype "*LINE,ARC,CIRCLE,ELLIPSE,LEADER,HATCH,TEXT,MTEXT,INSERT,VIEWPORT,TRACE,SOLID,WIPEOUT,3DFACE,ATTDEF,AEC_WALL")
); and
); not
(prompt "\nNothing selected, or cannot Align Snap with that object --")
); while
(cond
((= etype "HATCH") (setvar 'snapang (cdr (assoc 52 edata))))
((wcmatch etype "*TEXT,INSERT,ATTDEF")
(setvar 'snapang (cdr (assoc 50 edata)))
); text/mtext/block/xref/attribute types
((wcmatch etype "MLINE,TRACE,SOLID,VIEWPORT,WIPEOUT,3DFACE,AEC_WALL")
(setq picknear (osnap (cadr esel) "nea"))
(setvar 'snapang (angle picknear (osnap picknear "end")))
); non-"curve" types with straight edges that can be Osnapped to
(T; for everything else
(setq
path (car esel)
picknear (osnap (cadr esel) "nea")
); setq
(setvar 'snapang
(angle
'(0 0 0)
(vlax-curve-getFirstDeriv path (vlax-curve-getParamAtPoint path picknear))
); angle
); setvar
); linear-curvilinear entity types
); cond - type of entity
(setvar 'orthomode 0)
(command "_.leader" pause pause)
(setvar 'orthomode 1)
(command pause "" "" "_none"); finish Leader
(setvar 'aperture apert)
(setvar 'snapang snang)
(setvar 'orthomode orth)
); defun
It assumes you always want a two-leg Leader as in your image. It aligns the SNAPANG System Variable with the straight thing you pick on, starts a LEADER command with ORTHO turned off for the first two picks, then turns ORTHO on for the third pick [yes, you could draw the landing part perpendicular to that direction, but I leave it to you to do the result you want], and ends the command. It then resets System Variables that it changed in the process.
After testing this out, this is the solution that I was hoping for. Works great, just got to remember to use it now instead of eyeballing. Much appreciated!