See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: find dx and offset of a picked point relative to straight polyline

  1. #1
    Member
    Join Date
    2012-06
    Posts
    13
    Login to Give a bone
    0

    Default find dx and offset of a picked point relative to straight polyline

    Hello
    any help to write a lisp that can print on screen dx and offset of a picked point relative to polyline as shown in attached image
    thanks
    Attached Images Attached Images

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: find dx and offset of a picked point relative to straight polyline

    Hi,

    I am not sure that I got your point clearly so more details is required I guess.

    Can you please write down the steps of the program that you are after?
    eg: Select polyline, then Specify a point , .... etc

  3. #3
    Member
    Join Date
    2012-06
    Posts
    13
    Login to Give a bone
    0

    Default Re: find dx and offset of a picked point relative to straight polyline

    Thank you tharwat for reply
    step for input
    1-pick the polyline
    2-pick any place on screen to find dx and offset of this place relative to polyline
    3-pick place to print dx and offset on screen

  4. #4
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: find dx and offset of a picked point relative to straight polyline

    Can you please clarify what is the meaning of DX ? Is it a text, a point, ... ect ?
    What to offset? the polyline or draw a polyline from that DX point perpendicular to the main polyline?

    A drawing with before and after would help a lot to describe the issue.

  5. #5
    Member
    Join Date
    2012-06
    Posts
    13
    Login to Give a bone
    0

    Default Re: find dx and offset of a picked point relative to straight polyline

    offset is the perpendicular distance between picked place and polyline
    dx is the distance between start point of polyline and the fallen point of a picked point on the polyline
    dx is the same delta x
    soo offset and delta x is a number to be print on screen attached with a leader

  6. #6
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    1

    Default Re: find dx and offset of a picked point relative to straight polyline

    Hi,

    Something like this?

    Code:
    (defun c:Test ( / s p c a d)
      ;;	Tharwat - 28.May.2018		;;
      (if (and (setq s (car (entsel "\nPick a polyline :")))
             (or (= (cdr (assoc 0 (entget s))) "LWPOLYLINE")
                 (alert "Invalid object! Please pick a polyline only.")
                 )
             (setq p (getpoint "\nSpecify point perpendicular to polyline :"))
             (setq c (vlax-curve-getclosestpointto s p))
             (setq a (angle p c))
             (not (grdraw p c 1 -1)) ;; rubber line in red colour.
             (setq d (angle '(0. 0. 0.) (vlax-curve-getfirstderiv s (vlax-curve-getparamatpoint s c))))
             (or (or (equal (rem (+ d (* pi 0.5)) (+ pi pi)) a 1e-4)
                     (equal (rem (+ d (* pi 1.5)) (+ pi pi)) a 1e-4)
                     )
                 (alert "Picked point is not a perpendicular to picked polyline. <!>")
                 )
             )
      (command "_.leader" "_non" p "\\" "" (strcat "DX= " (rtos (vlax-curve-getdistatpoint s c) 2 4)
                                                   "\\P"
                                                   "Offset= " (rtos (distance c p) 2 4)) "")
      )
    (princ)
    ) (vl-load-com)
    Last edited by Tharwat; 2018-05-28 at 11:46 AM. Reason: Added extra check-up codes for the angle

  7. #7
    Member
    Join Date
    2012-06
    Posts
    13
    Login to Give a bone
    0

    Default Re: find dx and offset of a picked point relative to straight polyline

    wow very nice lisp tharawat
    one more thing i want if the picked point is outside the length of polyline
    the dx distance will be minus value as shown on image
    second need to add while if i have to repeat different point
    thanks
    Attached Images Attached Images

  8. #8
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    1

    Default Re: find dx and offset of a picked point relative to straight polyline

    Hi,

    Please try this program and let me know.

    Code:
    (defun c:Test (/ *error* oblique ray_ b s p c a d m l z e r)
      ;;	Tharwat - 29.May.2018		;;
      (defun *error* (msg)
        (and r (vla-delete r))
        (princ "\n*cancel*")
      )
      ;;				;;
      (defun oblique (ent pnt)
        (angle '(0. 0. 0.)
               (vlax-curve-getfirstderiv
                 ent
                 (vlax-curve-getparamatpoint ent pnt)
               )
        )
      )
      ;;				;;
      (defun ray_ (spc pt1 pt2)
        (vlax-invoke spc 'addray pt1 pt2)
      )
      ;;				;;
      (setq b (vla-get-block
                (vla-get-activelayout
                  (vla-get-activedocument (vlax-get-acad-object))
                )
              )
      )
      (cond
        ((=
           4
           (logand
             4
             (cdr
               (assoc 70
                      (setq e (entget (tblobjname "LAYER" (getvar 'clayer))))
               )
             )
           )
         )
         (alert "Current layer is locked <!>.")
        )
        ((minusp (cdr (assoc 62 e)))
         (alert "Current layer is off <!>.")
        )
        (t
         (while
           (and
             (setq s (car (entsel "\nPick a polyline :")))
             (or (= (cdr (assoc 0 (entget s))) "LWPOLYLINE")
                 (alert "Invalid object! Please pick a polyline only.")
             )
             (setq
               p (getpoint "\nSpecify point perpendicular to polyline :")
             )
             (setq c (vlax-curve-getclosestpointto s p))
             (setq a (angle p c))
             (setq d (oblique s c))
             (or (or (equal (rem (+ d (* pi 0.5)) (+ pi pi)) a 1e-4)
                     (equal (rem (+ d (* pi 1.5)) (+ pi pi)) a 1e-4)
                 )
                 (progn
                   (setq m (vl-sort (mapcar '(lambda (q) (cons (distance p q) q))
                                            (list (vlax-curve-getstartpoint s)
                                                  (vlax-curve-getendpoint s)
                                            )
                                    )
                                    '(lambda (j k) (< (car j) (car k)))
                           )
                         z (cdr (car m))
                         r (ray_ b z (polar z (+ pi (oblique s z)) 1.0))
                         c (vlax-curve-getclosestpointto r p)
                         l (distance c z)
                   )
                   (vla-delete r)
                   (if (zerop l)
                     (progn
                       (setq r (ray_ b z (polar z (oblique s z) 1.0))
                             c (vlax-curve-getclosestpointto r p)
                             l (distance c z)
                       )
                       (vla-delete r)
                     )
                   )
                   l
                 )
             )
           )
            (command
              "_.leader"
              "_non"
              p
              "\\"
              ""
              (strcat
                (if l
                  (strcat "DX= -" (rtos l 2 4))
                  (strcat "DX= " (rtos (vlax-curve-getdistatpoint s c) 2 4))
                )
                "\\POffset= "
                (rtos (distance c p) 2 4)
              )
              ""
            )
         )
        )
      )
      (princ)
    ) (vl-load-com)
    Last edited by Tharwat; 2018-05-29 at 09:38 PM. Reason: A few lines of codes adjusted.

  9. #9
    Member
    Join Date
    2012-06
    Posts
    13
    Login to Give a bone
    0

    Default Re: find dx and offset of a picked point relative to straight polyline

    thank you tharwat you are a great man
    code is complete

  10. #10
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: find dx and offset of a picked point relative to straight polyline

    Quote Originally Posted by motee View Post
    thank you tharwat you are a great man
    code is complete
    Excellent. You are welcome anytime.

    NOTE: I have updated he codes a bit that related to current layer for a better performance although the program may give unexpected result in certain cases if took a place.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 2009-05-28, 12:20 AM
  2. Determining if a Point is picked inside a 3D Solid
    By roger_wall in forum VBA/COM Interop
    Replies: 0
    Last Post: 2007-02-01, 12:07 AM
  3. How to find the length from the start point of a polyline?
    By pferreira in forum AutoCAD Tips & Tricks
    Replies: 1
    Last Post: 2006-07-10, 03:36 AM
  4. Straight Line from a Curved polyline
    By rhayes.99001 in forum ACA General
    Replies: 2
    Last Post: 2006-06-09, 09:25 AM
  5. Associative dimensions that remember side of point picked
    By lcamara in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2005-01-14, 11:16 PM

Posting Permissions

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