Find one letter within a closed polyline and append it to a string within the same closed polyline

Find one letter within a closed polyline and append it to a string within the same closed polyline

johnlagasse
Contributor Contributor
465 Views
6 Replies
Message 1 of 7

Find one letter within a closed polyline and append it to a string within the same closed polyline

johnlagasse
Contributor
Contributor

I have a one or two letters as an indicator with a closed polyline. Within that closed polyline is a string of text that I want to append the one or two letters to.  Is there any LISP routine out there already that does this?  I've attached a DWG.  I'm looking to select all the polylines within the drawing and have them all update.  In the case of the DWG I want 10.03.T to end up as 10.03.TB and 10.04.T to end up as 10.04.TAA. Thanks for any assistance.

0 Likes
Accepted solutions (2)
466 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

DWG seems empty to me.

Message 3 of 7

johnlagasse
Contributor
Contributor

I downloaded it and can see two rectangles and text in each.  I resaved it and uploaded it.  Added screenshot.

johnlagasse_0-1654267469311.png

 

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

Ok, it behaves weird, but see it now.

Is it always short label TEXT and long one MTEXT?

Message 5 of 7

johnlagasse
Contributor
Contributor

It can be changed so it's either all Text or all MTEXT

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, here you go. It could be easier if that was a rule.

Anyway.

 

(vl-load-com)

(defun c:PlineAppendString ( / e i v p e1 e2)

  (if (setq s (ssget '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
    (repeat (setq i (sslength s))
      (if (and (setq v (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) (entget (ssname s (setq i (1- i)))))))
	       (setq p (ssget "_WP" v '((0 . "*TEXT"))))
	       (= (sslength p) 2)
	       (setq e1 (entget (ssname p 0)))
	       (setq e2 (entget (ssname p 1)))
	       )
	(if (< (strlen (cdr (assoc 1 e1))) 3)
	  (entmod (subst (cons 1 (strcat (cdr (assoc 1 e2)) (cdr (assoc 1 e1)))) (assoc 1 e2) e2))
	  (entmod (subst (cons 1 (strcat (cdr (assoc 1 e1)) (cdr (assoc 1 e2)))) (assoc 1 e1) e1))))))
  (princ)
  )
Message 7 of 7

johnlagasse
Contributor
Contributor
Accepted solution

Awesome!  Works perfectly.  I just need to close some of the polylines.  THANKS!

0 Likes