Breaking from the Intersection Point - write length

Breaking from the Intersection Point - write length

k005
Advisor Advisor
1,569 Views
22 Replies
Message 1 of 23

Breaking from the Intersection Point - write length

k005
Advisor
Advisor

Hello friends;


How can I print the total by breaking the lines at the intersection point, transferring them to layer 0 ? ?


Sample file has been added.


Thanks in advance to the helpful friend.

0 Likes
Accepted solutions (2)
1,570 Views
22 Replies
Replies (22)
Message 2 of 23

Kent1Cooper
Consultant
Consultant

There are various routines available that will Break all selected objects at every intersection.  I'll let you Search.

But you didn't change all of the things Broken to Layer 0.  Why those of one Layer but not of the other?  I guess a Break-everything routine could check for an object's current Layer and decide whether to put it on Layer 0.

More bizarre:  the numerical content of the Text seems to have nothing to do with the lengths or spacings or enclosed areas of the nearby things, so a routine would not be able to populate the numerical Text, unless there's some relationship that is not apparent to me.  What is really supposed to happen?

Kent Cooper, AIA
0 Likes
Message 3 of 23

Moshe-A
Mentor
Mentor

@k005  hi,

 

check this CBRK command.

 

first select all the cutting lines (green) + enter

than select all the lines to break (red) + enter

 

enjoy

Moshe

 

(vl-load-com) ; load activex support

