Jump to content

Gap CROSSING Lines


barristann

Recommended Posts

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)
      )
    )
  )
)

Link to comment
Share on other sites

Thanks for replying devitg. For example, if I choose both Yellow Lines as the Cutter

image.thumb.png.d8c39862f0356c1a8576fce66992cc4d.png

Then this is what happen, it also cut the 2 Red Lines on the Left that are only Touching

image.thumb.png.fd98715f45e82d380ec8a6dec6c92c4b.png

Is it possible to modify this so that they only cut the 2 Red Lines on the Right that are Crossing?

image.thumb.png.ba4d307a4cb0a403bb58b005f99e71d6.png

 

Thank you

Edited by barristann
Link to comment
Share on other sites

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 by devitg
add comment
Link to comment
Share on other sites

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 

 

image.png.05e57aeb25cdfbd9347764be54c12244.png 

 

Link to comment
Share on other sites

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 by marko_ribar
Link to comment
Share on other sites

Hi marko. They only want those that are crossings to be gapped. Those that are touching can stay connected (not gapped) .

Link to comment
Share on other sites

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 by marko_ribar
  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by BIGAL
  • Like 1
Link to comment
Share on other sites

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"

image.thumb.png.f27eb610bef9cef658ddd60327b658e7.png

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

image.thumb.png.6ac29681948e948e1140e72fcfe5250d.png

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 by barristann
Link to comment
Share on other sites

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

 

 

  • Like 1
Link to comment
Share on other sites

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 by Tsuky
Code updated
  • Like 1
Link to comment
Share on other sites

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 by barristann
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...