overlapping texts

overlapping texts

dani-perez
Advocate Advocate
9,238 Views
10 Replies
Message 1 of 11

overlapping texts

dani-perez
Advocate
Advocate

Hello all

 

I have two problems:

 

1- test1. In this dwg you can see a lot of overlapping texts from a engineering software. I must print it with that text height, but they get overlapping. is there a way move the texts to right or left and establish an specifyc distance between them?

 

2-test2. in this dwg, you see a text surrounded by a series of lines (not block) from the same software. I have lots of them and the idea is to move the texts to the center of that series of line. any suggestions?

 

I lost too much time with this tasks...

Thanks in advance

0 Likes
Accepted solutions (3)
9,239 Views
10 Replies
Replies (10)
Message 2 of 11

CodeDing
Advisor
Advisor
Accepted solution

@dani-perez ,

 

This seems most efficient for your cases:

Test 1 - I think you should experiment with TEXTALIGN since you have text in many places/directions. Try to paste this into command line:

(command "_.TEXTALIGN" "_o" "_s" 0.0415 pause)

Test 2 - Assuming they're all similar to the one you provided, just paste this each time:

(progn (setq o (getvar 'OSMODE)) (setvar 'OSMODE 0) (command "_.MOVE" (car (entsel "\nSelect Text: ")) "" '(0 0.166 0) '(0 0 0)) (setvar 'OSMODE o))

Best,

~DD

0 Likes
Message 3 of 11

dani-perez
Advocate
Advocate

Hello CodeDing,

 

Thanks a lot for replying.

 

I tested code 1 (test1) and it works very well, it's really fast, so I can save much time in that task. Thanks

 

I tested code 2 (test2) and it works very well to. I see you fixed a distance to move down the texts, so I can modify it to move in other directions. But I don't know how to add a multiple texts selection (I think ssget but I dont know).

The next is an imaginary thing: Would be possible for the code to analyze if around the texts there is a boundary of any type (pline, lines, circles, blocks...) and move the texts to its center? it's a imaginary think hehe..

 

Thanks a lot!

 

 

0 Likes
Message 4 of 11

ВeekeeCZ
Consultant
Consultant

THIS Lee's routine might also help for your #1 issue.

0 Likes
Message 5 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

@dani-perez wrote:

....

2-test2. in this dwg, you see a text surrounded by a series of lines (not block) from the same software. I have lots of them and the idea is to move the texts to the center of that series of line. any suggestions?

....


 

Here's a way to do that figures out for itself  the direction and distance the Text needs to Move, so one routine can handle any relationship.  It assumes Text [no Mtext], and that there's only one  Text object in a related group, and Lines [not a Polyline or Block or something].  It requires you to select each related group separately, but they can be selected together in a Window or whatever selection option(s) you prefer -- no need to select the Text and Lines in separate selections.  [With a lot more code, it could presumably be made to allow selection of a lot of groups together, and figure out which Lines to work with in connection with each Text object, but that's quite a bit more challenging.]  Lightly tested.

 

(defun C:TCWL ; = Text Centered within Lines
  (/ ss n ent LL UR linesLL linesUR txtLL txtUR)
  (setq ss (ssget '((0 . "LINE,TEXT"))))
  (repeat (setq n (sslength ss))
    (setq ent (ssname ss (setq n (1- n))))
    (vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)
    (setq
      LL (vlax-safearray->list minpt)
      UR (vlax-safearray->list maxpt)
    ); setq
    (if (= (cdr (assoc 0 (entget ent))) "LINE")
      (setq ; then
        linesLL (if linesLL (mapcar 'min linesLL LL) LL)
        linesUR (if linesUR (mapcar 'max linesUR UR) UR)
      ); setq
      (setq txt ent txtLL LL txtUR UR); else [assumes one Text object]
    ); if
  ); repeat
  (command "_.move" txt ""
    "_none" (mapcar '/ (mapcar '+ txtLL txtUR) '(2 2 2)); from midpoint of Text
    "_none" (mapcar '/ (mapcar '+ linesLL linesUR) '(2 2 2)); to midpoint of Lines
  ); command
  (princ)
); defun
Kent Cooper, AIA
0 Likes
Message 6 of 11

dani-perez
Advocate
Advocate

Hello 

 

0 Likes
Message 7 of 11

dani-perez
Advocate
Advocate

Hello 

 

0 Likes
Message 8 of 11

Kent1Cooper
Consultant
Consultant

@dani-perez wrote:

....


 

It's actually easier for any single  object such as a Circle or a Polyline [rectangle, polygon, donut, rev-cloud, etc.] than with a group  of Lines as before, because the bounding box for figuring the Move destination is a one-shot evaluation, rather than a cumulative thing comparing the bounding boxes of the multiple Lines.  It would be easy to make a routine that could do it for such things, but some questions arise.  What kind(s) of things?  Any others than Circles or Polylines, such as maybe Ellipses, Splines, or Blocks?  Would you want to be able to select either  a Text object and one  shape object to move it into the middle of or  a Text object and multiple  things making up the surrounding shape?  [It would be easy with separate commands, but I can sort of imagine a possible approach that would handle either situation in one command -- I'd have to work it out.]

Kent Cooper, AIA
0 Likes
Message 9 of 11

dani-perez
Advocate
Advocate

Hello  

 

Thanks for replying again. You don't have to lose time on this if you dont want or you cant,I think I am asking for too much.

 

The idea will be any others that be a boundary, such as plines, circles, boundaries, Ellipses, Splines, or Blocks you know.

Then I select the text and the object and the text will move to its center.

 

Thanks a lot for you time. Dont worry about this, I am not in a hurry.

 

0 Likes
Message 10 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

@dani-perez wrote:

....

The idea will be any others that be a boundary, such as plines, circles, boundaries, Ellipses, Splines, or Blocks you know.

Then I select the text and the object and the text will move to its center.

....


 

This seems to do that [adding the possibility of Mtext], whether you select one  thing in addition to a Text/Mtext object, or multiple  things as in the Lines earlier.  But be aware of a few things:

 

If there are more than one  Text/Mtext objects in the selection, the first one it "sees"  will be Moved, and the other(s) will become part of the "shape"-defining collection of other objects.

 

Since it uses bounding boxes, in some cases you can get slightly different results than you might expect.  The bounding box of Mtext includes the full width of its defining box  [if other than zero], whether or not the content in it uses  that full width.  [There are routines around to pull the defining box in to match the width of the content, if you need to do that.]  And Splines can sometimes have a bounding box that extends farther than their visible shape.  And Blocks at other-than-zero rotation can get a bigger bounding box than they deserve, depending on their shape.  For example, here's:

RotatedBlockBoundingBox.PNG

a wall-mounted toilet Block, at the left at zero rotation, and at the right at 45 degrees.  The dashed red is its bounding box on the left [what you would expect] -- it is not  part of the Block, which is only the white and grey parts.  On the right, the yellow is the Block's bounding box -- note that it "reaches out" to the extents of the rotated virtual bounding box [the darker red] of the Block as if  that were actually part of the Block's contents, so the yellow bounding box goes beyond the visible extents of the rotated Block itself.

 

But given those caveats, try this:

(defun C:TCW ; = Text Centered Within other object(s)
  (/ ss sst txt txtLL txtUR n ent LL UR otherLL otherUR)
  (prompt "\nTo Move Text/Mtext to middle of other object(s), collectively")
  (setq
    ss (ssget)
    sst (ssget "_P" '((0 . "*TEXT")))
    txt (ssname sst 0); first Text/Mtext object in selection
  ); setq
  (ssdel txt ss); take Text/Mtext object out of overall selection
  (vla-getboundingbox (vlax-ename->vla-object txt) 'minpt 'maxpt)
  (setq
    txtLL (vlax-safearray->list minpt)
    txtUR (vlax-safearray->list maxpt)
  ); setq
  (repeat (setq n (sslength ss)); other object's/objects' extents
    (setq ent (ssname ss (setq n (1- n))))
    (vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)
    (setq
      LL (vlax-safearray->list minpt)
      UR (vlax-safearray->list maxpt)
      otherLL (if otherLL (mapcar 'min otherLL LL) LL)
      otherUR (if otherUR (mapcar 'max otherUR UR) UR)
    ); setq
  ); repeat
  (command "_.move" txt ""
    "_none" (mapcar '/ (mapcar '+ txtLL txtUR) '(2 2 2)); from midpoint of Text/Mtext
    "_none" (mapcar '/ (mapcar '+ otherLL otherUR) '(2 2 2)); to midpoint of other(s)
  ); command
  (princ)
); defun
Kent Cooper, AIA
0 Likes
Message 11 of 11

dani-perez
Advocate
Advocate

Hello 

 

Wow, it works really good. You are very good at coding and giving information about limitations and advices of your codes.

 

Thanks a lot for your effort!!

0 Likes