Lisp Delete lines next to circles.

Lisp Delete lines next to circles.

manasi4532
Enthusiast Enthusiast
1,011 Views
14 Replies
Message 1 of 15

Lisp Delete lines next to circles.

manasi4532
Enthusiast
Enthusiast

Is there a way to delete specific objects that have circles attached to them? I've attached an example.

Thank you so much

0 Likes
Accepted solutions (3)
1,012 Views
14 Replies
Replies (14)
Message 2 of 15

EnM4st3r
Advocate
Advocate
Accepted solution

my approach:
ssget objects via circle's bounding box -> check for exactly only one intersection point

(defun c:test123 (/ sel ssresult pt1 pt2 ss i ent)
  (setq sel (ssget '((0 . "Circle"))))
  (setq ssresult (ssadd))
  (if (setq sel (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
    (progn
      (vlax-for obj sel
        (vla-getboundingbox obj 'pt1 'pt2)
        (setq ss (ssget "_C"
                    (vlax-safearray->list pt1)
                    (vlax-safearray->list pt2)
                    '((0 . "~Circle"))
                 )
        )
        (setq i 0)
        (while (and ss (< i (sslength ss)))
          (setq ent (ssname ss i))
          (if (= 1 (length (LM:intersections obj (vlax-ename->vla-object ent) acExtendNone)))
            (ssadd ent ssresult)
          )
          (setq i (1+ i))
        )
      )
      (vla-delete sel)
    )  
  )
  (sssetfirst nil ssresult)
  (princ)
)


;; Intersections  -  Lee Mac
;; Returns a list of all points of intersection between two objects
;; for the given intersection mode.
;; ob1,ob2 - [vla] VLA-Objects
;;     mod - [int] acextendoption enum of intersectwith method

(defun LM:intersections ( ob1 ob2 mod / lst rtn )
    (if (and (vlax-method-applicable-p ob1 'intersectwith)
             (vlax-method-applicable-p ob2 'intersectwith)
             (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
        )
        (repeat (/ (length lst) 3)
            (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
                  lst (cdddr lst)
            )
        )
    )
    (reverse rtn)
)
0 Likes
Message 3 of 15

manasi4532
Enthusiast
Enthusiast

Works almost fine But select only lines. I also want it to select additional adjacent circles. Is it possible? Select Line and Circle . Very Thank you.

0 Likes
Message 4 of 15

EnM4st3r
Advocate
Advocate
Accepted solution

change line 18 to

(progn (ssadd ent ssresult)(ssadd (vlax-vla-object->ename obj) ssresult))
0 Likes
Message 5 of 15

manasi4532
Enthusiast
Enthusiast

Thank you for help .

0 Likes
Message 6 of 15

manasi4532
Enthusiast
Enthusiast

I have a problem. Some parts are not working.

0 Likes
Message 7 of 15

EnM4st3r
Advocate
Advocate

when you zoom in you can see that these lines and circles are acutually not touching each other

EnM4st3r_0-1718861745732.png

 

0 Likes
Message 8 of 15

manasi4532
Enthusiast
Enthusiast

Can we adjust it to choose places that are close to each other?

0 Likes
Message 9 of 15

EnM4st3r
Advocate
Advocate

dont know if there is a easy way for that. maybe start a new post?

Message 10 of 15

EnM4st3r
Advocate
Advocate

one could possibly use modifier to extend one entity but maybe this will result in always 2 intersection points so idk

Message 11 of 15

Kent1Cooper
Consultant
Consultant

@manasi4532 wrote:

Is there a way to delete specific objects that have circles attached to them? ....


Given that wording, I would do it by selecting the Lines [and if what you're looking for would always end at a Circle, other kinds of things -- Arcs, open-ended Polylines, etc.], not the Circles.  An (ssget) function using a little crossing window built around each end of a Line [etc.], and looking for Circles, would get around the ones that don't quite touch [you would need to decide on a fuzz distance].  Does that sound like it would do what you want?

Kent Cooper, AIA
0 Likes
Message 12 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

@manasi4532 wrote:

Is there a way to delete specific objects that have circles attached to them? ....


... I would do it by selecting the Lines [and ... other kinds of things -- Arcs, open-ended Polylines, etc.], not the Circles.  An (ssget) function using a little crossing window built around each end ... would get around the ones that don't quite touch [you would need to decide on a fuzz distance].  ....


For example, this worked in your sample drawing, including when I replaced a few of the connecting Lines with Arcs or open-ended Polylines/Splines/Ellipses.  I used a diagonal fuzz distance [for looking for Circles at open ends] of 0.1 units, which seemed appropriate for your drawing, but you can edit that.

(vl-load-com)
(defun C:DOEC ; = Delte Objects Ending at Circles [and the Circles]
  (/ getcirc ss delss n ent)
  (defun getcirc (pt)
    (ssget "_c" (polar pt (* pi 1.25) 0.1) (polar pt (/ pi 4) 0.1) '((0 . "CIRCLE")))
      ;; EDIT the 0.1 for crossing-window diagonal fuzz distance
  ); defun
  (if
    (setq ss
      (ssget "_:L" ; on unlocked Layer(s) only
        (list
          '(-4 . "<OR")
            '(0 . "LINE,ARC"); any [always open-ended]
            '(-4 . "<AND"); Pline or Spline not closed
              '(0 . "LWPOLYLINE,SPLINE") '(-4 . "<NOT") '(-4 . "&") '(70 . 1) '(-4 . "NOT>")
            '(-4 . "AND>")
            '(-4 . "<AND"); Ellipse not closed
              '(0 . "ELLIPSE")
              '(-4 . "<NOT") '(-4 . "<AND") '(41 . 0.0) (cons 42 (* pi 2)) '(-4 . "AND>") '(-4 . "NOT>")
            '(-4 . "AND>")
          '(-4 . "OR>")
        ); list
      ); ssget
    ); setq
    (progn ; then
      (setq delss (ssadd)); initially empty
      (repeat (setq n (sslength ss)) ; then
        (setq ent (ssname ss (setq n (1- n))))
        (foreach end (list (vlax-curve-getStartPoint ent) (vlax-curve-getEndPoint ent))
          (if (setq ss2 (getcirc end))
            (progn (ssadd ent delss) (ssadd (ssname ss2 0) delss)) 
          ); if
        ); foreach
      ); repeat
      (if (> (sslength delss) 0)
        (command "_.erase" delss ""); then
        (prompt "\nNo Circle(s) found at ends of selected object(s)."); else
      ); if
    ); progn
    (prompt "\nNo open-ended object(s) selected."); else
  ); if
  (prin1)
)

 

Kent Cooper, AIA
0 Likes
Message 13 of 15

manasi4532
Enthusiast
Enthusiast

Thank you very much for your help. If I want to delete only the lines and circle that are close to the circle, how can I modify the command?

0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant

@manasi4532 wrote:

Thank you very much for your help. If I want to delete only the lines and circle that are close to the circle, how can I modify the command?


I'm not sure what you mean by "the lines and circle that are close to the circle."  Would you have Circles close to other Circles, without linking Lines?  Give another example drawing with before and after, including both situations where things should be deleted and some that should not be deleted.

Kent Cooper, AIA
0 Likes
Message 15 of 15

manasi4532
Enthusiast
Enthusiast

The command works fine. I forgot to set polyline to close so it caused the command to delete the polyline. Now I changed the setting and fixed it. Thankyou somuch

0 Likes