If the answers to some of my earlier questions are that it will always be between orthogonal elements, here's another approach. It works with either a Line or either kind of Polyline. It simply checks the angle of the selected Line or Polyline line segment, and if it's at any of the 45° directions, it proceeds. It refuses not only other object types but also arc segments of Polylines.
BUT, as with several other offerings on this thread, it will label any 45°-direction Line or Polyline line segment, whether or not it's actually a Chamfer, and even if it is, whether or not the adjacent Lines or Polyline segments extend orthogonally from its ends. So it's up to the User to select only an appropriate object.
(vl-load-com)
(defun C:CCML ; = Chamfered Corner Multileader Label
(/ *error* doc svn svv esel ent pick ang mid)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg))
); if
(mapcar 'setvar svn svv); reset System Variables
(vla-endundomark doc)
(princ)
); defun - *error*
(vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
(setq ; System Variable saving/resetting without separate variables for each:
svn '(aperture orthomode); System Variable Names
svv (mapcar 'getvar svn); System Variable current Values
); setq
(mapcar 'setvar svn (list (getvar 'aperture) 0))
; prevent Osnapping to something else, Ortho off
(setq esel (entsel "\nChamfered edge Line/Polyline: "))
(if
(and
(setq ent (car esel) pick (cadr esel))
(wcmatch (cdr (assoc 0 (entget ent))) "LINE,*POLYLINE")
(not (osnap pick "_cen")); if on Polyline, not an arc segment
); and
(progn ; then
(setq ang
(angle
'(0 0)
(vlax-curve-getFirstDeriv ent (vlax-curve-getParamAtPoint ent (setq mid (osnap pick "_mid"))))
); angle & ang
); setq
(if
(and
(equal (rem ang (/ pi 4)) 0 1e-3); multiple of 45°
(not (equal (rem ang (/ pi 2)) 0 1e-3)); but not multiple of 90°
); and
(progn ; then
(setq end (osnap pick "_end")); either end
(command
"_.mleader" "_non" mid pause
(strcat "C" (rtos (* (distance mid end) (sqrt 0.5) 2))) ""
; in current Units mode/precision settings; use line below instead to round to integer
;; (strcat "C" (rtos (* (distance mid end) (sqrt 0.5) 2) 2 0)) ""
); command
); progn
(prompt "\nError - not equal-distance Chamfer of orthogonal edges."); else
); if [angle]
); progn
(prompt "\nNothing selected, not a Line or Polyline, or on a Polyline arc segment."); else
); if [object type]
(mapcar 'setvar svn svv); reset
(vla-endundomark doc)
(princ)
); defun
(prompt "\nType CCML for a Chamfered Corner Multileader Label.")
Kent Cooper, AIA