Jump to content

Copy multiple text contents to nearest text (multiples)


Recommended Posts

Posted

@ronjonp correct me if am wrong.

Build a selection set

set a mini distance for t

depending on layer separate the selection set into 2 lists

  one with the point and text

  other with the point and entity

Sort each list by first elements x cord smallest to largest.

while their is a elements in list a

compare the first element to each element in list b stop if distance is less then 1.5 & change the text and remove it from list b.

(works left to right in drawing because of sort)

(usually only have to compare 1-5 items before meeting distance statement instead of checking whole list)

if nothing is withing 1.5 distance make a circle around text point on nomatch layer.

Posted (edited)
2 hours ago, mhupp said:

@ronjonp correct me if am wrong.

Build a selection set

set a mini distance for t

depending on layer separate the selection set into 2 lists

  one with the point and text

  other with the point and entity

Sort each list by first elements x cord smallest to largest.

while their is a elements in list a

compare the first element to each element in list b stop if distance is less then 1.5 & change the text and remove it from list b.

(works left to right in drawing because of sort)

(usually only have to compare 1-5 items before meeting distance statement instead of checking whole list)

if nothing is withing 1.5 distance make a circle around text point on nomatch layer.

Spot on :) ... the speed boost comes from the pre-sorted x values and vl-some stepping out when it finds a match (which should be closer to the front of the list).

Edited by ronjonp
Posted

Wouldn't it be possible to get the wrong text?  like it would pick up cat before dog because its to the left but still within the acceptable distance? Just trying to fig it out the pros and cons. like not to make the check distance too big or you might get errors.

 

image.png.5ade21c1eb0ffb4fc1d7b93510920d74.png

Posted (edited)
10 minutes ago, mhupp said:

Wouldn't it be possible to get the wrong text? ....

Yes. vl-sort to the closest distance is probably the most reliable.

 

That code was tailored to the sample drawing.

Edited by ronjonp
  • Like 1
Posted

Like the ronjonp answer it will depend on tolerance so maybe use the text ht * fuzz factor for the tolerance, I will do the search by polygon method interested as to how fast compared to the distance method. Have to go out now later today hopefully.

  • 3 years later...
Posted
On 11/22/2021 at 11:30 PM, ronjonp said:

Here is another way .. checks that there is something within a distance of 1.5 ( based on the sample drawing ). Should be fairly fast 🍻

(defun c:foo (/ a b c d el r s)
  ;; RJP » 2021-11-22
  (cond	((setq s (ssget "_X" '((0 . "TEXT") (8 . "urb_rasante,CVL_RAS_TX"))))
	 (setq d 1.5)
	 (foreach e (mapcar 'cadr (ssnamex s))
	   (if (= "CVL_RAS_TX" (cdr (assoc 8 (setq el (entget e)))))
	     (setq a (cons (list (cdr (assoc 11 el)) (cdr (assoc 1 el))) a))
	     (setq b (cons (list (cdr (assoc 11 el)) e) b))
	   )
	 )
	 (setq a (vl-sort a '(lambda (r j) (< (caar r) (caar j)))))
	 (setq b (vl-sort b '(lambda (r j) (< (caar r) (caar j)))))
	 (while	(setq c (car a))
	   (setq a (cdr a))
	   (if (vl-some '(lambda (x) (<= (distance (car c) (car (setq r x))) d)) b)
	     (list (entmod (append (entget (cadr r)) (list (cons 1 (cadr c)))))
		   (setq b (vl-remove r b))
	     )
	     (entmake (list '(0 . "circle") (cons 10 (car c)) '(40 . 5) '(8 . "NoMatch")))
	   )
	 )
	)
  )
  (princ)
)

 

Hi Ronjonp, Thanks for this wonderful code, can this be modified further?
1. To select the texts irrespective of the layers and distances (select the first set of text and the second set whose values are to be changed.)
2. Change the text values even if the numbers are different. For example, if the first set has 7 texts and the second set has 20 texts (and vice versa), the values for the first 7 text objects should be changed, and the remaining should be ignored. The selection should be from top to bottom or left to right.

3. The code should loop for multiple sets.

 

I appreciate any help you can provide.

  • 2 weeks later...
Posted
On 1/16/2025 at 3:23 PM, symoin said:

Hi Ronjonp, Thanks for this wonderful code, can this be modified further?
1. To select the texts irrespective of the layers and distances (select the first set of text and the second set whose values are to be changed.)
2. Change the text values even if the numbers are different. For example, if the first set has 7 texts and the second set has 20 texts (and vice versa), the values for the first 7 text objects should be changed, and the remaining should be ignored. The selection should be from top to bottom or left to right.

3. The code should loop for multiple sets.

 

I appreciate any help you can provide.

Any Help?

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