Jump to content

Combine text strings


pyrzms

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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