rcb007 Posted May 4, 2022 Posted May 4, 2022 I have been using this alot lately. Great routine. I was wondering how I could swap the reference from being parallel to being 90 degrees of the selected line object. (defun c:foo (/ _foo e i s) (defun _foo (e) (abs (angle (vlax-curve-getstartpoint e) (vlax-curve-getendpoint e)))) (if (and (setq e (car (entsel "\nSelect Line to for Parallel Reference: "))) (setq i (_foo e)) (setq s (ssget "_X" '((-4 . "<OR") (0 . "line") (-4 . "<AND") (0 . "*polyline") (90 . 2) (-4 . "AND>") (-4 . "OR>") ) ) ) ) (progn (foreach pl (mapcar 'cadr (ssnamex s)) (if (not (or (equal (setq a (_foo pl)) i 1e-3) (equal (/ pi 2 a) i 1e-3))) ;;<<--- (/ pi 2 a) from (+ pi a) (ssdel pl s) ) ) (sssetfirst nil s) ) ) (princ) ) Thanks for the help. Quote
mhupp Posted May 4, 2022 Posted May 4, 2022 (edited) Add 90° aka π/2 when calculating i in the 4th line. -Edit- had to keep the angle within 360 so it checks if the (_foo e) angle is less then 270 to add 90 or it will subtract 90. Horizontal lines would make a = 0 and would error with when dividing by 0 or does in Bricscad. added back in (+ pi a) and (- pi a) very neat code. going to have to remember the _foo mini function for the future. (defun c:foo (/ _foo e i s) (defun _foo (e) (abs (angle (vlax-curve-getstartpoint e) (vlax-curve-getendpoint e)))) (if (and (setq e (car (entsel "\nSelect Line to for Perpendicular Reference: "))) (if (< (setq i (_foo e)) (/ (* 3 pi) 2)) (setq i (+ i (/ pi 2))) (setq i (- i (/ pi 2))) ) (setq s (ssget "_X" '((-4 . "<OR") (0 . "line") (-4 . "<AND") (0 . "*polyline") (90 . 2) (-4 . "AND>") (-4 . "OR>") ) ) ) ) (progn (foreach pl (mapcar 'cadr (ssnamex s)) (if (or (equal (setq a (_foo pl)) i 1e-3) (equal (abs (- pi a)) i 1e-3) (equal (abs (+ pi a)) i 1e-3)) (progn) (ssdel pl s) ) ) (sssetfirst nil s) ) ) (prompt (strcat "\n" (rtos (sslength s) 2 0) " Lines found")) (princ) ) Edited May 5, 2022 by mhupp 1 Quote
rcb007 Posted May 5, 2022 Author Posted May 5, 2022 Well, I think Mr Ron did this code originally. So he is the one master mind on this. Thank you for clarifying how to get this to work. Appreciate it alot. 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.