Leika Posted May 29, 2022 Posted May 29, 2022 Hello, I'm trying to know when selecting a line the angle of the line. The code works well with lines, but with a polyline I have to explode it first and select it again. I would have liked that after the explode I know the angle immediately . This is my code : (defun C:AAA (/ lisel ln pt1 pt2) ;(vl-load-com) (while (setq lisel (entsel "\nSelect line <exit>: ")) (if (wcmatch (cdr (assoc 0 (entget (setq ln (car lisel))))) "LINE") ; wcmatch performs a wild-card pattern match on a string (progn (prompt "\nSelected object is line.") (setq lisel (car lisel)) (setq pt1 (cdr (assoc 10 (entget lisel)))) (setq pt2 (cdr (assoc 11 (entget lisel)))) (prompt "\n|") (prompt "\n|") (princ (strcat "\n| Degrees = " (angtos (angle pt1 pt2)) "°")) (princ (strcat "\n| Radians = " (rtos (angle pt1 pt2) 2 3)"\n")) (princ "\n|") (princ) ) (progn (command "_explode" ln) (prompt "\nNO LINE - Please select again.") ) ) ) (princ) ) (C:AAA) Thank you to read this Quote
Tharwat Posted May 29, 2022 Posted May 29, 2022 If you are selecting polyline with two vertices then just use angle function on the two CG 10 as follows: (angle (cdr (assoc 10 (entget ln))) (cdr (assoc 10 (reverse (entget ln)))) 1 Quote
BIGAL Posted May 29, 2022 Posted May 29, 2022 (edited) Maybe this. ; Pline segment with angle (defun c:plseg( / oldsnap pick plobj pick2 param segemnt co-ord pt1 pt2 ang) (setq plent (entsel "\nSelect Pline or line ")) (setq oldsnap (getvar 'osmode)) (setvar "osmode" 0) (cond ((= (cdr (assoc 0 (entget (car plent)))) "LWPOLYLINE") (setq pick (cadr plent) plObj (vlax-ename->vla-object (car plent)) pick2 (vlax-curve-getclosestpointto plobj pick) param (vlax-curve-getparamatpoint plObj pick2) segment (fix param) co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))) pt1 (nth segment co-ord) pt2 (nth (+ segment 1) co-ord)) ) ((= (cdr (assoc 0 (entget (car plent)))) "LINE") (setq lObj (vlax-ename->vla-object (car plent)) pt1 (vlax-curve-getstartPoint lobj) pt2 (vlax-curve-getEndPoint lobj)) ) ((alert "incorrect object selected Pline or line")) ) (setq ang (angle pt1 pt2)) (alert (strcat "angle is " (rtos (/ (* ang 180.0) pi) 2 2) )) (setvar 'osmode oldsnap) (princ) ) Edited May 29, 2022 by BIGAL 2 Quote
Leika Posted May 30, 2022 Author Posted May 30, 2022 @Tharwat, thank you very much, I know now how to do it with two vertices. @Bigal, thank you very much for this code! With closed polylines, one line will give this error: error: bad argument type: 2D/3D point: nil I tested on a rectangle - the other lines work perfectly as i want! I'm one big step further Quote
Leika Posted May 31, 2022 Author Posted May 31, 2022 Hello, Do any of you know where I should write between the code Bigal : If the polyline give me that error (closed) then it need be explode and select again as in my first code. Do you do that by placing assoc 70 somewhere in between? Then I intercept the error... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.