Hybrid View

1. Login to Give a bone

entsel point

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 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'```

2. Login to Give a bone

Re: entsel point

Without complete code or a better description of what you're doing couldn't you simply snap to Perpendicular using 'DIST?

3. Login to Give a bone

Re: entsel point

Originally Posted by Tom Beauford
Without complete code or a better description of what you're doing couldn't you simply snap to Perpendicular using 'DIST?
That is something I'm going to try out. Thanks for the response. Also, the code below is what I ended up with (with the help of various CAD forums ). It does what I need.

Code:
```(defun c:rsk (/	      ent     entPt   entDef  lPt1    lPt2    beta
toPt    L	      theta   alpha   dist    offset  *error*
)
(defun *error* (msg)
(or	(wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n; error: " msg))
)
)

(setvar 'errno 0)
(setq ent (entsel "\nFrom point:"))
(while (= (getvar 'errno) 7)
(setvar 'errno 0)
(setq ent (entsel "\nSelect a point on a line or xline"))
)

(setq	entPt
)
(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 (abs (distance toPt entPt)))
(setq theta (angle entPt toPt))
(setq alpha (- theta beta))
(setq dist (abs (* L (sin alpha))))
(setq offset (getreal "\n\nEnter offset:\n"))
(setq dist (+ dist offset))
(setq dist (distof (rtos dist 5 4) 2)) ;rkmcswain - AUGI forum
(command "_offset" dist ent toPt "")

)```

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•