Exchange Forum > AutoLISP and Visual LISP
Break a Series of Lines, Intersect with another Line. (Help)
Break a Series of Lines, Intersect with another Line. (Help)

#1

Theodorus Winata
Join Date:
11-15-2007
J Briggs,
Please help fix the program. It has to break a series of lines, intersect with another line. Broken lines will offset based on user input.
Thanks,
Theodorus Winata
Code:
; BG.LSP - breaks line at intersections
; offset broken line to create gap
; at intersections
(defun c:bg2 ( / ss point echo)
  (setq snap (getvar "osmode"))
  (setq echo (getvar "cmdecho"))
  (setq olderr *error*)
  (setq *error* break_error)
  (setvar "cmdecho" 0)
  ;;------- get offset info ------------
  (if (not Off_Def)
     (progn
        (initget 1)
        (setq L_Off (getdist "\nEnter offset for broken line: "))
     )
        (setq L_Off (getdist (strcat "\nEnter offset for broken lines <" (rtos Off_Def) ">: ")))
  )
  (if (not L_Off) (setq L_Off Off_Def))
  (setq Off_Def L_Off)   
  ;;--------------------------
  (while (not ss)
    (princ "\nSelect lines to break: ")
    (setq ss (ssget))
    ;(setq ss (ssget "\nSelect lines to break: "))
  );while
  (setvar "osmode" 32)
  (while (not point)
    (setq point
    (osnap (getpoint "\nSelect intersections to break at: ") "int"))
  );while
  (setq Num 0)
  (setq Ssl (sslength ss))
  (repeat Ssl
    (setq Ssn (ssname ss Num))
    (setq El (entget Ssn)) 
    (setvar "osmode" 0) 
    (command "break" ss "f" point "@")
  ;;------code for offset lines-----------
    (setq EndPt1 (cdr (assoc 10 El)))
    (setq Line2 (entlast))
    (setq Line2_Dat (entget Line2))
    (setq EndPt2 (cdr (assoc 11 Line2_Dat)))
    (setq LineAng (angle EndPt1 EndPt2))
    (setq L1_pt2 (polar EndPt1 LineAng (- (distance EndPt1 Point) L_Off)))
    (setq L2_pt1 (polar EndPt1 LineAng (+ (distance EndPt1 Point) L_Off)))
    (setq El (subst (cons 11 L1_pt2) (assoc 11 El) El))
    (entmod El)
    (setq Line2_Dat (subst (cons 10 L2_pt1) (assoc 10 Line2_Dat) Line2_Dat))
    (entmod Line2_Dat)
    (setq Num (1+ Num))
  );repeat
   ;;--------------------------
  (setvar "osmode" snap)
  (setvar "cmdecho" echo)
  (setq *error* olderr)
  (princ)
)
(defun break_error (msg)
  (princ (strcat "\nError: " msg))
  (setvar "osmode" snap)
  (setvar "cmdecho" 1)
  (setq *error* olderr) 
  (princ)
)
Break a Series of Lines, Intersect with another Line. (Help)

#2

J Briggs
Join Date:
07-25-2007
Hi Theodorus,
This may fix part of your program. It works, but we may need to revise it some more. The only thing I found is that the "break" command is expecting a point not an entity name. We may need to adjust that initial point to be one of the endpoints instead of the intersecting point, because the "break" command may pick the wrong line sometimes.
Code:
(command "break" point "f" point "@")
Break a Series of Lines, Intersect with another Line. (Help)

#3

Theodorus Winata
Join Date:
11-15-2007
J Briggs,
The program hasn't worked, yet. Please run again and show me how to fix it.
 
Thanks,
Theodorus Winata
Break a Series of Lines, Intersect with another Line. (Help)

#4

J Briggs
Join Date:
07-25-2007
Hi Theodorus,
I found a solution that may work with the "break" command. Here are the changes I made.
Code:
(setq Pt10 (cdr (assoc 10 El)))
(setvar "osmode" 0)
(command "break" Pt10 "f" point "@")
I tested it, and it seems to work as planned. Here is a screen clip of when I ran it on the first two intersections on the screen.



Attachments  BG3.lsp  
Break a Series of Lines, Intersect with another Line. (Help)

#5

Theodorus Winata
Join Date:
11-15-2007
J Briggs,
You are getting there, but not quite what intended. I attach BG3.pdf for better what is intended.
 
Thanks,
Theodorus Winata

Attachments  BG3.pdf  
Break a Series of Lines, Intersect with another Line. (Help)

#6

J Briggs
Join Date:
07-25-2007
Theodorus,
This version you select a main break line first. Then select all the lines you want to break away from the main break line. It works faster because you do not have to select any intersections to break from.
Quote:
Command: BG4 
Enter offset for broken lines <0.750>: .5 
Select line to use for main break line: 
Select lines to break: 
Select objects: Specify opposite corner: 70 found



Attachments  BG4.lsp  
Break a Series of Lines, Intersect with another Line. (Help)

#7

Theodorus Winata
Join Date:
11-15-2007
J Briggs,
Well done. Thanks so much for your help, you cracked the code which puzzled me for a while.
 
Regards,
Theodorus Winata