Author Topic: Why is this lisp count start point of 2 lines as one point?  (Read 1141 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1421
Why is this lisp count start point of 2 lines as one point?
« on: April 18, 2018, 12:02:25 PM »
attached snapshop for the result no. 1 has 2 lines
The code
Code - Auto/Visual Lisp: [Select]
  1. (defun c:RVC ( / *acad arc clyr doc gp gp1 i obj objs ortmd
  2.                p1 p1x p1y p2 p2x p2y p3 p4 p5 p5x p5y ptlist
  3.                sp spc tmp ts)
  4.         spc (if (zerop (vla-get-activespace doc))
  5.               (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc))
  6.               (vla-get-modelspace doc)))
  7.  
  8.   (setq arc  500)
  9.   (setq gp (getpoint "\nPick gathering porvcint"))
  10.   (setq gp (trans gp 1 0))
  11.   (setq ts (getvar 'TEXTSIZE))
  12.   (setvar 'TEXTSIZE 250)
  13.   (setq sp (getvar 'TEXTSIZE))
  14.   (setq i -1)
  15.    
  16.   (while T
  17.     (if (and (setq p1 (getpoint "\nPick first corner"))
  18.              (setq p1 (trans p1 1 0 ))
  19.              (setq ortmd (getvar "orthomode"))
  20.              (setvar "orthomode" 0)
  21.              (setq p2 (getcorner p1 "\nPick second corner"))
  22.              (setq p2 (trans p2 1 0 ))
  23.              (setvar "orthomode" ortmd)
  24.              )
  25.       (progn
  26.         (setq clyr (getvar "clayer"))
  27.         (vl-cmdf "_.LAYER" "MAKE" "Defpoints" "")
  28.         (setvar "clayer" clyr)
  29.         (setq p1X (min (nth 0 p1) (nth 0 p2))
  30.               p1Y (min (nth 1 p1) (nth 1 p2))
  31.               p2X (max (nth 0 p1) (nth 0 p2))
  32.               p2Y (max (nth 1 p1) (nth 1 p2))
  33.               )
  34.         (setq p1 (list p1X p1Y 0)
  35.               p2 (list p2X p2Y 0)
  36.               p3 (list p2X p1Y 0)
  37.               p4 (list p1X p2Y 0)
  38.               ptlist (list p1 p3 p2 p4)
  39.               ptlist (apply 'append ptlist)
  40.               )
  41.         (setq tmp (vlax-make-safearray vlax-vbDouble (cons 0 (- (length ptlist) 1))))
  42.         (vlax-safearray-fill tmp ptlist)
  43.  
  44.         (setq obj (vla-addPolyline spc tmp))
  45.         (vla-put-closed obj :vlax-true)
  46.  
  47.         (vl-cmdf "_.Revcloud" "A" arc arc "" (entlast) "NO")
  48.         (setq obj (vlax-ename->vla-object (entlast)))
  49.         (setq objs (vla-put-layer obj "Defpoints"))
  50.         (setq objs (vla-put-color obj 256))
  51.  
  52.         (if (< 0 (nth 0 p1)) (setq p5x (nth 0 p1)) (setq p5x (nth 0 p2)))
  53.         (if (< 0 (nth 1 p1)) (setq p5y (nth 1 p1)) (setq p5y (nth 1 p4)))
  54.  
  55.         (setq p5 (kjk_nearest gp (list p1 p2 p3 p4 )))
  56.         (setq gp1 (polar gp (* 1.5 pi) (* (setq i (1+ i)) (* sp 2))))
  57.  
  58.         (vl-cmdf "_.LINE" gp1 p5 "")
  59.         (setq obj (vlax-ename->vla-object (entlast)))
  60.         (setq objs (vla-put-layer obj "Defpoints"))
  61.         (setq objs (vla-put-color obj 256))
  62.         (setq objs (vla-put-linetype obj "Continuous"))
  63.  
  64.         (setq obj (vla-addtext spc (strcat (itoa (1+ i)) " - ") (vlax-3D-point gp1) sp))
  65.         (setq objs (vla-put-layer obj "Defpoints"))
  66.         (setq objs (vla-put-color obj 256))
  67.        
  68.         )))
  69.   (setvar 'TEXTSIZE ts)
  70.   )
  71. (defun kjk_nearest (pt1 ptlist / tpt nearest)
  72.   (foreach tpt ptlist (if tpt (setq nearest tpt)))
  73.   (foreach tpt ptlist (if tpt (if (< (distance tpt pt1) (distance pt1 nearest)) (setq nearest tpt))))
  74.   nearest
  75. )
  76.  
Thanks in advance

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Why is this lisp count start point of 2 lines as one point?
« Reply #1 on: April 18, 2018, 12:12:35 PM »
Without trying the lisp, Turn the osnaps off.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

HasanCAD

  • Swamp Rat
  • Posts: 1421
Re: Why is this lisp count start point of 2 lines as one point?
« Reply #2 on: April 19, 2018, 03:09:52 AM »
Thanks CAB
Working perfect