Difference between 2 text values and the result as a text.

Difference between 2 text values and the result as a text.

symoin
Enthusiast Enthusiast
658 Views
4 Replies
Message 1 of 5

Difference between 2 text values and the result as a text.

symoin
Enthusiast
Enthusiast

Hi Everyone,

I have a situation Where I need to find the difference between 2 layers (Before and after) and write the result in another layer (Difference). The drawing has points with elevations and the text as elevation labels, I need to write the difference in the Z value Elevations near the location. I there any way this can be achieved in one go rather than each pair of text (selecting 3 points)? There are more than 2500 pairs of such points.

 

The attached drawing is for reference.

0 Likes
Accepted solutions (1)
659 Views
4 Replies
Replies (4)
Message 2 of 5

komondormrex
Mentor
Mentor
Accepted solution

hey,

check this one

 

(defun c:diff (/ bp_sset +bt_size -bt_size bt_insertion ba_sset z_diff diff_text)
	(princ "\nSelect \"BEFORE\" texts...")
	(if (setq bp_sset (ssget '((0 . "text") (8 . "before"))))
		(foreach b_text (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex bp_sset))))
			(setq +bt_size (* 2 (vla-get-height b_text))
				  -bt_size (* -1 +bt_size)
				  bt_insertion (vlax-get b_text 'insertionpoint)
				  ba_sset (ssget "_cp" 
				  				 (mapcar '(lambda (point_1 point_2) (mapcar '+ point_1 point_2))
								 		  (list (list -bt_size -bt_size) (list -bt_size +bt_size) (list +bt_size +bt_size) (list +bt_size -bt_size))
								   		  (list bt_insertion bt_insertion bt_insertion bt_insertion)
								 )
								 '((0 . "text") (8 . "after"))
						  )
				  z_diff (- (atof (vla-get-textstring b_text)) (atof (vla-get-textstring (vlax-ename->vla-object (ssname ba_sset 0)))))
				  diff_text (vla-copy b_text)    
			)
			(vla-move diff_text (vlax-3d-point bt_insertion) (vlax-3d-point (mapcar '+ bt_insertion (list 0 (* -1.65 +bt_size) z_diff)))) 
			(vla-put-textstring diff_text (rtos z_diff 2 3))  
			(entmod (append (entget (entlast)) '((8 . "DIFFERENCE"))))
		)
	)
	(princ)
)

updated

 

0 Likes
Message 3 of 5

symoin
Enthusiast
Enthusiast

Thank you komondormrex,
This is a great code and is as I need. Here I have noticed its nor working on a few text values. I have attached the Snap , look at the command prompt.

Further I request you for another update. like :  if there are no text and only points are available in the drawing. Can we calculate the differences from the point elevations?

Thanks once again for the help.

0 Likes
Message 4 of 5

komondormrex
Mentor
Mentor

check update with increased fuzz to select text. will see the option with points only later on. 

0 Likes
Message 5 of 5

komondormrex
Mentor
Mentor

hey,

here you go

(defun c:z_diff (/ bp_sset +bp_size -bp_size bt_insertion ap_sset z_diff)
	(princ "\nSelect \"BEFORE\" points...")
	(if (setq bp_sset (ssget '((0 . "point") (8 . "before"))))
		(foreach b_point (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex bp_sset))))
			(setq +bp_size (* 2 (getvar 'pdsize))
				  -bp_size (* -1 +bp_size)
				  bt_insertion (vlax-get b_point 'coordinates)
				  ap_sset (ssget "_cp" 
				  				 (mapcar '(lambda (point_1 point_2) (mapcar '+ point_1 point_2))
								 		  (list (list -bp_size -bp_size) (list -bp_size +bp_size) (list +bp_size +bp_size) (list +bp_size -bp_size))
								   		  (list bt_insertion bt_insertion bt_insertion bt_insertion)
								 )
								 '((0 . "point") (8 . "after"))
						  )
				  z_diff (- (caddr bt_insertion) (caddr (vlax-get (vlax-ename->vla-object (ssname ap_sset 0)) 'coordinates)))
			)

			(vla-addtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
						 (rtos z_diff 2 3)
						 (vlax-3d-point (mapcar '+ bt_insertion (list 0 (* -1.65 +bp_size) z_diff)))
						 (if (null text_size) (setq text_size (getreal "\nEnter marking text size: ")) text_size) 
			)
			(entmod (append (entget (entlast)) '((8 . "DIFFERENCE"))))
		)
	)
	(princ)
)
0 Likes