block textstring's width

block textstring's width

Anonymous
Not applicable
371 Views
2 Replies
Message 1 of 3

block textstring's width

Anonymous
Not applicable
i insert a block,and the block's textstirng is input by the user, and sometimes the textstring is a litter long, how do i judge the textstring is longer than the block's width. and in textstring,there may contain chinese charactor. thanks
0 Likes
372 Views
2 Replies
Replies (2)
Message 2 of 3

cadMeUp
Collaborator
Collaborator
You can try this:

Autodesk.AutoCAD.GraphicsInterface.TextStyle txtStyle = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
txtStyle.StyleName = "Standard";
txtStyle.TextSize = 1.0;
txtStyle.XScale = 1.0;
txtStyle.Vertical = false;

Extents2d ext = txtStyle.ExtentsBox("TEXTSTRING", true, false, null);
double width = ext.MaxPoint.X - ext.MinPoint.X;
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thanks a lot
and i solve it in another way.
the width is fixed for a block, and the max bytes is also fixed,
so i use System.Text.Encoding.Default.GetByteCount(string) to count all words in bytes number including chinese charactor.
0 Likes