barristann Posted April 8, 2023 Posted April 8, 2023 Hi all, is it possible to modify this to only Gap other Lines that are CROSSING (the selected Lines). The below will do this if they are just Touching, I need them to actually Cross one another ;;;;;;;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/break-multiple-polylines-with-each-other/td-p/11580876/page/2 (defun c:bmcut (/ _pts d cutter e pts pts2 p1 p2) (defun _pts (ent) (mapcar 'cdr (vl-remove-if-not '(lambda (x) (member (car x) '(10 11))) ent))) (setq d (getdist "\nEnter Gap distance: ")) (princ "\nSelect Cutter lines:") (setq cutter (ssget (setq fl '((-4 . "<OR") (-4 . "<AND") (0 . "LWPOLYLINE") (90 . 2) (-4 . "AND>") (0 . "LINE") (-4 . "OR>") )) ) ) (repeat (setq i (sslength cutter)) (setq e (ssname cutter (setq i (1- i)))) (setq pts (_pts (entget e))) (if (and (setq cut-ee (ssget "_F" pts fl)) (ssdel e cut-ee) ) (repeat (setq n (sslength cut-ee)) (Setq en (ssname cut-ee (setq n (1- n)))) (setq pts2 (_pts (entget en))) (setq bpt (inters (Car pts) (cadr pts) (car pts2) (cadr pts2))) (setq p1 (polar bpt (angle (car pts2) (cadr pts2)) (* d 0.5))) (setq p2 (polar bpt (angle (cadr pts2) (car pts2)) (* d 0.5))) (command "_break" en "_non" p1 "_non" p2) ) ) ) ) Quote
devitg Posted April 8, 2023 Posted April 8, 2023 1 hour ago, barristann said: modify this to only Gap other Lines that are CROSSING (the selected Lines) @barristann Please upload an Image Quote
barristann Posted April 8, 2023 Author Posted April 8, 2023 (edited) Thanks for replying devitg. For example, if I choose both Yellow Lines as the Cutter Then this is what happen, it also cut the 2 Red Lines on the Left that are only Touching Is it possible to modify this so that they only cut the 2 Red Lines on the Right that are Crossing? Thank you Edited April 8, 2023 by barristann Quote
devitg Posted April 9, 2023 Posted April 9, 2023 (edited) 3 hours ago, barristann said: For example, if I choose both Yellow Lines as the Cutter @barristann Find attached your image as dwg . I put cutting lines on YELLOW layer, and cut lines on RED layer . It will be a good way to make selections . Please add or change as you need to . Example the GAP distance to cut . Please upload it in ACAD version 2019 , as I have not 2020 Also state the gap distance, and if they are lines and or polylines . Please draw some more representatives entities. barristan cut crosing lines -01.dwg Edited April 9, 2023 by devitg add comment Quote
barristann Posted April 9, 2023 Author Posted April 9, 2023 Hi devitg. Gap distance = 4, they are lines. barristan cut crosing lines - modified.dwg Quote
devitg Posted April 9, 2023 Posted April 9, 2023 12 hours ago, barristann said: they are lines. @barristann, please clear it Quote
barristann Posted April 9, 2023 Author Posted April 9, 2023 Sorry about that. I've deleted the image. I hope this is okay now. Please take a look devitg. barristan cut crosing lines - mod 2.dwg Quote
devitg Posted April 9, 2023 Posted April 9, 2023 6 minutes ago, barristann said: I hope this is okay now @barristann No. it are all lines , no crossing the yellow line . Please make a new dwg , use this one as template, in the real case Quote
barristann Posted April 9, 2023 Author Posted April 9, 2023 The Top is Before the cutting, the Bottom is the wanted result. I hope this is better, devitg. barristan cut crosing lines - mod 4.dwg Quote
marko_ribar Posted April 9, 2023 Posted April 9, 2023 (edited) Why do you need this... I am curious, why don't explain background behind this task, maybe someone may open your vision more clearly - for me I'd be pleased and with both gappings and touchings and crossings... Edited April 9, 2023 by marko_ribar Quote
barristann Posted April 9, 2023 Author Posted April 9, 2023 Hi marko. They only want those that are crossings to be gapped. Those that are touching can stay connected (not gapped) . Quote
marko_ribar Posted April 9, 2023 Posted April 9, 2023 (edited) Not tested... (defun c:cross+cut-lins ( / process ss gap i e lay laylst slay sss ch sscross sscut ) (defun process ( sscross sscut gap / p1e p2e p1c p2c ip p1 p2 ) (foreach e (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex sscross))) (foreach c (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex sscut))) (setq p1e (cdr (assoc 10 (entget e))) p2e (cdr (assoc 11 (entget e)))) (setq p1c (cdr (assoc 10 (entget c))) p2c (cdr (assoc 11 (entget c)))) (if (and (setq ip (inters p1e p2e p1c p2c)) (not (or (equal p1e ip 1e-3) (equal p2e ip 1e-3) ) ) ) (progn (setq p1 (polar ip (angle ip p1e) (/ gap 2.0))) (setq p2 (polar ip (angle ip p2e) (/ gap 2.0))) (if command-s (command-s "_.BREAK" e "_non" p1 "_non" p2) (vl-cmdf "_.BREAK" e "_non" p1 "_non" p2) ) ) ) ) ) ) (if (and (setq ss (ssget "_:L" (list (cons 0 "LINE")))) (not (initget 5)) (setq gap (getdist "\nPick or specify gap : ")) ) (progn (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i)))) (setq lay (cdr (assoc 8 (entget e)))) (if (not (vl-position lay laylst)) (setq laylst (cons lay laylst)) ) ) (foreach lay laylst (sssetfirst nil ss) (setq slay (ssget "_I" (list (cons 8 lay)))) (setq sss (cons slay sss)) ) (if (= 2 (length sss)) (progn (sssetfirst nil (car sss)) (initget "Yes No") (setq ch (cond ( (getkword "\nAre highlighted lines crossings or cutting lines [Yes / No] <Yes> : ") ) ( "Yes" ))) (sssetfirst) (if (= ch "Yes") (progn (setq sscross (car sss)) (setq sscut (cadr sss)) (process sscross sscut gap) ) (progn (setq sscut (car sss)) (setq sscross (cadr sss)) (process sscross sscut gap) ) ) ) ) ) ) (princ) ) HTH. M.R. Edited April 10, 2023 by marko_ribar 1 Quote
barristann Posted April 9, 2023 Author Posted April 9, 2023 It's saying there's a syntax error, marko_ribar Quote
marko_ribar Posted April 9, 2023 Posted April 9, 2023 Founded few lacks and tested... No syntax error on my side... Regards, M.R. Quote
barristann Posted April 9, 2023 Author Posted April 9, 2023 I've tried it again but still getting ; error: syntax error I'll continue to try and figure out why it's not working for me. Thank you for your help, marko_ribar. Quote
BIGAL Posted April 9, 2023 Posted April 9, 2023 (edited) Like others doing something, there is an alternative to breaking the lines and that is to use a wipeout and play with draw order. The advantage is that the line is not broken but appears to to be. Can do something if that is helpful. Another attempt, select cut P/lines, then select P/lines to break. ; Break p/lines at intersection ; By AlanH April 2023 (defun c:wow ( / x y ss1 ss2 obj1 obj2 obj intpt inpts) (setq oldsnap (getvar 'osmode)) (prompt "Select cut lines ") (setq ss1 (ssget '((0 . "LWPOLYLINE,LINE")))) (princ "\n") (prompt "Select break lines ") (setq ss2 (ssget '((0 . "LWPOLYLINE,LINE")))) (setvar 'osmode 0) (repeat (setq x (sslength ss1)) (setq obj1 (vlax-ename->vla-object (ssname ss1 (setq x (- x 1))))) (repeat (setq y (sslength ss2)) (setq obj2 (vlax-ename->vla-object (ssname ss2 (setq y (- y 1))))) (setq intpt (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity)) (if intpt (progn (command "circle" intpt 4) ; can add a set gap (setq obj (vlax-ename->vla-object (entlast))) (setq intpts (vlax-invoke obj2 'intersectWith obj acExtendThisEntity)) (entdel (entlast)) (command "break" (list (car intpts)(cadr intpts)) (list (nth 3 intpts)(nth 4 intpts))) ) ) ) ) (setvar 'osmode oldsnap) (princ) ) (c:wow) Edited April 10, 2023 by BIGAL 1 Quote
barristann Posted April 10, 2023 Author Posted April 10, 2023 (edited) Thank you BIGAL, your codes are the best so far. I'll definitely use them. I just have to be careful with my selection. For example 1) If I also accidentally select the 2 Red Lines on the Left as "Select break lines", then nothing will happen - 2 Yellow for "Select cut lines" - 4 Red for "Select break lines" Is it possible to ignore the 2 Left Red Lines (if I accidentally select them) but still process the 2 Right Red Lines? 2) Also, if I SWITCH my selections - 4 Red for "Select cut lines" - 2 Yellow for "Select break lines", this is the result The 2 Left Red is gapping the Yellow, even though it's just touching Anyways, it works if I'm careful about my selection, I was hoping to full automation. Again, I'm still very grateful for your codes, BIGAL. I'll be using them since they're best I've seen so far. Thank you BIGAL. Edited April 10, 2023 by barristann Quote
BIGAL Posted April 10, 2023 Posted April 10, 2023 I have always taken approach of the end user having some skill and understanding what the code is doing, hence a simplified answer. You could add a UNDO back setting so if done wrong will undo all changes. Getting a full automation of If and Buts is extremely difficult some times and as code is provided free not on the high To do List. The code takes like 2 seconds to use with a bit of care so still way quicker than a Manual Break. At some stage must have time for a sip of coffee. I am glad though its working. (command "._undo" "_mark") ..... code (command "._undo" "_end") if you type UNDO then B will undo back to mark 1 Quote
Tsuky Posted April 10, 2023 Posted April 10, 2023 (edited) Hi, Try this! (defun c:cut_line ( / js_all js_h js_v tmp_js tmp_lst lst_exth lst_extv nb_all name_ent dxf_ent dxf_10 dxf_11 gap nb_v lst_pt_brk v_name dxf_entv lst_int lst_pt_make) (princ "\nSelect lines to cut vertical or horizontal lines: ") (setq js_all (ssget '((0 . "LINE"))) js_h (ssadd) js_v (ssadd) lst_exth nil lst_extv nil) (cond (js_all (repeat (setq nb_all (sslength js_all)) (setq name_ent (ssname js_all (setq nb_all (1- nb_all))) dxf_ent (entget name_ent) dxf_10 (cdr (assoc 10 dxf_ent)) dxf_11 (cdr (assoc 11 dxf_ent)) ) (cond ((equal (cadr (trans dxf_10 0 1)) (cadr (trans dxf_11 0 1)) 1E-5) (setq js_h (ssadd name_ent js_h) lst_exth (cons (list dxf_10 dxf_11) lst_exth)) ) ((equal (car (trans dxf_10 0 1)) (car (trans dxf_11 0 1)) 1E-5) (setq js_v (ssadd name_ent js_v) lst_extv (cons (list dxf_10 dxf_11) lst_extv)) ) ) ) ) ) (cond ((and js_h js_v) (initget "Vertical Horizontal") (if (eq (getkword "\nCut with [Vertical/Horizontal] lines? <Horizontal>: ") "Vertical") (setq tmp_js js_h tmp_lst lst_exth js_h js_v lst_exth lst_extv js_v tmp_js lst_extv tmp_lst ) (setq tmp_js nil tmp_lst nil) ) (initget 4) (setq gap (getreal (strcat "\nEnter the gap? <" (rtos (getvar "DIMEXO")) ">: "))) (if gap (setvar "DIMEXO" gap)) (repeat (setq nb_v (sslength js_v)) (setq lst_pt_brk nil v_name (ssname js_v (setq nb_v (1- nb_v))) dxf_entv (entget v_name) dxf_10 (cdr (assoc 10 dxf_entv)) dxf_11 (cdr (assoc 11 dxf_entv)) lst_int (vl-remove nil (mapcar '(lambda (x) (inters dxf_10 dxf_11 (car x) (cadr x) T)) lst_exth)) ) (foreach xint lst_int (if (member xint (apply 'append (if tmp_lst lst_exth lst_extv))) (setq lst_int (vl-remove xint lst_int)) ) ) (cond (lst_int (mapcar '(lambda (el) (setq lst_pt_brk (cons (polar el (+ (atan (/ (cadr (getvar "UCSXDIR")) (car (getvar "UCSXDIR")))) (if tmp_js 0 (* pi 0.5))) (getvar "DIMEXO" )) (cons (polar el (+ (atan (/ (cadr (getvar "UCSXDIR")) (car (getvar "UCSXDIR")))) (if tmp_js pi (* pi 1.5))) (getvar "DIMEXO" )) lst_pt_brk ) ) ) ) lst_int ) (setq lst_pt_make (vl-sort (cons dxf_11 (cons dxf_10 lst_pt_brk)) '(lambda (e1 e2) (if tmp_js (< (car e1) (car e2)) (< (cadr e1) (cadr e2)))))) (while lst_pt_make (entmake (list (assoc 0 dxf_entv) '(100 . "AcDbEntity") (assoc 67 dxf_entv) (assoc 410 dxf_entv) (assoc 8 dxf_entv) (if (assoc 62 dxf_entv) (assoc 62 dxf_entv) '(62 . 256)) (if (assoc 6 dxf_entv) (assoc 6 dxf_entv) '(6 . "BYLAYER")) (if (assoc 48 dxf_entv) (assoc 48 dxf_entv) '(48 . 1.0)) (if (assoc 370 dxf_entv) (assoc 370 dxf_entv) '(370 . -1)) '(100 . "AcDbLine") (cons 10 (car lst_pt_make)) (cons 11 (cadr lst_pt_make)) (assoc 210 dxf_entv) ) ) (setq lst_pt_make (cddr lst_pt_make)) ) (entdel v_name) ) ) ) ) ) (prin1) ) Edited April 10, 2023 by Tsuky Code updated 1 Quote
barristann Posted April 10, 2023 Author Posted April 10, 2023 (edited) I agree BIGAL. Tsuky, your codes work! It ignores lines that are just touching. Thank you Tsuky! Now, is it possible to update this so that: 1) if we select some Horizontal Lines as the Cutters, these will gap ALL Intersecting Vertical Lines on screen? (So we don't need to select the Vertical Lines) 2) Vice versa. if we select some Vertical Lines as the Cutters, these will gap ALL Intersecting Horizontal Lines on screen? Sorry If I'm asking too much. If it's not possible then It's okay. Your codes still work great Tsuky. Thanks again. Edited April 10, 2023 by barristann Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.