Hi all,
I have below a simple instructions to get the perpendicular distance from a LINE/XLINE to a point. The user selects the line or xline and I use the "selection point" from entsel in the calculations in the program. The problem is, the program works great whenever I use a "snap" like "near" or "endpoint" when using entsel. If I just select the entity (line or xline) the number I get is slightly off. Any suggestions?
Thanks
PS
I'm sure there is a much fancier/simpler way of doing what I'm doing but this is what I got
Code:
(defun *error* (msg)
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n; error: " msg))
)
)
(setq ent (entsel))
(setq entPt (cadr ent))
(setq entDef (entget (car ent)))
(setq ent (car ent))
;check ent is line or xline
(cond
(
(or (= (cdr (assoc 0 entDef)) "LINE")
(= (cdr (assoc 0 entDef)) "XLINE")
)
(setq lPt1 (cdr (assoc 10 entDef))
lPt2 (cdr (assoc 11 entDef))
)
(if (= (cdr (assoc 0 entDef)) "XLINE")
(setq beta (angle lPt1 (mapcar '+ lPt1 lPt2)))
(setq beta (angle lPt1 lPt2))
)
)
(T
(princ "Entity must be 'XLINE' or 'LINE'")
(exit)
)
)
(setq toPt (getpoint "\nto point"))
(setq L (distance toPt entPt))
(setq theta (angle entPt toPt))
(setq alpha (- theta beta))
(setq a (abs (* L (sin alpha))))
(princ a) ; 'a' is perpendicular distance to point selected with 'entsel' and 'toPt'