(defun c:cbrk (/ build_data change_layer_color ; local function
                 adoc modelSpace ss0 ss1 dat AcDbLine0 AcDbLine1 cr p0 p1)
 
 (defun build_data (/ ename0 ename1 elist0 elist1 p0 p1 p2 p3)
  (foreach ename0 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0)))
    (setq elist0 (entget ename0))
    (setq p0 (cdr (assoc '10 elist0)))
    (setq p1 (cdr (assoc '11 elist0)))
    
    (foreach ename1 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1)))
      (setq elist1 (entget ename1))
      (setq p2 (cdr (assoc '10 elist1)))
      (setq p3 (cdr (assoc '11 elist1)))
      
      (if (setq cr (inters p0 p1 p2 p3))
       (setq lst (cons (list ename1 cr) lst))
	  )
    ); foreach
  ); foreach
   
  (reverse lst) ; return
 ); build_data
  
 (defun change_layer_color (AcDbObj / AcCmColor)
   (setq AcCmColor (vla-get-trueColor AcDbObj))
   (vla-put-colorindex AcCmColor acByLayer)           
   (vla-put-TrueColor AcDbObj AcCmColor)
   (vlax-release-object AcCmColor)
   
   (vla-put-layer AcDbObj "0")
   (vlax-release-object AcDbObj)
 ); change_layer_color
 
  
; here start c:cbrk
 (setq adoc (vla-get-activeDocument (vlax-get-acad-object)))
  
 (vla-StartUndoMark adoc)
 (setq modelSpace (vla-get-modelspace adoc))
   
 (if (and
       (not (prompt "\nSelect Cutting edges..."))
       (setq ss0 (ssget '((0 . "line"))))
       (not (prompt "\nSelect object to trim..."))
       (setq ss1 (ssget '((0 . "line"))))
     )
  (foreach dat (build_data)
    (setq AcDbLine0 (vlax-ename->vla-object (car dat)))
    (setq cr (cadr dat))
    (setq p0 (vlax-safearray->list (vlax-variant-value (vla-get-startpoint AcDbLine0))))
    (setq p1 (vlax-safearray->list (vlax-variant-value (vla-get-endpoint   AcDbLine0))))
    
    (cond
     ((< (distance p0 cr) (distance p1 cr))
      (vla-put-startpoint AcDbLine0 (vlax-3d-point p0))
      (setq AcDbLine1 (vla-addLine modelSpace (vlax-3d-point cr) (vlax-3d-point p0)))
      (change_layer_color AcDbLine1) ; memory is disposed in caller function
	 ); case
     ((< (distance p1 cr) (distance p0 cr))
      (vla-put-endpoint AcDbLine0 (vlax-3d-point p1)) 
      (setq AcDbLine1 (vla-addLine modelSpace (vlax-3d-point cr) (vlax-3d-point p1)))
	  (change_layer_color AcDbLine1) ; memory is disposed in caller function           
     ); case
    ); cond
      
    (vlax-release-object AcDbLine0)
  ); foreach
 ); if
  
 (vlax-release-object modelSpace)
  
 (vla-EndUndoMark adoc)
 (vlax-release-object adoc)
  
 (princ)
) ; c:cbrk

 

 

 

0 Likes
Message 4 of 23

Kent1Cooper
Consultant
Consultant

@Moshe-A wrote:

.....

first select all the cutting lines (green) + enter

than select all the lines to break (red) + enter

.....


[Except that the "after" situation in the sample drawing also has the green lines broken at all intersections.]

Kent Cooper, AIA
0 Likes
Message 5 of 23

k005
Advisor
Advisor

Let me explain it this way:

 

I need the layer before the break for another calculation. The name of that layer is:SIVA. and KIRIS.

The reason I want to get it at 0 is to separate it from this SIVA layer. Because that part requires a separate account and a local account. In short, like this...

0 Likes
Message 6 of 23

k005
Advisor
Advisor

Thank you for the reply.


However, when I ran the routine, I did not get the desired result... and a +1 object was created... I do not want this. In other words, operations must be performed on existing Line objects, text must be created.

0 Likes
Message 7 of 23

Kent1Cooper
Consultant
Consultant

@k005 wrote:

.... In short, like this...

[and in Reply to @Moshe-A:]   text must be created


In short, like what?  Did you mean to attach something?

And is the "before" situation in the drawing incorrect?  Should it not have the Text, if that is to be created [not edited] by the routine?

Also, you haven't explained the discrepancy between the numbers in the Text and the properties of the Lines.

If only SIVA Line segments between KIRIS Lines are to be moved to Layer 0, do you still want to also Break the KIRIS Lines at every intersection, as in the sample drawing?

Kent Cooper, AIA
0 Likes
Message 8 of 23

Moshe-A
Mentor
Mentor

@k005  hi,

 

i think you did not gave us the whole picture and your relay on our investigation of your sample drawing which result giving you some code only then you discover that it does not work or do what you want so why don't you change approach, draw a complete sample drawing with Before and After exactly as you want it add some leader notes with explanations where relevant so you will get one working code - ok?!

 

Moshe

 

0 Likes
Message 9 of 23

komondormrex
Mentor
Mentor

@k005 

hey there,

are these entities to be broken always lines?

0 Likes
Message 10 of 23

k005
Advisor
Advisor

* If he tells the whole picture here, things will get even more complicated...

 

I have already stated what is wanted in the sample drawing... Relax.!

 

1. It will be broken at the intersection points.

2. A new line will definitely not be created.

3. After breaking at the intersection points, the total length of these lines will be calculated

4. The total length of the broken lines will be the text on the TABANALANI layer.

5. The broken lines will be moved to layer 0 in their new dimensions. ( SIVA )

 

0 Likes
Message 11 of 23

k005
Advisor
Advisor

Yes. Beings are always Line.

0 Likes
Message 12 of 23

k005
Advisor
Advisor

Now ;


1. What I want to achieve is as I mentioned in AFTER. Breaking of SIVA lines at the intersection with KIRIS.

2. Moving these broken Lines to layer 0.

3. Calculating and printing the total length of these broken lines from the point where they are broken. In the TABANALANI layer. (Example is given...)


That's all.

0 Likes
Message 13 of 23

Kent1Cooper
Consultant
Consultant

There are still discrepancies between your descriptions and the sample drawing.

You describe Breaking the SIVA lines, but in "after," the KIRIS lines [which are continuous in "before"] are also Broken at every intersection.  Should they not be Broken, or do you really want all lines on both Layers Broken?

I would assume "these broken lines" that are to be moved to Layer 0 are all the lines that were Broken, but in "after," those on the KIRIS Layer are not moved to Layer 0.  [If they should not have been Broken at all, that answers this issue.]

You describe in one Message that the Text needs to be "created," but it is already there in "before," with zeros for all the numerical parts.  Should it not be in "before"?  If it should be there already, it would only be edited, not created.

The Text content in "after" does reflect the total length of all SIVA lines that are near that Text inside the KIRIS "box," but where is the 2.88 multiplier coming from?  I can't find anything with that kind of length or size.  [The SIVA Layer has a non-zero lineweight, but it's not 2.88, and if lines on it go to Layer 0, they lose that anyway.]  If 2.88 is a constant, and if the Text is really already there, should the 2.88 be built into the appropriate place in the Text, rather than starting as zero?  If 2.88 is not a constant, then a routine would need some basis for it to use in the multiplication.  Should the routine ask the User?  Can it be calculated from I-don't-knw-what in the drawing or the selected objects?  Is it a variable that would already be established?

Unrelated to the discrepancies:

The "before" text has two decimal places in all numbers, but in "after," the area numbers [not the lengths or the multiplier] are to only one decimal place.  Which should they be?

If the Text is to be created, what are the criteria for its Style and height and location?  Would they be constant, or should the User be asked?  Could the height be calculated relative to something, like the drawing's plotting scale?

Is it your intent that all these lines should be selected together?  If so, how is a routine to know that [in your sample drawing] there should be two calculations done and which of the lines go together into those two, rather than that they are all to be processed as one group?

 

Kent Cooper, AIA
0 Likes
Message 14 of 23

john.uhden
Mentor
Mentor

@k005 ,

Umm, how do you break a line and not create a new one?

Oh, I guess you mean you will have created a 2 part line.  😲

John F. Uhden

0 Likes
Message 15 of 23

k005
Advisor
Advisor

- The number 2.88 is fixed. The text is created from scratch. The current one is not used., it was for the example... It should be in the TABANALANI layer.

- Total line length must be in the SIVA layer. However, as seen in the example, it must be calculated from the breaking points...

- Then move these broken and sized SIVA lines to layer 0.

 

In other words, the KIRIS layer is only auxiliary..., In fact, exactly what is requested is given in the sample drawing...


That's all.

 

 

0 Likes
Message 16 of 23

k005
Advisor
Advisor

Yes . Definitely.

Before the process, both parts are in the SIVA layer. , should be in layer 0, the size of which is calculated after the process.

0 Likes
Message 17 of 23

komondormrex
Mentor
Mentor
Accepted solution

@k005 

hello there,

check the following code. just select lines to break and a container text for the summary inside breaker lines.

 

;***********************************************************************************************************************************************************************

(defun get_fence_ints (point_1 point_2)
  	(if (and (setq fence_sset (ssget "_f" (list point_1 point_2) '((8 . "KIRIS"))))
  		   	 (setq intersected_list (ssnamex fence_sset))
  	    )
    	(mapcar '(lambda (intersected) (list (cadr intersected) (cadr (cadddr intersected)))) intersected_list)
  	)
)

;***********************************************************************************************************************************************************************

(defun c:break_n_sum (/ line_sset total_length factor sset_data sec_lines text_object parsed_line_list inters_point point_list
					  int_point_list_1 break_point_1 left_over_1_list int_point_list_2 break_point_2 left_over_2_list line_object
				   )
	(princ "\nSelect lines to break and container text inside breaker lines...")
	(if (setq line_sset (ssget '((-4 . "<or") (0 . "line") (-4 . "<and") (0 . "text") (1 . "Kln*") (-4 . "and>") (-4 . "or>"))))
		(progn
			(setq total_length 0 factor 2.88)
  			(if (= -1 (car (last (setq sset_data (ssnamex line_sset)))))
  			  (setq sec_lines (mapcar 'list (setq point_list (mapcar 'cadr (cdr (last sset_data))))
  						          			(append (cdr point_list) (list (car point_list)))
  					    	  )
  				    sset_data (cdr (reverse sset_data))
  			  )
  			)
  			(foreach line sset_data
  			  	(cond
					((member '(0 . "TEXT") (entget (cadr line))) (setq text_object (vlax-ename->vla-object (cadr line))))
  			  		((= 1 (car line))
  			  		 	(setq parsed_line_list (append parsed_line_list (list (list (cadr line) (vlax-curve-getclosestpointto (cadr line) (cadr (cadddr line)))))))
  			  		)
  			  		((= 3 (car line))
  			  		 	(setq parsed_line_list (append parsed_line_list (list (list (cadr line)
  			  		 								     					   		 (if (vl-some '(lambda (sec_line) (setq inters_point (inters (vlax-curve-getstartpoint (cadr line))
  			  		 									 					   									         						 (vlax-curve-getendpoint (cadr line))
  			  		 									 					   									         						 (car sec_line)
  			  		 									 					   									         						 (cadr sec_line)
  			  		 									 					   									 						 )
  			  		 									 					   						      			  )
  			  		 									 					   				   		)
  			  		 									 					   				   		sec_lines
  			  		 									 					   			  )
  			  		 								     					   			    inters_point
  			  		 								     					   		 )
  			  		 							       					 	   )
  			  		 													 )
  			  		 							)
  			  		 	)
  			  		)
  			  	)
  			)
  			(foreach selected_line parsed_line_list
  			  (if (and (setq int_point_list_1 (vl-remove-if '(lambda (line) (assoc (car line) parsed_line_list)) (get_fence_ints (cadr selected_line) (vlax-curve-getstartpoint (car selected_line)))))
  					   (or (not (equal (cadar int_point_list_1) (vlax-curve-getstartpoint (car selected_line)) 1e-3))
  				     	   (not (equal (cadar int_point_list_1) (vlax-curve-getendpoint (car selected_line)) 1e-3))
  					   )
  					)
  			      	(setq break_point_1 (cadar int_point_list_1)
  				  	      left_over_1_list (list break_point_1 (vlax-curve-getstartpoint (car selected_line)))
  				  	)
  			      	(setq break_point_1 (vlax-curve-getstartpoint (car selected_line))
  				  	      left_over_1_list nil
  				  	)
  			  )
  			  (if (and (setq int_point_list_2 (vl-remove-if '(lambda (line) (assoc (car line) parsed_line_list)) (get_fence_ints (cadr selected_line) (vlax-curve-getendpoint (car selected_line)))))
  					   (or (not (equal (cadar int_point_list_2) (vlax-curve-getendpoint (car selected_line)) 1e-3))
  				     	   (not (equal (cadar int_point_list_2) (vlax-curve-getstartpoint (car selected_line)) 1e-3))
  					   )
  					)
  					(setq break_point_2 (cadar int_point_list_2)
  					      left_over_2_list (list break_point_2 (vlax-curve-getendpoint (car selected_line)))
  					)
  			      	(setq break_point_2 (vlax-curve-getendpoint (car selected_line))
  				  	      left_over_2_list nil
  				  	)
  			  )
  			  (if left_over_1_list
  			    	(progn
  				  		(setq left_over (vla-copy (setq line_object (vlax-ename->vla-object (car selected_line)))))
  				  		(vlax-put left_over 'startpoint (car left_over_1_list))
  				  		(vlax-put left_over 'endpoint (cadr left_over_1_list))
  					)
  			  )
  			  (if left_over_2_list
  			    	(progn
  				  		(setq left_over (vla-copy line_object))
  				  		(vlax-put left_over 'startpoint (car left_over_2_list))
  				  		(vlax-put left_over 'endpoint (cadr left_over_2_list))
  					)
  			  )
  			  (vlax-put line_object 'startpoint break_point_1)
  			  (vlax-put line_object 'endpoint break_point_2)
			  (vla-put-layer line_object "0")
			  (setq total_length (+ total_length (vla-get-length line_object)))
  			)
			(if text_object (vla-put-textstring text_object (strcat "Kln : " (rtos total_length 2 2) " x " (rtos factor 2 2) " = " (rtos (* total_length factor) 2 2) " m\\U+00B2"))
							(princ "\nContainer text was not selected")
			)
		)
	)
	(princ)
)

;***********************************************************************************************************************************************************************

 

 

0 Likes
Message 18 of 23

k005
Advisor
Advisor

Thank you very much, my friend. @komondormrex  This is exactly what I want... ‌🤗


God bless your hands.

0 Likes
Message 19 of 23

komondormrex
Mentor
Mentor

you're welcome)

Message 20 of 23

k005
Advisor
Advisor

Hello my friend. @komondormrex  I made some changes in the code section, but I think we need to update in the code. apology..


If you are available, of course,

 

The file is attached.

 

 

 

 

;***********************************************************************************************************************************************************************


(defun get_fence_ints (point_1 point_2)
  	(if (and (setq fence_sset (ssget "_f" (list point_1 point_2) '((8 . "KIRIS"))))
  		   	 (setq intersected_list (ssnamex fence_sset))
  	    )
    	(mapcar '(lambda (intersected) (list (cadr intersected) (cadr (cadddr intersected)))) intersected_list)
  	)
)

;***********************************************************************************************************************************************************************

(defun c:xbr2 (/ line_sset total_length yuks sset_data sec_lines text_object parsed_line_list inters_point point_list
					  int_point_list_1 break_point_1 left_over_1_list int_point_list_2 break_point_2 left_over_2_list
				   )
	(princ "\nSelect lines to break and container text inside breaker lines...")
        ;(setq factor (Getreal "\nYüksekliği Giriniz : "))

        (setq yuks (if (= yuks nil) 288 yuks))
        (setq yuk_t (getreal (strcat "\nYukseklik Giriniz <" (rtos yuks 2 2) ">: ")))
        (setq yuks (if (= yuk_t nil) yuks yuk_t))
  
	(if (setq line_sset (ssget '((-4 . "<or") (0 . "line") (-4 . "<and") (0 . "text") (1 . "Kln*") (-4 . "and>") (-4 . "or>"))))
		(progn
			(setq total_length 0)
  			(if (= -1 (car (last (setq sset_data (ssnamex line_sset)))))
  			  (setq sec_lines (mapcar 'list (setq point_list (mapcar 'cadr (cdr (last sset_data))))
  						          			(append (cdr point_list) (list (car point_list)))
  					    	  )
  				    sset_data (cdr (reverse sset_data))
  			  )
  			)
  			(foreach line sset_data
  			  	(cond
					((member '(0 . "TEXT") (entget (cadr line))) (setq text_object (vlax-ename->vla-object (cadr line))))
  			  		((= 1 (car line))
  			  		 	(setq parsed_line_list (append parsed_line_list (list (list (cadr line) (vlax-curve-getclosestpointto (cadr line) (cadr (cadddr line)))))))
  			  		)
  			  		((= 3 (car line))
  			  		 	(setq parsed_line_list (append parsed_line_list (list (list (cadr line)
  			  		 								     					   		 (if (vl-some '(lambda (sec_line) (setq inters_point (inters (vlax-curve-getstartpoint (cadr line))
  			  		 									 					   									         						 (vlax-curve-getendpoint (cadr line))
  			  		 									 					   									         						 (car sec_line)
  			  		 									 					   									         						 (cadr sec_line)
  			  		 									 					   									 						 )
  			  		 									 					   						      			  )
  			  		 									 					   				   		)
  			  		 									 					   				   		sec_lines
  			  		 									 					   			  )
  			  		 								     					   			    inters_point
  			  		 								     					   		 )
  			  		 							       					 	   )
  			  		 													 )
  			  		 							)
  			  		 	)
  			  		)
  			  	)
  			)
  			(foreach selected_line parsed_line_list
  			  (if (and (setq int_point_list_1 (vl-remove-if '(lambda (line) (assoc (car line) parsed_line_list)) (get_fence_ints (cadr selected_line) (vlax-curve-getstartpoint (car selected_line)))))
  					   (or (not (equal (cadar int_point_list_1) (vlax-curve-getstartpoint (car selected_line)) 1e-3))
  				     	   (not (equal (cadar int_point_list_1) (vlax-curve-getendpoint (car selected_line)) 1e-3))
  					   )
  					)
  			      	(setq break_point_1 (cadar int_point_list_1)
  				  	      left_over_1_list (list break_point_1 (vlax-curve-getstartpoint (car selected_line)))
  				  	)
  			      	(setq break_point_1 (vlax-curve-getstartpoint (car selected_line))
  				  	      left_over_1_list nil
  				  	)
  			  )
  			  (if (and (setq int_point_list_2 (vl-remove-if '(lambda (line) (assoc (car line) parsed_line_list)) (get_fence_ints (cadr selected_line) (vlax-curve-getendpoint (car selected_line)))))
  					   (or (not (equal (cadar int_point_list_2) (vlax-curve-getendpoint (car selected_line)) 1e-3))
  				     	   (not (equal (cadar int_point_list_2) (vlax-curve-getstartpoint (car selected_line)) 1e-3))
  					   )
  					)
  					(setq break_point_2 (cadar int_point_list_2)
  					      left_over_2_list (list break_point_2 (vlax-curve-getendpoint (car selected_line)))
  					)
  			      	(setq break_point_2 (vlax-curve-getendpoint (car selected_line))
  				  	      left_over_2_list nil
  				  	)
  			  )
  			  (if left_over_1_list
  			    	(progn
  				  		(setq left_over (vla-copy (setq line_object (vlax-ename->vla-object (car selected_line)))))
  				  		(vlax-put left_over 'startpoint (car left_over_1_list))
  				  		(vlax-put left_over 'endpoint (cadr left_over_1_list))
  					)
  			  )
  			  (if left_over_2_list
  			    	(progn
  				  		(setq left_over (vla-copy line_object))
  				  		(vlax-put left_over 'startpoint (car left_over_2_list))
  				  		(vlax-put left_over 'endpoint (cadr left_over_2_list))
  					)
  			  )
  			  (vlax-put line_object 'startpoint break_point_1)
  			  (vlax-put line_object 'endpoint break_point_2)
			  (vla-put-layer line_object "0")
			  (setq total_length (+ total_length (vla-get-length line_object)))
  			)
		        (setq toplamUzn(/ total_length 100.0))
		        (setq carpFactor (/ yuks 100.0))
		        
			(if text_object (vla-put-textstring text_object (strcat "Kln : " (rtos  toplamUzn 2 2) " x " (rtos carpFactor 2 2) " = " (rtos (* toplamUzn carpFactor) 2 2) " m\\U+00B2"))
							(princ "\nContainer text was not selected")
			)
		)
	)
	(princ)
)

 

0 Likes