Author Topic: Edit LISP to find geometric center and ignore duplicates in a list.  (Read 2444 times)

0 Members and 1 Guest are viewing this topic.

osa

  • Mosquito
  • Posts: 1
Hi, I am still in the process of learning AUTOLISP, and would like to edit some script.  Recently I asked a question on autodesk and someone gave me this code which I am grateful for. but I have been trying to edit it for the past few days.

 

basically it selects a polyline, finds intersection points with the polyline and selected objects, then places text at points of intersection

 

the problem is

1- many times the polyline intersects twice with an object, so it places two text objects

2-  the text should be at the geometric center of the polyline or block if necessary to transform it.

i really have tried and it was too complex for my level .. any help would be truly appreciated.





Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:IntersNumbering ( / LM:intersections p s l o z e)
  3.  
  4.   (or *in-n* (setq *in-n* 0))
  5.  
  6.   ;; Intersections  -  Lee Mac ;; Returns a list of all points of intersection between two objects ;; for the given intersection mode.
  7.   ;; ob1,ob2 - [vla] VLA-Objects ;;     mod - [int] acextendoption enum of intersectwith method
  8.  
  9.   (defun LM:intersections ( ob1 ob2 mod / lst rtn )
  10.     (if
  11.       (and
  12.         (vlax-method-applicable-p ob1 'intersectwith)
  13.  
  14.         (vlax-method-applicable-p ob2 'intersectwith)
  15.  
  16.         (setq lst (vlax-invoke ob1 'intersectwith ob2 mod)
  17.               )
  18.              )
  19.       (repeat
  20.         (/ (length lst) 3)
  21.         (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
  22.               lst (cdddr lst))))
  23.     (reverse rtn))
  24.  
  25.   ; ======================================================================================================
  26.  
  27.  
  28.   (if (and (setq p (car (entsel "\nSelect a polyline: ")
  29.                                       );car
  30.                         );setq
  31.            (princ "Select intersecting polylines and blocks, ")
  32.            
  33.            (setq s (ssget '((0 . "LWPOLYLINE,LINE,INSERT"))))
  34.            (or (ssdel p s) t)
  35.            (setq *in-n* (cond ((setq f (getint (strcat "\nStart with <" (itoa (1+ *in-n*)) ">: ")))
  36.                                (1- f))
  37.                               (*in-n*)))
  38.            
  39.            (setq o (vlax-ename->vla-object p))
  40.            (setq l '()
  41.                  z (getvar 'textsize))
  42.            );and
  43.     (repeat (setq i (sslength s))
  44.       (setq e (vlax-ename->vla-object (ssname s (setq i (1- i))))
  45.             l (append (LM:intersections o e acextendnone) l))))
  46.  
  47.   (and l
  48.        (setq l (vl-sort l '(lambda (p1 p2) (< (vlax-curve-getdistatpoint p p1) (vlax-curve-getdistatpoint p p2)))))
  49.        (foreach p l (entmake (list (cons 0 "TEXT") (cons 10 p) (cons 40 z) (cons 1 (itoa (setq *in-n* (1+ *in-n*))))))))
  50.  
  51.   (princ)
  52.   )

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: Edit LISP to find geometric center and ignore duplicates in a list.
« Reply #1 on: November 07, 2022, 07:10:58 AM »
Welcome OSA

I moved your question to the lisp section  :-)

DEVITG

  • Bull Frog
  • Posts: 479
Re: Edit LISP to find geometric center and ignore duplicates in a list.
« Reply #2 on: November 21, 2022, 09:45:43 AM »
Please upload your sample.dwg
Location @ Córdoba Argentina Using ACAD 2019  at Window 10