Author Topic: Help with pickpoint  (Read 859 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Help with pickpoint
« on: February 15, 2022, 08:11:58 AM »
I get a lot of use out of this sweet routine by Lee Mac.
I've tried to incorporate inserting a circle (centered on the pick point) When asked to "Select LWPolyline".
I'm getting nowhere fast. Any help would be much appreciated. Thanks in advance.
And a big thank you to Lee for his amazing skills!
 

Code: [Select]
;;------------------=={ Offset LWPolyline Section }==-------------------;;
;;                                                                      ;;
;;  This program prompts the user to specify an offset distance and to  ;;
;;  select an LWPolyline. The user is then prompted to specify two      ;;
;;  points on the LWPolyline enclosing the section to be offset. The    ;;
;;  progam will proceed to offset all segments between the two given    ;;
;;  points to both sides by the specified distance.                     ;;
;;                                                                      ;;
;;  The program is compatible with LWPolylines of constant or varying   ;;
;;  width, with straight and/or arc segments, and defined in any UCS    ;;
;;  construction plane.                                                 ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Version 1.0    -    27-12-2012                                      ;;
;;                                                                      ;;
;;  First release.                                                      ;;
;;----------------------------------------------------------------------;;
;;  Version 1.1    -    05-04-2013                                      ;;
;;                                                                      ;;
;;  Fixed bug when offsetting polyline arc segments.                    ;;
;;----------------------------------------------------------------------;;

(defun c:offsec ( / d e h l m n o p q w x z )
    (if (null *off*)
        (setq *off* 1.0)
    )
    (initget 6)
    (if (setq d (getdist (strcat "\nSpecify Offset <" (rtos *off*) ">: ")))
        (setq *off* d)
        (setq d *off*)
    )
    (while
        (progn (setvar 'errno 0) (setq e (car (entsel "\nSelect LWPolyline: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null e) nil)
                (   (/= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
                    (princ "\nObject is not an LWPolyline.")
                )
                (   (setq p (getpoint "\nSpecify 1st Point: "))
                    (setq p (vlax-curve-getclosestpointto e (trans p 1 0)))
                    (while
                        (and
                            (setq  q (getpoint (trans p 0 1) "\nSpecify 2nd Point: "))
                            (equal p (setq q (vlax-curve-getclosestpointto e (trans q 1 0))) 1e-8)
                        )
                        (princ "\nPoints must be distinct.")
                    )
                    (if q
                        (progn
                            (if (> (setq m (vlax-curve-getparamatpoint e p))
                                   (setq n (vlax-curve-getparamatpoint e q))
                                )
                                (mapcar 'set '(m n p q) (list n m q p))
                            )
                            (setq e (entget e)
                                  h (reverse (member (assoc 39 e) (reverse e)))
                                  h (subst (cons 70 (logand (cdr (assoc 70 h)) (~ 1))) (assoc 70 h) h)
                                  l (LM:LWVertices e)
                                  z (assoc 210 e)
                            )
                            (repeat (fix m)
                                (setq l (cdr l))
                            )
                            (if (not (equal m (fix m) 1e-8))
                                (setq x (car l)
                                      w (cdr (assoc 40 x))
                                      l
                                    (cons
                                        (list
                                            (cons  10 (trans p 0 (cdr z)))
                                            (cons  40 (+ w (* (- m (fix m)) (- (cdr (assoc 41 x)) w))))
                                            (assoc 41 x)
                                            (cons  42
                                                (tan
                                                    (*  (- (min n (1+ (fix m))) m)
                                                        (atan (cdr (assoc 42 x)))
                                                    )
                                                )
                                            )
                                        )
                                        (cdr l)
                                    )
                                )
                            )
                            (setq l (reverse l))
                            (repeat (+ (length l) (fix m) (- (fix n)) -1)
                                (setq l (cdr l))
                            )
                            (if (not (equal n (fix n) 1e-8))
                                (setq x (car l)
                                      w (cdr (assoc 40 x))
                                      l
                                    (vl-list*
                                        (list
                                            (cons 10 (trans q 0 (cdr z)))
                                           '(40 . 0.0)
                                           '(41 . 0.0)
                                           '(42 . 0.0)
                                        )
                                        (list
                                            (assoc 10 x)
                                            (assoc 40 x)
                                            (cons  41
                                                (+ w
                                                    (*  (/ (- n (max m (fix n))) (- (1+ (fix n)) (max m (fix n))))
                                                        (- (cdr (assoc 41 x)) w)
                                                    )
                                                )
                                            )
                                            (cons  42
                                                (tan
                                                    (*  (if (< (fix n) m) 1.0 (- n (fix n)))
                                                        (atan (cdr (assoc 42 x)))
                                                    )
                                                )
                                            )
                                        )
                                        (cdr l)
                                    )
                                )
                            )
                            (setq o
                                (vlax-ename->vla-object
                                    (entmakex (append h (apply 'append (reverse l)) (list z)))
                                )
                            )
                            (vl-catch-all-apply 'vla-offset (list o d))
                            (vl-catch-all-apply 'vla-offset (list o (- d)))
                            (vla-delete o)
                        )
                    )
                )
            )
        )
    )
    (princ)
)

;; Tangent  -  Lee Mac
;; Args: x - real
 
(defun tan ( x )
    (if (not (equal 0.0 (cos x) 1e-8))
        (/ (sin x) (cos x))
    )
)
 
;; LW Vertices  -  Lee Mac
;; Returns a list of lists in which each sublist describes the position,
;; starting width, ending width and bulge of a vertex of an LWPolyline
 
(defun LM:LWVertices ( e )
    (if (setq e (member (assoc 10 e) e))
        (cons
            (list
                (assoc 10 e)
                (assoc 40 e)
                (assoc 41 e)
                (assoc 42 e)
            )
            (LM:LWVertices (cdr e))
        )
    )
)

;;----------------------------------------------------------------------;;

(vl-load-com)
(princ
    (strcat
        "\n:: OffsetSection.lsp | Version 1.1 | \\U+00A9 Lee Mac "
        (menucmd "m=$(edtime,0,yyyy)")
        " www.lee-mac.com ::"
        "\n:: Type \"offsec\" to Invoke ::"
    )
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;

BIGAL

  • Swamp Rat
  • Posts: 1422
  • 40 + years of using Autocad
Re: Help with pickpoint
« Reply #1 on: February 15, 2022, 10:15:24 PM »
The answer is all in your code, when you do a Entsel you get 2 things Entityname and pick pt,  but the pick point can be off the line etc so you use the get closestpointto function to make sure its on the line, this is at start of your code add a new PC point, than add your circle. Can be easily checked with a horizontal line as Y will be the same for the circle

Code: [Select]
(setq e (car (entsel "\nSelect LWPolyline: ")))
do the PC here
CIRCLE
            (cond
A man who never made a mistake never made anything

Lee Mac

  • Seagull
  • Posts: 12919
  • London, England
Re: Help with pickpoint
« Reply #2 on: February 16, 2022, 09:04:05 AM »
Thank you for your compliments & gratitude - I'm delighted that you find the program useful  :-)

Consider the following modified code:
Code - Auto/Visual Lisp: [Select]
  1. ;;------------------=={ Offset LWPolyline Section }==-------------------;;
  2. ;;                                                                      ;;
  3. ;;  This program prompts the user to specify an offset distance and to  ;;
  4. ;;  select an LWPolyline. The user is then prompted to specify two      ;;
  5. ;;  points on the LWPolyline enclosing the section to be offset. The    ;;
  6. ;;  progam will proceed to offset all segments between the two given    ;;
  7. ;;  points to both sides by the specified distance.                     ;;
  8. ;;                                                                      ;;
  9. ;;  The program is compatible with LWPolylines of constant or varying   ;;
  10. ;;  width, with straight and/or arc segments, and defined in any UCS    ;;
  11. ;;  construction plane.                                                 ;;
  12. ;;----------------------------------------------------------------------;;
  13. ;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
  14. ;;----------------------------------------------------------------------;;
  15. ;;  Version 1.0    -    27-12-2012                                      ;;
  16. ;;                                                                      ;;
  17. ;;  First release.                                                      ;;
  18. ;;----------------------------------------------------------------------;;
  19. ;;  Version 1.1    -    05-04-2013                                      ;;
  20. ;;                                                                      ;;
  21. ;;  Fixed bug when offsetting polyline arc segments.                    ;;
  22. ;;----------------------------------------------------------------------;;
  23.  
  24. (defun c:offsec ( / c d e h l m n o p q w x z )
  25.     (if (null *off*)
  26.         (setq *off* 1.0)
  27.     )
  28.     (initget 6)
  29.     (if (setq d (getdist (strcat "\nSpecify Offset <" (rtos *off*) ">: ")))
  30.         (setq *off* d)
  31.         (setq d *off*)
  32.     )
  33.     (while
  34.         (progn
  35.             (setvar 'errno 0)
  36.             (setq e (entsel "\nSelect LWPolyline: ")
  37.                   c (cadr e)
  38.                   e (car  e)
  39.             )
  40.             (cond
  41.                 (   (= 7 (getvar 'errno))
  42.                     (princ "\nMissed, try again.")
  43.                 )
  44.                 (   (null e) nil)
  45.                 (   (/= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
  46.                     (princ "\nObject is not an LWPolyline.")
  47.                 )
  48.                 (   (setq p (getpoint "\nSpecify 1st Point: "))
  49.                     (setq p (vlax-curve-getclosestpointto e (trans p 1 0)))
  50.                     (while
  51.                         (and
  52.                             (setq  q (getpoint (trans p 0 1) "\nSpecify 2nd Point: "))
  53.                             (equal p (setq q (vlax-curve-getclosestpointto e (trans q 1 0))) 1e-8)
  54.                         )
  55.                         (princ "\nPoints must be distinct.")
  56.                     )
  57.                     (if q
  58.                         (progn
  59.                             (entmake
  60.                                 (list
  61.                                    '(000 . "CIRCLE")
  62.                                     (cons  010 (trans (vlax-curve-getclosestpointto e (trans c 1 0)) 0 e))
  63.                                     (cons  040 1.0)
  64.                                     (assoc 210 (entget e))
  65.                                 )
  66.                             )
  67.                             (if (> (setq m (vlax-curve-getparamatpoint e p))
  68.                                    (setq n (vlax-curve-getparamatpoint e q))
  69.                                 )
  70.                                 (mapcar 'set '(m n p q) (list n m q p))
  71.                             )
  72.                             (setq e (entget e)
  73.                                   h (reverse (member (assoc 39 e) (reverse e)))
  74.                                   h (subst (cons 70 (logand (cdr (assoc 70 h)) (~ 1))) (assoc 70 h) h)
  75.                                   l (LM:LWVertices e)
  76.                                   z (assoc 210 e)
  77.                             )
  78.                             (repeat (fix m)
  79.                                 (setq l (cdr l))
  80.                             )
  81.                             (if (not (equal m (fix m) 1e-8))
  82.                                 (setq x (car l)
  83.                                       w (cdr (assoc 40 x))
  84.                                       l
  85.                                     (cons
  86.                                         (list
  87.                                             (cons  10 (trans p 0 (cdr z)))
  88.                                             (cons  40 (+ w (* (- m (fix m)) (- (cdr (assoc 41 x)) w))))
  89.                                             (assoc 41 x)
  90.                                             (cons  42
  91.                                                 (tan
  92.                                                     (*  (- (min n (1+ (fix m))) m)
  93.                                                         (atan (cdr (assoc 42 x)))
  94.                                                     )
  95.                                                 )
  96.                                             )
  97.                                         )
  98.                                         (cdr l)
  99.                                     )
  100.                                 )
  101.                             )
  102.                             (setq l (reverse l))
  103.                             (repeat (+ (length l) (fix m) (- (fix n)) -1)
  104.                                 (setq l (cdr l))
  105.                             )
  106.                             (if (not (equal n (fix n) 1e-8))
  107.                                 (setq x (car l)
  108.                                       w (cdr (assoc 40 x))
  109.                                       l
  110.                                     (vl-list*
  111.                                         (list
  112.                                             (cons 10 (trans q 0 (cdr z)))
  113.                                            '(40 . 0.0)
  114.                                            '(41 . 0.0)
  115.                                            '(42 . 0.0)
  116.                                         )
  117.                                         (list
  118.                                             (assoc 10 x)
  119.                                             (assoc 40 x)
  120.                                             (cons  41
  121.                                                 (+ w
  122.                                                     (*  (/ (- n (max m (fix n))) (- (1+ (fix n)) (max m (fix n))))
  123.                                                         (- (cdr (assoc 41 x)) w)
  124.                                                     )
  125.                                                 )
  126.                                             )
  127.                                             (cons  42
  128.                                                 (tan
  129.                                                     (*  (if (< (fix n) m) 1.0 (- n (fix n)))
  130.                                                         (atan (cdr (assoc 42 x)))
  131.                                                     )
  132.                                                 )
  133.                                             )
  134.                                         )
  135.                                         (cdr l)
  136.                                     )
  137.                                 )
  138.                             )
  139.                             (setq o
  140.                                 (vlax-ename->vla-object
  141.                                     (entmakex (append h (apply 'append (reverse l)) (list z)))
  142.                                 )
  143.                             )
  144.                             (vl-catch-all-apply 'vla-offset (list o d))
  145.                             (vl-catch-all-apply 'vla-offset (list o (- d)))
  146.                             (vla-delete o)
  147.                         )
  148.                     )
  149.                 )
  150.             )
  151.         )
  152.     )
  153.     (princ)
  154. )
  155.  
  156. ;; Tangent  -  Lee Mac
  157. ;; Args: x - real
  158.  
  159. (defun tan ( x )
  160.     (if (not (equal 0.0 (cos x) 1e-8))
  161.         (/ (sin x) (cos x))
  162.     )
  163. )
  164.  
  165. ;; LW Vertices  -  Lee Mac
  166. ;; Returns a list of lists in which each sublist describes the position,
  167. ;; starting width, ending width and bulge of a vertex of an LWPolyline
  168.  
  169. (defun LM:LWVertices ( e )
  170.     (if (setq e (member (assoc 10 e) e))
  171.         (cons
  172.             (list
  173.                 (assoc 10 e)
  174.                 (assoc 40 e)
  175.                 (assoc 41 e)
  176.                 (assoc 42 e)
  177.             )
  178.             (LM:LWVertices (cdr e))
  179.         )
  180.     )
  181. )
  182.  
  183. ;;----------------------------------------------------------------------;;
  184.  
  185.     (strcat
  186.         "\n:: OffsetSection.lsp | Version 1.1 | \\U+00A9 Lee Mac "
  187.         (menucmd "m=$(edtime,0,yyyy)")
  188.         " www.lee-mac.com ::"
  189.         "\n:: Type \"offsec\" to Invoke ::"
  190.     )
  191. )
  192.  
  193. ;;----------------------------------------------------------------------;;
  194. ;;                             End of File                              ;;
  195. ;;----------------------------------------------------------------------;;

The circle radius is set on line 63.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Help with pickpoint
« Reply #3 on: February 16, 2022, 04:05:28 PM »
Thank Lee...I'll give it a shot.