Jump to content

Recommended Posts

Posted

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.

Posted (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 by mhupp
  • Like 1
Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...