Space at end of line in MTEXT

Space at end of line in MTEXT

dvertz
Collaborator Collaborator
3,624 Views
20 Replies
Message 1 of 21

Space at end of line in MTEXT

dvertz
Collaborator
Collaborator

I am wondering if anyone has a good solution to adding a space at the end-of-the line in MTEXT.

Why to I want this? Simply to align text with a line to the right of the MTEXT.

For example: Draw a line. Create an MTEXT object with the number 1, set the justification to middle right. Now place the insert point on the end-of-the line. By adding a space to end-of-line, it creates white space between the end-of-line and the line but keeps the MTEXT in alignment with the line. This can easily be done with TEXT (DTEXT), but not with MTEXT because the MTEXT gets all spacing removed at end-of-line.

Civil 3D 2026,
Windows 11 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


0 Likes
3,625 Views
20 Replies
Replies (20)
Message 2 of 21

pendean
Community Legend
Community Legend

@dvertz May I ask, have you considered this combo as a dynamic block (line and "text") so what you want is always true all the time?

 

And a dumb question... why the need for MTEXT and not just TEXT? the former is not some sort of replacement for the latter.

0 Likes
Message 3 of 21

dvertz
Collaborator
Collaborator

Thanks for the suggestion. I might try a dynamic block next time I need to use this combination of entities.

 

I prefer MTEXT for its options that TEXT does not have. I use MTEXT everywhere, for decades now and have always had issues with the space getting removed.

Civil 3D 2026,
Windows 11 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


0 Likes
Message 4 of 21

pendean
Community Legend
Community Legend

@dvertz wrote:

...have always had issues with the space getting removed.


AFAIK there is no way to change how MTEXT works with spaces so far through 2024-versions: a letter or period or something is needed, perhaps you can assign it to RGB color 255/255/255 every ingle time you use an MTEXT all the time, then learn to ignore it while drafting since it will be visible (but never print).

 

Dynamic Block would be so much better.

0 Likes
Message 5 of 21

Kent1Cooper
Consultant
Consultant

@dvertz wrote:

.... the MTEXT gets all spacing removed at end-of-line.


I find that it doesn't remove trailing spaces from the content [you can see them in editing], but it ignores them in right justifications, and uses only the visible character content.  That's particularly odd, because it does not ignore leading spaces in left justifications.  [The bounding box uses the same double standard.]

 

I tried some ALT+ space options [ALT+255 & ALT+0160], but they are not treated any differently than a regular space [which is ALT+32].

 

If you're using a Style with an .shx font, you may be able to get what you want by putting a space and a | "pipe" character at the end.  Thatis a single vertical line in many .shx fonts [not all, e.g. ROMAND & ROMANT double it up, and SCRIPT types have it diagonal], and would coincide with your alignment Line.  But it would need the plotted weight of the Mtext to be no greater than that of the alignment Line.  If the alignment Line is heavy enough, it could also conceal a pipe character in at least some .ttf fonts.

Kent Cooper, AIA
0 Likes
Message 6 of 21

dvertz
Collaborator
Collaborator

Thanks for your solutions. I really thought the Non-Breaking space would be the one to do it, yet it does not.

 

After getting the reply from pendean, I started think about fonts. So I went through the list on my machine and found that there were some odd fonts that had blank characters that would work. But what if some else open the drawing? What would they get if they do not have the font?

 

After getting your reply I went back to the font list and looked a little deeper. I found that "Courier" has a blank character at code 0xA0 that works very well. And everyone should have that font on their machine. Right?

 

But like you pointed out, why does the space work at the beginning of the line but not at the end of line for right justified text? What were the programmers thinking?

Civil 3D 2026,
Windows 11 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


0 Likes
Message 7 of 21

pendean
Community Legend
Community Legend

@dvertz wrote:

...But what if some else open the drawing? What would they get if they do not have the font?...


You will always have to share your fonts with them 100% of the time if you want your setup to be replicated over there.

 

A custom dynamic block is starting to look real good about now, right?

0 Likes
Message 8 of 21

Kent1Cooper
Consultant
Consultant

@pendean wrote:

.... have you considered this combo as a dynamic block (line and "text") ....


If you're going to go the route of a Block, I don't see that it needs to be dynamic.  An ordinary one with a right-justified Attribute and an insertion point off to the right of the Attribute would do.  The Line part would not need to be part of it, but any number of them could be planted along a reference Line.  Unless I'm misunderstanding something....

Kent Cooper, AIA
0 Likes
Message 9 of 21

pendean
Community Legend
Community Legend

@Kent1Cooper wrote:

@pendean wrote:

.... have you considered this combo as a dynamic block (line and "text") ....


If you're going to go the route of a Block, I don't see that it needs to be dynamic.  An ordinary one with a right-justified Attribute and an insertion point off to the right of the Attribute would do.  The Line part would not need to be part of it, but any number of them could be planted along a reference Line.  Unless I'm misunderstanding something....


