Jump to content

perpendicular from a line


Recommended Posts

It seems to work at any time.

 

[ATTACH]17659[/ATTACH]

 

You are correct, I swear this didn't work in previous releases. Nice to know but I will stay with the UCS method with Ortho on.

Link to comment
Share on other sites

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    10

  • rkmcswain

    5

  • Nina

    5

  • mdbdesign

    3

Top Posters In This Topic

Posted Images

You are correct, I swear this didn't work in previous releases. Nice to know but I will stay with the UCS method with Ortho on.

 

And I'm not abandoning my Per routine. I think I might start using Polar Tracking, though. :)

Link to comment
Share on other sites

You are correct, I swear this didn't work in previous releases.

After you mentioned it, I was thinking the same thing too, until I tried it.

I don't have 2004/5/6 (or whenever Polar trk was added) to try though...

Link to comment
Share on other sites

  • 2 years later...
I wrote this for accomplishing that very thing. Mine will allow you to the closest point (based on your selection), closest end point or picked point.

http://www.cadtutor.net/forum/showpost.php?p=305119&postcount=53

 

You'll need a few subroutines (stated in the info), you can find them here..

http://www.cadtutor.net/forum/showthread.php?t=40344

 

Alan, can you please, post it again? This links looks like not available.

Thank you.

Link to comment
Share on other sites

Alan, can you please, post it again? This links looks like not available.

Thank you.

(defun c:PER (/ e p)
 ;; Draw Perpendicular Line, based on selected *line segment
 ;; Required Subroutines: AT:GetSel, AT:Segment, AT:ClosestPoint, AT:DrawX
 ;; Alan J. Thompson, 11.10.09 / 02.08.11
 (redraw)
 (if
   (and (setq e (AT:GetSel entsel
                           "\nSelect object for angle: "
                           (lambda (x)
                             (wcmatch (cdr (assoc 0 (entget (car x))))
                                      "AECC_ALIGNMENT,AECC_PARCEL_SEGMENT,LINE,*POLYLINE"
                             )
                           )
                )
        )
        (progn (if (wcmatch (cdr (assoc 0 (entget (car e)))) "AECC*")
                 (initget 0 "Selection")
                 (initget 0 "End Selection")
               )
               (setq pt (cond ((getpoint (if (wcmatch (cdr (assoc 0 (entget (car e)))) "AECC*")
                                           "\nSpecity starting point [<Selection>]: "
                                           "\nSpecify starting point [End/<Selection>: "
                                         )
                               )
                              )
                              ("Selection")
                        )
               )
        )
   )
    ((lambda (point)
       (vl-cmdf
         "_.line"
         "_non"
         point
         (strcat
           "<"
           (angtos (+ (/ pi 2.)
                      (apply 'angle (mapcar '(lambda (x) (trans x 0 1)) (cadr (AT:Segment e))))
                   )
                   (getvar 'AUNITS)
                   4
           )
         )
         PAUSE
       )
       (redraw)
     )
      (AT:DrawX (cond ((vl-consp pt) pt)
                      ((eq pt "Selection")
                       (trans (vlax-curve-GetClosestPointTo (car e) (trans (cadr e) 1 0)) 0 1)
                      )
                      ((eq pt "End") (trans (AT:ClosestPoint e) 0 1))
                )
                1
      )
    )
 )
 (princ)
)







(defun AT:GetSel (meth msg fnc / ent)
 ;; meth - selection method (entsel, nentsel, nentselp)
 ;; msg - message to display (nil for default)
 ;; fnc - optional function to apply to selected object
 ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC")))
 ;; Alan J. Thompson, 05.25.10
 (while
   (progn (setvar 'ERRNO 0)
          (setq ent (meth (cond (msg)
                                ("\nSelect object: ")
                          )
                    )
          )
          (cond ((eq (getvar 'ERRNO) 7) (princ "\nMissed, try again."))
                ((eq (type (car ent)) 'ENAME)
                 (if (and fnc (not (fnc ent)))
                   (princ "\nInvalid object!")
                 )
                )
          )
   )
 )
 ent
)


(defun AT:Segment (entPnt)
 ;; Retreive segment number and Start & End points
 ;; entPnt - List with entity (ENAME or VLA-OBJECT) & point
 ;; Alan J. Thompson, 11.10.09 / 08.19.10 / 11.15.11
 (if (vl-consp entPnt)
   ((lambda (e p / n)
      (if (setq n (vlax-curve-getPointAtParam e (1+ p)))
        (list p (list (vlax-curve-getPointAtParam e p) n))
        (list p (list (vlax-curve-getPointAtParam e (1- p)) (vlax-curve-getPointAtParam e p)))
      )
    )
     (car entPnt)
     (fix (vlax-curve-getParamAtPoint
            (car entPnt)
            (vlax-curve-getClosestPointToProjection
              (car entPnt)
              (trans (cadr entPnt) 1 (car entPnt))
              '(0. 0. 1.)
            )
          )
     )
   )
 )
)


(defun AT:ClosestPoint (ep / _next _dist ep el lst)
 ;; Return closest point to selected entity
 ;; ep - entity and point list
 ;; Alan J. Thompson, 09.14.10
 (defun _next (e / p)
   (if (and (setq e (entnext e)) (setq p (cdr (assoc 10 (entget e)))))
     (cons p (_next e))
   )
 )
 (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))
 (if
   (and (vl-consp ep)
        (eq (type (car ep)) 'ENAME)
        (or (eq 1 (getvar 'worlducs)) (setq ep (list (car ep) (trans (cadr ep) 1 0))))
        (cond
          ((vl-position (cdr (assoc 0 (setq el (entget (car ep))))) '("ARC" "LINE" "SPLINE"))
           (setq lst (list (vlax-curve-getStartPoint (car ep)) (vlax-curve-getEndPoint (car ep))))
          )
          ((eq (cdr (assoc 0 el)) "LWPOLYLINE")
           (foreach p el (and (eq (car p) 10) (setq lst (cons (cdr p) lst))))
           lst
          )
          ((eq (cdr (assoc 0 el)) "POLYLINE") (setq lst (_next (car ep))))
        )
   )
    (car (vl-sort lst (function (lambda (a b) (< (_dist a (cadr ep)) (_dist b (cadr ep)))))))
 )
)


(defun AT:DrawX (P C)
 ;; Draw and "X" vector at specified point
 ;; P - Placement point for "X"
 ;; C - Color of "X" (must be integer b/w 1 & 255)
 ;; Alan J. Thompson, 10.31.09
 (if (vl-consp P)
   ((lambda (d)
      (grvecs (cons C
                    (mapcar (function (lambda (n) (polar P (* n pi) d)))
                            '(0.25 1.25 0.75 1.75)
                    )
              )
      )
      P
    )
     (* (getvar 'VIEWSIZE) 0.02)
   )
 )
)

 

Once I discovered Polar and Object Snap Tracking, I use Ortho only on rare occasions.

Same.

Link to comment
Share on other sites

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...