LISP to Break Objects at any Intersection

LISP to Break Objects at any Intersection

andelo523
Enthusiast Enthusiast
8,805 Views
7 Replies
Message 1 of 8

LISP to Break Objects at any Intersection

andelo523
Enthusiast
Enthusiast

Hello everyone,

 

I need a LISP which will Break an Object (most likely a Line) on any Intersection Point which it's crossing (with no Gap). I've found allready something on the Net in that Direction, but unfortunately it doesn't work with intersection Points on Blocks, and that is mostly the Situation that I'm working with. I've put an Example in the Attachment where you can see my situation, and the situation that I need to have (EDIT: For some reason i can't put an Attachment in the Post Smiley Sad). In the moment I'm doing this all by Hand, and it's a total time waster.

 

Since I don't know how LISP programing works, can anyone please program me that kind of LISP? It would be very helpful.

Thanks in Advance!

0 Likes
Accepted solutions (1)
8,806 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

Post some typical example dwg with states before and after.

You probably found the popular CAB's BreakObjects.lsp, right? 

How much mass operation that would be? 

 

Upload it somewhere on a public cloud and post just a link. (I think the newbies with less than 5? posts can't attach files... BTW Welcome to the community!)

0 Likes
Message 3 of 8

andelo523
Enthusiast
Enthusiast

I've uploaded an Example on Wetransfer now, Here is the Link: https://we.tl/t-ZFLl0K8aXH

 

Yes, it was at CAB's. It functions really ok, but in the End I don't need so much Funtions in one LISP, and the second Issue is the Block story.

For me it would be more of a every day function that would come in handy, but it sure is a lot of work for now.

 

And thanks for the welcome! Smiley Happy

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant

Try this quick one if that works for you. This still requires CAB's routine loaded !!! - best if you copy-paste this into BreakObjects22.lsp file as another function... 

 

(defun c:BreakWithBlock ( / ss ss1 ss2)

  (prompt "\n***  Select BLOCK to break with:  ***")
  (if (setq ss (ssget "_+.:E:S" '((0 . "INSERT"))))
    (progn
      (command "_.COPY" ss "" "_non" '(0 0 0) "_non" '(0 0 0))
      (initcommandversion)
      (command "_.EXPLODE" ss "")
      (setq ss (ssget "_P"))
      (setq ss2 (ssget "_P" '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
       (not (prompt "\n***  Select objects to break:  ***"))
      (setq ss1 (ssget  "_+.:E:S" '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
      (break_with ss1 ss2 nil 0)
      (command "_.ERASE" ss "")
      ))
  (princ)
  )

If you want to allow multiple selection, just erase following: "_+.:E:S" either for blocks selection or line.

0 Likes
Message 5 of 8

andelo523
Enthusiast
Enthusiast

I've combined that code with the CAB routine, but it still got Issues. For example, it breaks the Line only on every second Intersection. Can this Function be made to only select the Line (or multiple Lines), and then it does the breaking automaticly on every Intersection, regardless if it's a Block or another Line, Circle or Whatever?

 

EDIT: I figured out that it broke the Line on every second Intersection because I have a Block in a Block. Could this be fixed too, that he uses all Levels of the Block instead of just the first one?

0 Likes
Message 6 of 8

Luís Augusto
Advocate
Advocate

Take a look at Lee Mac's code, you may have the answer to suit your code.

 

http://www.lee-mac.com/autoblockbreak.html

 

abb.gif

0 Likes
Message 7 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Then something like this. It won't be super fast but could make a job done. Still needs to be added to cab's.

 

(defun c:BreakWithBlocks ( / ssi ssb sse ss1 ss2 enlast enl prm)

  (command "_.undo" "_begin")
  (setq cmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  
  (if (and (princ "\n***  Select BLOCK to break with:  ***")
	   (setq ssi (ssget "_:L" '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE,INSERT"))))
	   )

    (progn
      (setq enlast (entlast))
      (command "_.COPY" ssi "" "_non" '(0 0 0) "_non" '(0 0 0)) ; copy all selected objs, blocks would be exploded
      								; the copies (or exploded ents of blocks) would ents to break with
      (setq sse (ssadd)
	    ssb (ssadd)
	    enl enlast)
      (while (setq enl (entnext enl))
	(ssadd enl (if (= "INSERT" (cdr (assoc 0 (entget enl)))) ; sorts all new objs to 
		     ssb					 ; ss blocks
		     sse)))					 ; ss another ents

      (while ssb						 ; blocks either for previous sort or from the explode
	(initcommandversion)
	(command "_.EXPLODE" ssb "")
	(setq ssb (ssget "_P" '((0 . "INSERT")))))		 ; if there is unexplodable block the explode returns empty ss

      (setq sse (ssadd)
	    ssb (ssadd)
	    enl enlast)
      (while (setq enl (entnext enl))				
	(ssadd enl (if (= "INSERT" (cdr (assoc 0 (entget enl)))) ; sort all new objs again to 
		     ssb					 ; unexplodable blocks
		     sse)))					 ; other ents

      (if (> (sslength sse) 0)
	(progn
	  (prompt "\n***  Select objects to break:  ***")
	  (setq ss1 (ssget "_:L" '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))))
	  
      (if (and ss1 (> (sslength sse) 0))
	(break_with ss1 sse nil 0))

      (if (> (sslength ssb) 0)
	(progn
	  (setq prm (strcat "\nFound " (itoa (sslength ssb)) " unexplodable blocks!"))
	  (command "_.ERASE" ssb "")))
      (if (> (sslength sse) 0)
	(command "_.ERASE" sse ""))))

  (setvar "CMDECHO" cmd)
  (command "_.undo" "_end")
  (if prm (princ prm))
  (princ)
  )

 

0 Likes
Message 8 of 8

andelo523
Enthusiast
Enthusiast

I've tried the Code now, and everything seem to work, exept that it's not very fast, but at least you can select all that you need at once. I guess because of the complicated calculation process that it cannot be speeded up, so I'll take it as the end Solution.

 

Thank you very much, you helped me a lot with this one! Smiley Very Happy

Best Regards!

0 Likes