pyrzms Posted January 17, 2014 Posted January 17, 2014 I have a lot of text strings in a drawing and I want to combine these texts in pairs once time. First Text : "47[20/20" Second text : "L=1200" Final text : "47[20/20 L=1200" I attached sample drawing. Thanks for help.sample.dwg Quote
ymg3 Posted January 17, 2014 Posted January 17, 2014 pyrzms, It is more difficult than it looks. How are we to make sure that the lenght part belongs to the first part. We could use the position and get the closest, but there might be case where it will not work correctly. This is why the repair routine was asking you to select. ymg Quote
hmsilva Posted January 18, 2014 Posted January 18, 2014 As a "demo", perhaps something like this (defun c:test (/ ENT ENT1 HND HND1 ITM MN MX NUM P1 P2 P3 SS SS1 STR) (if (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "#*`[##`/##")))) (progn (setq itm 0 num (sslength ss) ) (while (< itm num) (setq hnd (ssname ss itm) ent (entget hnd) ) (vla-getboundingbox (vlax-ename->vla-object hnd) 'mn 'mx) (setq p1 (vlax-safearray->list mn) p2 (vlax-safearray->list mx) ) (setq p3 (list (+ (- (car p2) (car p1)) (car p2)) (cadr p1) (caddr p2)) ) (if (setq ss1 (ssget "_C" p2 p3 '((0 . "TEXT") (1 . "@=#*")))) (progn (setq hnd1 (ssname ss1 0) ent1 (entget hnd1) str (strcat (cdr (assoc 1 ent)) " " (cdr (assoc 1 ent1))) ) (entmod (subst (cons 1 str) (assoc 1 ent) ent)) (entdel hnd1) ) ) (setq itm (1+ itm)) ) ) ) (princ) ) HTH Henrique Quote
ymg3 Posted January 19, 2014 Posted January 19, 2014 hmsilva, This is quite Good! Only thing I would do different would be to create the Joined entity on a new layer, and not delete the separated one until I could inspect them. Very small modification: (setq ent (subst (cons 1 str) (assoc 1 ent) ent) ent (subst (cons 8 "JOINED") (assoc 8 ent) ent) ) (entmakex ent) ymg Quote
hmsilva Posted January 19, 2014 Posted January 19, 2014 hmsilva, Only thing I would do different would be to create the Joined entity on a new layer, and not delete the separated one until I could inspect them. Nice modification, ymg Henrique Quote
pyrzms Posted January 21, 2014 Author Posted January 21, 2014 Thanks ymg3 and hmsilva . ymg3 how can I add your last (setq ent (subst (cons 1 str) (assoc 1 ent) ent) ent (subst (cons 8 "JOINED") (assoc 8 ent) ent) ) (entmakex ent) modification. Quote
hmsilva Posted January 21, 2014 Posted January 21, 2014 You're welcome, pyrzms With the ymg mod (defun c:test (/ ENT ENT1 HND ITM MN MX NUM P1 P2 P3 SS SS1 STR) (if (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "#*`[##`/##")))) (progn (setq itm 0 num (sslength ss) ) (while (< itm num) (setq hnd (ssname ss itm) ent (entget hnd) ) (vla-getboundingbox (vlax-ename->vla-object hnd) 'mn 'mx) (setq p1 (vlax-safearray->list mn) p2 (vlax-safearray->list mx) ) (setq p3 (list (+ (- (car p2) (car p1)) (car p2)) (cadr p1) (caddr p2)) ) (if (setq ss1 (ssget "_C" p2 p3 '((0 . "TEXT") (1 . "@=#*")))) (progn (setq ent1 (entget (ssname ss1 0)) str (strcat (cdr (assoc 1 ent)) " " (cdr (assoc 1 ent1))) ent (subst (cons 1 str) (assoc 1 ent) ent) ent (subst (cons 8 "JOINED") (assoc 8 ent) ent) ) (entmakex ent) ) ) (setq itm (1+ itm)) ) ) ) (princ) ) HTH Henrique Quote
ymg3 Posted January 21, 2014 Posted January 21, 2014 pyrzms, Hope Enrique won't mind, but here I've modified it some more, The joined text is placed on Layer Joined as the above, but we offset it by a constant equals to 1.25 times the text height of the first text entity in the selection set. The justification of the joined text entities is changed to left justify, to align more closely with the separated position. So once you are happy with the result, you delete everything on the initial layer, and then move everything down by the value of offset. A little report is sent to the text screen giving you the following: Found Items: 264 Matched Items: 262 Vert. Offset: 18.75 Here is the modification: (defun c:jtxt (/ ent ent1 hnd hnd1 itm mn mx num p1 p2 p3 ss ss1 str) (if (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "#*`[##`/##")))) (progn (setq ofs (* (cdr (assoc 40 (entget (ssname ss 0)))) 1.25) itm 0 jcount 0 num (sslength ss) ) (while (< itm num) (setq hnd (ssname ss itm) ent (entget hnd) ) (vla-getboundingbox (vlax-ename->vla-object hnd) 'mn 'mx) (setq p1 (vlax-safearray->list mn) p2 (vlax-safearray->list mx) ) (setq p3 (list (+ (- (car p2) (car p1)) (car p2)) (cadr p1) (caddr p2)) ) (if (setq ss1 (ssget "_C" p2 p3 '((0 . "TEXT") (1 . "@=#*")))) (progn (setq hnd1 (ssname ss1 0) ent1 (entget hnd1) str (strcat (cdr (assoc 1 ent)) " " (cdr (assoc 1 ent1))) loc (cdr (assoc 10 ent)) loc (list (car loc) (+ (cadr loc) ofs) (caddr loc)) ) (setq ent (subst (cons 1 str) (assoc 1 ent) ent) ent (subst (cons 8 "JOINED") (assoc 8 ent) ent) ent (subst (cons 10 loc) (assoc 10 ent) ent) ent (subst (cons 11 loc) (assoc 11 ent) ent) ent (subst (cons 72 0) (assoc 72 ent) ent) ) (entmake ent) (setq jcount (1+ jcount)) ) ) (setq itm (1+ itm)) ) ) ) (princ (strcat "\n Found Items: " (itoa itm) "\nMatched Items: " (itoa jcount) "\n Vert. Offset: " (rtos ofs 2 2) ) ) (princ) ) May be a better way would be to change the layer and move the separated item instead of the Joined one. This way you would have nothing to do at the end, except deleting the separated. But for this we would need to change the Selection Method a little to only include the text entity that have a "[" in them but no "L=". I'll see. ymg Quote
Recommended Posts
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.