Author Topic: How can we delete line with lisp  (Read 2387 times)

0 Members and 1 Guest are viewing this topic.

scorpion76

  • Guest
How can we delete line with lisp
« on: October 26, 2018, 04:08:45 AM »
Hi brothers, i write code for drawing the triangle, then i enter new point then drawing line this point to other 3 point. I can do at here.
I want to delete, long line (AC) of intersect. I hope i can tell my problem.
Here is code;

Code: [Select]
(defun c:mst()
  (setq liste nil
i 0
y 0)
 
(setq a1 (getpoint "\nİlk Nokta.."))
  (setq liste (cons a1 liste))
(setq a2 (getpoint "\nİkinci Nokta.."))
(setq liste (cons a2 liste))
(setq a3 (getpoint "\nÜçüncü Nokta.."))
  (setq liste (cons a3 liste))

 (command "_.line" a1 a2 a3 a1 "")

 (while

 (setq new (getpoint "\nYeni Nokta.."))
 
 (setq liste (cons new liste))
 (setq y (length liste))
 (setq listson (reverse liste))
 
 (setq m (- y 1))
 (setq i 0)
 
  (while (< i m)
 
        (command "_.line" (nth i listson) (nth m listson) "")
          (setq i (+ i 1))
  )
 )
   (princ)
)
  ;


« Last Edit: October 26, 2018, 04:17:52 AM by scorpion76 »

kpblc

  • Bull Frog
  • Posts: 396
Re: How can we delete line with lisp
« Reply #1 on: October 31, 2018, 11:10:21 AM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:mst (/ adoc pt1 pt lst ent f_3d2d)
  3.   (defun f_3d2d (p) (list (car p) (cadr p)))
  4.   (if (and (= (type (setq pt1 (vl-catch-all-apply (function (lambda () (getpoint "\nStart point <Cancel> : "))))))
  5.               'list
  6.               ) ;_ end of =
  7.            pt1
  8.            (= (type
  9.                 (setq pt (vl-catch-all-apply (function (lambda () (getpoint pt1 "\nNext point <Cancel> : ")))))
  10.                 ) ;_ end of type
  11.               'list
  12.               ) ;_ end of =
  13.            pt
  14.            ) ;_ end of and
  15.     (progn (setq lst  (mapcar (function f_3d2d) (list pt1 pt))
  16.                  adoc (vla-get-activedocument (vlax-get-acad-object))
  17.                  ent  (vla-addlightweightpolyline (vla-get-modelspace adoc)
  18.                                                   (vlax-make-variant
  19.                                                     (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length (apply 'append lst)))))
  20.                                                                          (apply 'append lst)
  21.                                                                          ) ;_ end of vlax-safearray-fill
  22.                                                     ) ;_ end of vlax-make-variant
  23.                                                   ) ;_ end of vla-addlightweightpolyline
  24.                  ) ;_ end of setq
  25.            (while (and (= (type
  26.                             (setq pt (vl-catch-all-apply (function (lambda () (getpoint (last lst) "\nNext point <Cancel> : ")))))
  27.                             ) ;_ end of type
  28.                           'list
  29.                           ) ;_ end of =
  30.                        pt
  31.                        ) ;_ end of and
  32.              (vla-startundomark adoc)
  33.              (setq lst (append lst (list (f_3d2d pt))))
  34.              (vla-put-coordinates ent
  35.                                   (vlax-make-variant
  36.                                     (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length (apply 'append lst)))))
  37.                                                          (apply 'append lst)
  38.                                                          ) ;_ end of vlax-safearray-fill
  39.                                     ) ;_ end of vlax-make-variant
  40.                                   ) ;_ end of vla-put-Coordinates
  41.              (vla-put-closed ent :vlax-true)
  42.              (vla-endundomark adoc)
  43.              ) ;_ end of while
  44.            ) ;_ end of progn
  45.     ) ;_ end of if
  46.   (princ)
  47.   ) ;_ end of defun
Sorry for my English.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: How can we delete line with lisp
« Reply #2 on: October 31, 2018, 11:39:02 AM »
Perhaps something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ p s)
  2.   (cond
  3.     ((setq s (ssget '((0 . "lwpolyline") (90 . 4))))
  4.      (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  5.        (setq p (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) (entget e))))
  6.        (if (< (distance (car p) (caddr p)) (distance (cadr p) (last p)))
  7.          (entmakex (list '(0 . "line") (cons 10 (car p)) (cons 11 (caddr p)) (assoc 8 (entget e))))
  8.          (entmakex (list '(0 . "line") (cons 10 (cadr p)) (cons 11 (last p)) (assoc 8 (entget e))))
  9.        )
  10.      )
  11.     )
  12.   )
  13.   (princ)
  14. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC