Check number range for Overlap

Check number range for Overlap

cherrygate
Enthusiast Enthusiast
2,699 Views
29 Replies
Message 1 of 30

Check number range for Overlap

cherrygate
Enthusiast
Enthusiast

Hi!

 

I have a block attribute that has a number range in it (example: 12-24) and another attribute with an identifier(example: A1). I need a script that will get that block attribute from all of a certain block and then make sure there are no overlapping numbers and if there are tell me a list of which identifiers have overlap.

 

For example if I have: 

Identifier: A1 Range: 12-24

Identifier: B1 Range: 24-48

Identifier: C1 Range: 49-62

Identifier: D1 Range: 1-13

Identifier: E1 Range: 20-30



The script would ideally output something like: “B1 + C1”, “D1 + A1”, “E1 + A1 + B1

Either a popup window or right in the command line area is fine. If no overlap found just output something like "All OK"




Here is a CAD file with this same example: https://drive.google.com/file/d/1L2fKoJDU96L03fvKjVPCqxl693ldDdPT/view?usp=sharing



Any help would be greatly appreciated, there are typically 100s of these per job and I have been checking them manually which takes me way too long. Thank you!

0 Likes
Accepted solutions (3)
2,700 Views
29 Replies
Replies (29)
Message 2 of 30

marko_ribar
Advisor
Advisor

Quickly written...

 

(defun c:overlapchk ( / unique rangenums ss i bl atts bll n a b x r )

  (vl-load-com)

  (defun unique ( l )
    (if l (cons (car l) (unique (vl-remove (car l) l))))
  )

  (defun rangenums ( str / a b )
    (setq a (substr str 1 (vl-string-search "-" str)))
    (setq b (substr str (+ (vl-string-search "-" str) 2)))
    (list (atoi a) (atoi b))
  )

  (prompt "\nSelect attributed blocks...")
  (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
    (progn
      (repeat (setq i (sslength ss))
        (setq bl (ssname ss (setq i (1- i))))
        (setq atts (vlax-invoke (setq bl (vlax-ename->vla-object bl)) 'getattributes))
        (foreach att atts  
          (if (= (vla-get-tagstring att) "TERM_TAG")
            (setq a (vla-get-textstring att))
          )
          (if (= (vla-get-tagstring att) "FIBERS_USED")
            (setq b (vla-get-textstring att))
          )
        )
        (setq bll (cons (list a b) bll))
      )
      (setq bll (unique bll))
      (foreach bl bll
        (setq a (car (setq n (rangenums (cadr bl)))))
        (setq b (cadr n))
        (setq x (vl-remove-if-not '(lambda ( x / n ) (setq n (rangenums (cadr x))) (or (< a (car n) b) (< a (cadr n) b))) (vl-remove bl bll)))
        (if x
          (setq r (cons (strcat (car bl) "+" (vl-string-right-trim "+" (apply 'strcat (mapcar '(lambda ( q ) (strcat (car q) "+")) x)))) r))
        )
      )
      (if r
        (princ r)
        (princ "\nAll OK...")
      )
    )
  )
  (princ)
)

HTH. M.R.

 

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 30

cherrygate
Enthusiast
Enthusiast

Thank you for that quick response. This works almost perfectly, just 1 minor issue I saw.

 

On the example file I had sent, the script I ran gave one group that didn't overlap with all of them (Output was: A1+E1+D1 B1+E1 D1+A1 E1+B1+A1)

 

A1 overlapped E1 and D1 but D1 and E1 don't overlap each other. So ideally the script would output A1+E1 and A1+D1 separately if that's possible. But also still output groups when 3 or more do overlap(Like it did for E1+B1+A1)

 

Also, if it is possible to add a character to separate the entries so it is a little easier to read that would be super helpful. (Maybe a "," or "|")

 

 

Thanks again for your help, I highly appreciate it. This is a huge time saver

0 Likes
Message 4 of 30

marko_ribar
Advisor
Advisor

Even with this simple DWG, it's not so easy to correclty analyze real situation... Check now what is output of LISP... I think that return is good, it just is not like you described...

 

(defun c:overlapchk ( / unique rangenums process ss i bl atts bll blll n a b x r )

  (vl-load-com)

  (defun unique ( l )
    (if l (cons (car l) (unique (vl-remove (car l) l))))
  )

  (defun rangenums ( str / a b )
    (setq a (substr str 1 (vl-string-search "-" str)))
    (setq b (substr str (+ (vl-string-search "-" str) 2)))
    (list (atoi a) (atoi b))
  )

  (defun process ( q )
    (if q
      (progn
        (setq a (car (setq n (rangenums (cadr q)))))
        (setq b (cadr n))
        (setq x (vl-remove-if-not '(lambda ( x / n ) (setq n (rangenums (cadr x))) (or (< a (car n) b) (< a (cadr n) b))) (setq blll (vl-remove q blll))))
        (if x
          (strcat (car q) "+" (process (car x)))
          (car q)
        )
      )
    )
  )

  (prompt "\nSelect attributed blocks...")
  (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
    (progn
      (repeat (setq i (sslength ss))
        (setq bl (ssname ss (setq i (1- i))))
        (setq atts (vlax-invoke (setq bl (vlax-ename->vla-object bl)) 'getattributes))
        (foreach att atts  
          (if (= (vla-get-tagstring att) "TERM_TAG")
            (setq a (vla-get-textstring att))
          )
          (if (= (vla-get-tagstring att) "FIBERS_USED")
            (setq b (vla-get-textstring att))
          )
        )
        (setq bll (cons (list a b) bll))
      )
      (setq bll (unique bll))
      (foreach bl bll
        (setq blll bll)
        (setq a (car (setq n (rangenums (cadr bl)))))
        (setq b (cadr n))
        (setq x (vl-remove-if-not '(lambda ( x / n ) (setq n (rangenums (cadr x))) (or (< a (car n) b) (< a (cadr n) b))) (vl-remove bl bll)))
        (setq blll (vl-remove bl blll))
        (if x
          (foreach q x
            (setq r (cons (vl-string-right-trim "+" (strcat (car bl) "+" (process q))) r))
          )
        )
      )
      (if r
        (princ (vl-string-right-trim "," (apply 'strcat (mapcar '(lambda ( x ) (strcat x ",")) r))))
        (princ "\nAll OK...")
      )
    )
  )
  (princ)
)

HTH. M.R.

 

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 5 of 30

cherrygate
Enthusiast
Enthusiast

Thank you very much for another quick response.

 

This version of the scripts seems to return a bit different result than expected, the output for this one is: A1+D1, A1+E1+B1, B1+E1+A1+D1, D1+A1+E1+B1, E1+A1+D1, E1+B1

 

Some of the groupings seem to be better but than others are bit odd.

 

I appreciate your help, thank you.

0 Likes
Message 6 of 30

ronjonp
Mentor
Mentor

Another for fun 🙂

 

(defun c:foo (/ a b c mn mx n r s x)
  ;; RJP » 2021-06-10
  (cond	((setq s (ssget '((0 . "INSERT") (66 . 1))))
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (if (= 'str (type (setq a (vl-catch-all-apply 'getpropertyvalue (list e "TERM_TAG")))))
	     (setq r (cons a r))
	   )
	 )
	 (setq r (vl-sort r '(lambda (r j) (> r j))))
	 (while	(car r)
	   (setq a (substr (car r) 1 1))
	   (setq b (vl-remove-if-not '(lambda (x) (wcmatch a (substr x 1 1))) (setq r (cdr r))))
	   (setq n (mapcar '(lambda (x) (atof (substr x 2))) b))
	   (setq c (cons (list a (apply 'min n) (apply 'max n)) c))
	   (foreach e b (setq r (vl-remove e r)))
	 )
	 (while	(setq a (car c))
	   (setq mn (cadr a))
	   (setq mx (caddr a))
	   (setq r (vl-remove-if-not '(lambda (x) (or (<= mn (cadr x) mx) (<= mn (caddr x) mx))) c))
	   (foreach e r (setq c (vl-remove e c)))
	   (if (= (length r) 1)
	     (print (strcat (car a) " - OK :)"))
	     (print r)
	   )
	 )
	)
  )
  (princ)
)

 

0 Likes
Message 7 of 30

john.uhden
Mentor
Mentor
;; organize your list of ranges like...
(setq ranges
  (list
    '("A1" 12 24)
    '("B1" 24 48)
    '("C1" 49 62)
    '("D1" 1 13)
    '("E1" 20 30)
  )
)
;; Function to return ranges that contain a given value:
(defun @Anonymous (value / hits)
  (foreach range ranges
    (if (<= (nth 1 range) value (nth 2 range))
      (setq hits (cons (car range) hits))
    )
  )
  (reverse hits)
)



John F. Uhden

0 Likes
Message 8 of 30

pbejse
Mentor
Mentor

Are there duplicates? 

Different identifier , same values

Identifier: A1 Range: 12-24

Identifier: F1 Range: 12-24

or

Same identifier , different values

Identifier: A1 Range: 12-24

Identifier: A1 Range: 24-48

 

 

 

Message 9 of 30

pbejse
Mentor
Mentor

@cherrygate wrote:

...A1+D1, A1+E1+B1, B1+E1+A1+D1, D1+A1+E1+B1, E1+A1+D1, E1+B1

..

Some of the groupings seem to be better but than others are bit odd.

...


Joining the fun

(defun c:clash ( / _range low high ovl attbv blocks i lst )
;;		 pBe June 2021			;;;
(defun _range (n m l / ol )
	(while
	  (and n m (< (low n) (low m) (high n)))
		(setq ol (cons (strcat (car n)"+"(car m)) ol))	  	
		(setq n (list (car ol) (strcat (itoa (low n))"-" (itoa (high m))))
		        l (cdr l) m (car l) )
			       )
   (reverse ol)
)
  (setq low (lambda (s)(atoi (cadr s))))
  (setq high (lambda (s)
	   (atoi
	     (substr (cadr s) (+ 2 (vl-string-position 45 (cadr s))))
	   )
	 )
  )
  
  (if (setq blocks (ssget '((0 . "INSERT")(66 . 1))))
    (progn
	    (repeat (setq i (sslength blocks))
		(setq attbv (mapcar '(lambda (At)
				       (list (Vla-get-tagstring at)(Vla-get-textstring at)))
				       (Vlax-invoke (vlax-ename->vla-object
						      (ssname blocks (setq i (1- i)))) 'GetAttributes)))
	      (and 
		  (setq lst (Cons 
		       (mapcar '(lambda (tg)(cadr (assoc tg attbv)))
						 '("TERM_TAG" "FIBERS_USED")) lst))
		)
	      )
           	(setq lst (Vl-sort lst '(lambda (a b)(< (cadr a)(cadr b)))))
		(While  (setq a (car lst))
		      (setq b (Cadr lst))
			(if (setq f (_range a b (cdr lst))) (setq ovl (cons f ovl)))
			(setq lst (cdr lst))		
		)
      )
    (princ "\nNo valid blocks found")
    )
      (if ovl
	(print (substr (apply 'strcat (mapcar '(lambda (v)(strcat " | " v ))
					      (apply 'append (reverse ovl)))) 4))
	(Alert "All OK")
	)
  (princ)  
)

 

command: clash

"D1+A1 | D1+A1+E1 | D1+A1+E1+B1 | A1+E1 | A1+E1+B1 | E1+B1"

 

I'm getting almost similar values as @marko_ribar 

Can you confirm if this is correct and not odd as you described it on your post?

 

 

Message 10 of 30

cherrygate
Enthusiast
Enthusiast

Thank you very much for taking the time to try and help as well, I appreciate it.

 

This one seems to be the closest to what I was expecting to see. Ideally, it would be a bit less cluttered output and show the final groups of which values overlap. For example, the last output of your script "E1+B1" isn't necessary because it is already included in the A1+E1+B1 line of output if that makes sense? 

 

After looking closer at the example DWG I gave, I see I made an error in typing in some values for the example I had intended to give making this more confusing than it needs to be. 

 

 

 

 

Here is a cleaner example DWG: https://drive.google.com/file/d/1o3v_claLxm9oklYmvQNyzXRldOTFThRl/view?usp=sharing

 

The output of this one from your script is: "A1+D1 | A1+D1+B1 | D1+B1 | E1+G1"

 

It missed the number range that was identical (C1+F1) and gave some extra (A1+D1 & D1+B1 both of which are included in A1+D1+B1) but it also missed A1+H1 for a reason unknown to me. (I played around with this a bit more, and if I make H1 1-6 it misses even more combinations of overlaps which I don't understand)

 

Ideally, it would output this: A1+D1+B1 | A1+H1 | C1+F1 | E1+G1

 

 

Again, I really appreciate any help with this as this level of scripting is above my level of knowledge and doing these checks manually takes me hours per job I look at.

 

 

0 Likes
Message 11 of 30

marko_ribar
Advisor
Advisor

I've changed my version a little...

 

(defun c:overlapchk ( / unique rangenums process ss i bl atts bll blll n a b x r )

  (vl-load-com)

  (defun unique ( l )
    (if l (cons (car l) (unique (vl-remove (car l) l))))
  )

  (defun rangenums ( str / a b )
    (setq a (substr str 1 (vl-string-search "-" str)))
    (setq b (substr str (+ (vl-string-search "-" str) 2)))
    (list (atoi a) (atoi b))
  )

  (defun process ( q )
    (if q
      (progn
        (setq a (car (setq n (rangenums (cadr q)))))
        (setq b (cadr n))
        (setq x (vl-remove-if-not '(lambda ( x / n ) (setq n (rangenums (cadr x))) (or (<= a (car n) b) (<= a (cadr n) b))) (setq blll (vl-remove q blll))))
        (if x
          (strcat (car q) "+" (process (car x)))
          (car q)
        )
      )
    )
  )

  (prompt "\nSelect attributed blocks...")
  (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
    (progn
      (repeat (setq i (sslength ss))
        (setq bl (ssname ss (setq i (1- i))))
        (setq atts (vlax-invoke (setq bl (vlax-ename->vla-object bl)) 'getattributes))
        (foreach att atts  
          (if (= (vla-get-tagstring att) "TERM_TAG")
            (setq a (vla-get-textstring att))
          )
          (if (= (vla-get-tagstring att) "FIBERS_USED")
            (setq b (vla-get-textstring att))
          )
        )
        (setq bll (cons (list a b) bll))
      )
      (setq bll (unique bll))
      (foreach bl bll
        (setq a (car (setq n (rangenums (cadr bl)))))
        (setq b (cadr n))
        (setq x (vl-remove-if-not '(lambda ( x / n ) (setq n (rangenums (cadr x))) (or (<= a (car n) b) (<= a (cadr n) b))) (vl-remove bl bll)))
        (if x
          (foreach q x
            (setq blll bll)
            (setq blll (vl-remove bl blll))
            (setq r (cons (vl-string-right-trim "+" (strcat (car bl) "+" (process q))) r))
          )
        )
      )
      (if r
        (princ (vl-string-right-trim "," (apply 'strcat (mapcar '(lambda ( x ) (strcat x ",")) r))))
        (princ "\nAll OK...")
      )
    )
  )
  (princ)
)

This part :

      (foreach bl bll
        (setq blll bll)
        (setq a (car (setq n (rangenums (cadr bl)))))
        (setq b (cadr n))
        (setq x (vl-remove-if-not '(lambda ( x / n ) (setq n (rangenums (cadr x))) (or (< a (car n) b) (< a (cadr n) b))) (vl-remove bl bll)))
        (setq blll (vl-remove bl blll))
        (if x
          (foreach q x
            (setq r (cons (vl-string-right-trim "+" (strcat (car bl) "+" (process q))) r))
          )
        )
      )

Is now :

      (foreach bl bll
        (setq a (car (setq n (rangenums (cadr bl)))))
        (setq b (cadr n))
        (setq x (vl-remove-if-not '(lambda ( x / n ) (setq n (rangenums (cadr x))) (or (<= a (car n) b) (<= a (cadr n) b))) (vl-remove bl bll)))
        (if x
          (foreach q x
            (setq blll bll)
            (setq blll (vl-remove bl blll))
            (setq r (cons (vl-string-right-trim "+" (strcat (car bl) "+" (process q))) r))
          )
        )
      )

And I also changed signs (< a num b) into (<= a num b) in all places...

 

My output is :

G1+E1,F1+C1,E1+G1,D1+B1+A1+H1,D1+A1+B1,C1+F1,B1+D1+A1+H1,B1+A1+D1,A1+H1,A1+D1+B1,A1+B1+D1

That's with your new DWG...

 

I see that some things are repeating, but I thought better more than less info...

And BTW. if I was to remove duplicates, then which one is correct (to leave it and remove only wrong ones)???

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 12 of 30

pbejse
Mentor
Mentor

@cherrygate wrote:

.."E1+B1" isn't necessary because it is already included in the A1+E1+B1 line...



If that rule applies then on the first drawing example  should be

"D1+A1+E1+B1" <-- all the overlaps

 

This is what I got from your new example based on a modified code.

"A1+H1+D1+B1 | F1+C1 | E1+G1"  

 

Here's a breakdown

"A1+H1+D1+B1"
(("A1" "1-13") ("H1" "3-6") ("D1" "11-16") ("B1" "12-24")
"F1+C1"
("F1" "25-48") ("C1" "25-48")
"E1+G1"
("E1" "49-62") ("G1" "61-72"))

 

Can you confirm it that is the right result?

 

0 Likes
Message 13 of 30

ronjonp
Mentor
Mentor

Did you try my version ? Does not have the '+' formatting but conveys the same information.

*Edit .. now I see the range you're referring to in another attribute. I thought that the TERM_TAG was the att to tally.

Try this quick modification:

Returns this on your test-new.dwg.

(("A1" (1 13)) ("H1" (3 6)) ("D1" (11 16)) ("B1" (12 24)))
(("C1" (25 48)) ("F1" (25 48)))
(("E1" (49 62)) ("G1" (61 72)))

 

(defun c:foo (/ a b mn mx r r2 s)
  ;; RJP » 2021-06-11
  (cond
    ((setq s (ssget '((0 . "INSERT") (66 . 1))))
     (foreach e	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
       (if
	 (and (= 'str (type (setq a (vl-catch-all-apply 'getpropertyvalue (list e "TERM_TAG")))))
	      (= 'str (type (setq b (vl-catch-all-apply 'getpropertyvalue (list e "FIBERS_USED")))))
	 )
	  (setq r (cons (list a (read (vl-string-translate "-" " " (strcat "(" b ")")))) r))
       )
     )
     (setq r (vl-sort r '(lambda (r j) (< (caadr r) (caadr j)))))
     (while (setq a (car r))
       (setq mn (caadr a))
       (setq mx (cadadr a))
       (setq r2 (vl-remove-if-not '(lambda (x) (or (<= mn (caadr x) mx) (<= mn (cadadr x) mx))) r))
       (foreach e r2 (setq r (vl-remove e r)))
       (if (= (length r2) 1)
	 (princ (strcat "\n" (car a) " - OK :)"))
	 (print r2)
       )
     )
    )
  )
  (princ)
)

 

Message 14 of 30

cherrygate
Enthusiast
Enthusiast

@pbejse wrote:

@cherrygate wrote:

.."E1+B1" isn't necessary because it is already included in the A1+E1+B1 line...



If that rule applies then on the first drawing example  should be

"D1+A1+E1+B1" <-- all the overlaps

 

This is what I got from your new example based on a modified code.

"A1+H1+D1+B1 | F1+C1 | E1+G1"  

 

Here's a breakdown

"A1+H1+D1+B1"
(("A1" "1-13") ("H1" "3-6") ("D1" "11-16") ("B1" "12-24")
"F1+C1"
("F1" "25-48") ("C1" "25-48")
"E1+G1"
("E1" "49-62") ("G1" "61-72"))

 

Can you confirm it that is the right result?

 


This is extremely close to my desired result, with one exception being this:

 

"A1+H1+D1+B1" <- In this line, H1+A1 should be a separate entry from A1+D1+B1 since H1 only overlaps with A1.

 

 

With that being said, if this is the best result that can be achieved with AutoLISP then I would be ok with that result.

0 Likes
Message 15 of 30

pbejse
Mentor
Mentor
Accepted solution

@cherrygate wrote:

With that being said, if this is the best result that can be achieved with AutoLISP then I would be ok with that result.


😄 It's not that @cherrygate , I'm sure it can be accomodated, but if the goal is to identify the values with overlaps, then the result would be sufficient enough for the task

 

(defun c:clash ( / _range low high ovl attbv blocks i lst a b f)
;;		 pBe June 2021			;;;
(defun _range (n m l / ol )
	(while
	  (and n m (or (< (low n) (low m) (high n))
		       (eq (cadr n)(cadr  m))))
		(setq ol (strcat (car n)"+"(car m)))	  	
		(setq n (list ol (strcat (itoa (low n))"-"
					 (itoa (max (high m)(high n)))))
		        l (cdr l) m (car l) )
			       )
   (list ol l)
)
  (setq low (lambda (s)(atoi (cadr s))))
  (setq high (lambda (s)
	   (atoi
	     (substr (cadr s) (+ 2 (vl-string-position 45 (cadr s))))
	   )
	 )
  )
  
  (if (setq blocks (ssget '((0 . "INSERT")(66 . 1))))
    (progn
	    (repeat (setq i (sslength blocks))
		(setq attbv (mapcar '(lambda (At)
				       (list (Vla-get-tagstring at)(Vla-get-textstring at)))
				       (Vlax-invoke (vlax-ename->vla-object
						      (ssname blocks (setq i (1- i)))) 'GetAttributes)))
	          (if (Setq f (mapcar '(lambda (tg)(cadr (assoc tg attbv)))
						 '("TERM_TAG" "FIBERS_USED")))
		  (setq lst (Cons f lst))
		)
	      )
           	(setq lst (Vl-sort lst '(lambda (a b)  (< (atoi (cadr a))(atoi (cadr b))))))
		(While  (setq a (car lst))
		      (setq b (Cadr lst))
			(if (Car (setq f (_range a b (cdr lst)))) (setq ovl (cons (Car f) ovl)))
			(setq lst (cadr f))		
		)
      )
    (princ "\nNo valid blocks found")
    )
      (if ovl
	(print (substr (apply 'strcat (mapcar '(lambda (v)(strcat " | " v )) (reverse ovl))) 4))
	(Alert "All OK")
	)
  (princ)  
)

 HTH

 

Command: clash

Select objects:
"A1+H1+D1+B1 | F1+C1 | E1+G1"

 

Also, check out @ronjonp  entry, the code yields  similar results.

 

Message 16 of 30

pbejse
Mentor
Mentor

@ronjonp wrote:
...
	  (setq r (cons (list a (read (vl-string-translate "-" " " (strcat "(" b ")")))) r))
... 

 


Nice, should've thought of that. 👍

 

Message 17 of 30

hak_vz
Advisor
Advisor

Another one.

 

(defun c:checkrange 
( /
	i ss att term_tags fibers_used list_to_string string_to_list overlap sit a b c d left cur tmp ret
)
(defun unique ( l )(if l (cons (car l) (unique (vl-remove (car l) l)))))
(defun string_to_list ( str del / pos )
	(if (setq pos (vl-string-search del str))
		(cons (substr str 1 pos) (string_to_list (substr str (+ pos 1 (strlen del))) del))
		(list str)
	)
)
(defun list_to_string (lst del)
    (if (cdr lst)
        (strcat (car lst) del (list_to_string (cdr lst) del))
        (car lst)
    )
)
(defun overlap (a b c d)
(or
	(>= b c)
	(>= b d)
)
)

(princ "\nSelect blocks to check >")
(setq ss (ssget '((0 . "INSERT"))) i -1)
(while (< (setq i (1+ i)) (sslength ss))
(setq att 
	(cons
		(mapcar '(lambda (att) (cons(vla-get-tagstring att)(vla-get-textstring att))) (vlax-invoke(vlax-ename->vla-object(ssname ss i)) 'getattributes))
		att)
	)
)
(setq sit nil)
(foreach a att 
	(setq term_tags (cons (cdr (assoc "TERM_TAG" a)) term_tags))
	(setq fibers_used (cons (mapcar 'atoi (string_to_list (cdr (assoc "FIBERS_USED" a)) "-")) fibers_used))
)
(setq sit (vl-sort (mapcar 'cons term_tags fibers_used) '(lambda (x y) (< (cadr x)(cadr y)))))
(setq i -1 ret (list))
(while (< (setq i (1+ i)) (1-(length sit)))
	(setq left (nth i sit) j i tmp (list))
	(setq a (cadr left) b (caddr left))
	(while (< (setq j (1+ j)) (length sit))
			(setq cur (nth j sit))
			(setq c (cadr cur) d (caddr cur))
			(if (overlap a b c d)(setq tmp (append tmp (list (car left) (car cur)))))
	)
	(if tmp (setq ret (append ret (list (unique tmp)))))
)
(if ret
	(foreach e ret(princ (strcat "\n" (list_to_string e "+"))))
	(princ "\nAll OK!")
)
(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 18 of 30

cherrygate
Enthusiast
Enthusiast

Thank you everyone for all your help, it has been greatly appreciated and saved me so much time.

0 Likes
Message 19 of 30

ronjonp
Mentor
Mentor

@pbejse wrote:

@ronjonp wrote:
...
	  (setq r (cons (list a (read (vl-string-translate "-" " " (strcat "(" b ")")))) r))
... 

 


Nice, should've thought of that. 👍

 


Thanks! 🍻

0 Likes
Message 20 of 30

cherrygate
Enthusiast
Enthusiast

@pbejse wrote:

@cherrygate wrote:

With that being said, if this is the best result that can be achieved with AutoLISP then I would be ok with that result.


😄It's not that @cherrygate , I'm sure it can be accomodated, but if the goal is to identify the values with overlaps, then the result would be sufficient enough for the task

 

 

 

(defun c:clash ( / _range low high ovl attbv blocks i lst a b f)
;;		 pBe June 2021			;;;
(defun _range (n m l / ol )
	(while
	  (and n m (or (< (low n) (low m) (high n))
		       (eq (cadr n)(cadr  m))))
		(setq ol (strcat (car n)"+"(car m)))	  	
		(setq n (list ol (strcat (itoa (low n))"-"
					 (itoa (max (high m)(high n)))))
		        l (cdr l) m (car l) )
			       )
   (list ol l)
)
  (setq low (lambda (s)(atoi (cadr s))))
  (setq high (lambda (s)
	   (atoi
	     (substr (cadr s) (+ 2 (vl-string-position 45 (cadr s))))
	   )
	 )
  )
  
  (if (setq blocks (ssget '((0 . "INSERT")(66 . 1))))
    (progn
	    (repeat (setq i (sslength blocks))
		(setq attbv (mapcar '(lambda (At)
				       (list (Vla-get-tagstring at)(Vla-get-textstring at)))
				       (Vlax-invoke (vlax-ename->vla-object
						      (ssname blocks (setq i (1- i)))) 'GetAttributes)))
	          (if (Setq f (mapcar '(lambda (tg)(cadr (assoc tg attbv)))
						 '("TERM_TAG" "FIBERS_USED")))
		  (setq lst (Cons f lst))
		)
	      )
           	(setq lst (Vl-sort lst '(lambda (a b)  (< (atoi (cadr a))(atoi (cadr b))))))
		(While  (setq a (car lst))
		      (setq b (Cadr lst))
			(if (Car (setq f (_range a b (cdr lst)))) (setq ovl (cons (Car f) ovl)))
			(setq lst (cadr f))		
		)
      )
    (princ "\nNo valid blocks found")
    )
      (if ovl
	(print (substr (apply 'strcat (mapcar '(lambda (v)(strcat " | " v )) (reverse ovl))) 4))
	(Alert "All OK")
	)
  (princ)  
)

 

 


So I have come across one issue while using it in the real world - Sometimes there isn't a number RANGE and just a single number in that attribute, and it doesn't work.

 

If you could help me out with that, that would be amazing. This has been working perfectly besides that

0 Likes