I assumed that "line" might change in length based solely on the replies, but I could be wrong: if it is truly static I wonder why it was never a block, perhaps multi-line ATTRIBUTEs could come into play too since there seems to be a need for MTEXT abilities.

0 Likes
Message 10 of 21

Kent1Cooper
Consultant
Consultant

@dvertz wrote:

...: Draw a line. Create an MTEXT object with the number 1, set the justification to middle right. Now place the insert point on the end-of-the line. ....


Wait a minute....  I was probably misunderstanding, thinking of holding content off a vertical Line, like the left side here:

Kent1Cooper_0-1704476960143.png

but reading it again, it sounds more like the right side.  Still, a Block with its insertion point off the right of Attribute [M]text would do, and if the Line length varies but it's always a single horizontal Line [not, say, the end of a Polyline that might bend, etc.], then a dynamic Block could be a good solution.

Kent Cooper, AIA
0 Likes
Message 11 of 21

Kent1Cooper
Consultant
Consultant

Another possibility:

 

Use a LEADER for the Line, and have the Mtext be its associated Annotation.  You can define a Dimension Style for Leaders to have no arrowhead, and you have choices for the vertical relationship between the Annotation and the Leader's tail.  It can be a single "line," or bend around, etc.  The DIMGAP System Variable defines the spacing between the end of the tail and the Annotation, which will take the place of your intended space, and will work the same from either left or right.  If you Move the Annotation, the Leader's tail will follow.

Kent Cooper, AIA
0 Likes
Message 12 of 21

dvertz
Collaborator
Collaborator

I have returned to this issue. And I have decided to try the dynamic block route. Now I am running into a couple of problems that I can't seem to resolve.

1. The attributes I have inserted into the dynamic block, will not appear when I close the editor.

2. I can't seem to find a way to get the numbers to auto increment with the array.

I tried changing the attributes to mtext. The mtext will appear, but I am still stuck getting the numbers to auto increment.

I have attached the current state of the block.

Any help is appreciated.

Civil 3D 2026,
Windows 11 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


0 Likes
Message 13 of 21

Kent1Cooper
Consultant
Consultant

@dvertz wrote:

....

1. The attributes I have inserted into the dynamic block, will not appear when I close the editor.

....


ATTSYNC after editing the Block.

Kent Cooper, AIA
0 Likes
Message 14 of 21

dvertz
Collaborator
Collaborator

Thanks Kent. That got the one on the left to show up, but the one on the right still did not show.

Civil 3D 2026,
Windows 11 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


0 Likes
Message 15 of 21

vladimir_michl
Advisor
Advisor

For the right-aligned MTexts, the trailing space is considered a "potential new line" and so ignored. You can put a non-breaking space there - Alt+0160, represented by the MText control code \~.

 

If you want to replace it in all existing MTexts, you can use e.g. the srxText utility (free), the SRXTEXT2 command and use the Regular expression replacement:

search: (.+)\s

replace: $1\~

 

Vladimir Michl, www.arkance-systems.cz  -  www.cadforum.cz

 

0 Likes
Message 16 of 21

dvertz
Collaborator
Collaborator

vladimir,

Thanks for the reply. However, as pointed out in message 6, non-breaking spaces do no allow the bounding box (and therefore the justification) to be adjusted to the end of the spaced text. The bounding box (and justification) will adjust to the visible text every time.

Civil 3D 2026,
Windows 11 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


0 Likes
Message 17 of 21

vladimir_michl
Advisor
Advisor

But I was trying that (ACAD 2024.1) and the NBR space was counted, the text was moved left after it was added.

 

Vladimir Michl, www.arkance-systems.cz  -  www.cadforum.cz

 

0 Likes
Message 18 of 21

dvertz
Collaborator
Collaborator

Seems something is different on your computer than on mine. I checked the version I have, it is 2024.1. But I can't get the about box to display will in the mtext editor. Are you sure that you are using MTEXT and not TEXT. As pointed out, TEXT will adjust. MTEXT will not.

I highlighted the non-breaking space in this image. As you can see, the bounding box did not adjust. But thanks for trying.

2024-01-31_111545.png

Civil 3D 2026,
Windows 11 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


0 Likes
Message 19 of 21

vladimir_michl
Advisor
Advisor

Now when retrying on another computer it behaves like yours. But maybe I have added the NBR space after the original space (this works fine) or I have experimented with other whitespace characters like ZWJ.

 

So the replacement sequence is rather:

search: (.+\s)

replace: $1\~

 

mtextnbr.gif

 

Vladimir Michl, www.arkance-systems.cz  -  www.cadforum.cz

 

Message 20 of 21

smithjohns401
Explorer
Explorer

It’s great you found that "Courier" has a blank character at code 0xA0, which works and should be available on most machines. The issue with spaces behaving differently at the start versus the end of right-justified text likely stems from how the text rendering engine interprets spaces, possibly treating alignment differently in those cases.

0 Likes