<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Width of text in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/width-of-text/m-p/7217647#M30675</link>
    <description>&lt;P&gt;I am trying to determine the width of the longest text string in order to set a table column width. Geometric extents only work if the text is added to the database - I'd rather not do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are some examples of "ExtentsBox" (like &lt;A href="http://adndevblog.typepad.com/autocad/2012/05/how-to-load-graphicsinterfacetextstyle-from-a-textstyletablerecord-in-net.html" target="_self"&gt;&amp;gt;&amp;gt;this one&amp;lt;&amp;lt;&amp;lt;&lt;/A&gt;&amp;nbsp;from Phillipe Leefsma) but that is sort of old (May 2012). &amp;nbsp;If I need to use that, how do I determine the "EntryPoint"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is another example&amp;nbsp;&lt;A href="http://adndevblog.typepad.com/autocad/2012/05/actual-width-and-height-of-a-text-string.html" target="_self"&gt;&amp;gt;&amp;gt;here&amp;lt;&amp;lt;&lt;/A&gt;&amp;nbsp;from Balaji Ramamoorthy that includes instructions on how to obtain the "mangled name" using "dumpbin" but I am not sure what to look for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;[DllImport("acdb18.dll",&lt;BR /&gt; CharSet = CharSet.Unicode,&lt;BR /&gt; CallingConvention = CallingConvention.Cdecl,&lt;BR /&gt; EntryPoint =&lt;BR /&gt; "?fromAcDbTextStyle@@YA?AW4ErrorStatus@Acad@@AAVAcGiTextStyle@@PB_W@Z")]&lt;BR /&gt;private static extern ErrorStatus fromAcDbTextStyle(&lt;BR /&gt; System.IntPtr style, string styleName);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;translated to something I can use in Civil3D 2016 (I believe the entrypoint is in acdb20.dll).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TIA&lt;/P&gt;</description>
    <pubDate>Mon, 10 Jul 2017 19:52:35 GMT</pubDate>
    <dc:creator>fieldguy</dc:creator>
    <dc:date>2017-07-10T19:52:35Z</dc:date>
    <item>
      <title>Width of text</title>
      <link>https://forums.autodesk.com/t5/net-forum/width-of-text/m-p/7217647#M30675</link>
      <description>&lt;P&gt;I am trying to determine the width of the longest text string in order to set a table column width. Geometric extents only work if the text is added to the database - I'd rather not do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are some examples of "ExtentsBox" (like &lt;A href="http://adndevblog.typepad.com/autocad/2012/05/how-to-load-graphicsinterfacetextstyle-from-a-textstyletablerecord-in-net.html" target="_self"&gt;&amp;gt;&amp;gt;this one&amp;lt;&amp;lt;&amp;lt;&lt;/A&gt;&amp;nbsp;from Phillipe Leefsma) but that is sort of old (May 2012). &amp;nbsp;If I need to use that, how do I determine the "EntryPoint"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is another example&amp;nbsp;&lt;A href="http://adndevblog.typepad.com/autocad/2012/05/actual-width-and-height-of-a-text-string.html" target="_self"&gt;&amp;gt;&amp;gt;here&amp;lt;&amp;lt;&lt;/A&gt;&amp;nbsp;from Balaji Ramamoorthy that includes instructions on how to obtain the "mangled name" using "dumpbin" but I am not sure what to look for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;[DllImport("acdb18.dll",&lt;BR /&gt; CharSet = CharSet.Unicode,&lt;BR /&gt; CallingConvention = CallingConvention.Cdecl,&lt;BR /&gt; EntryPoint =&lt;BR /&gt; "?fromAcDbTextStyle@@YA?AW4ErrorStatus@Acad@@AAVAcGiTextStyle@@PB_W@Z")]&lt;BR /&gt;private static extern ErrorStatus fromAcDbTextStyle(&lt;BR /&gt; System.IntPtr style, string styleName);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;translated to something I can use in Civil3D 2016 (I believe the entrypoint is in acdb20.dll).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TIA&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:52:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/width-of-text/m-p/7217647#M30675</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2017-07-10T19:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Width of text</title>
      <link>https://forums.autodesk.com/t5/net-forum/width-of-text/m-p/7217960#M30676</link>
      <description>&lt;P&gt;I was able to get what I needed using System.Drawing. &amp;nbsp;The font we are using is Arial.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using (var image = new Bitmap(1, 1))&lt;BR /&gt;{&lt;BR /&gt; using (var g = Graphics.FromImage(image))&lt;BR /&gt; {&lt;BR /&gt; Font usefont = new Font("Arial", 10); // 10 is pixels&lt;BR /&gt; SizeF txtwidth = new SizeF();&lt;BR /&gt; Single widesttxt = 0.0F;&lt;BR /&gt; List&amp;lt;string&amp;gt; checkwidths = new List&amp;lt;string&amp;gt;() { "s1", "s2", "morestrings" };&lt;BR /&gt; foreach (string s in checkwidths)&lt;BR /&gt; {&lt;BR /&gt; txtwidth = g.MeasureString(s, usefont);&lt;BR /&gt; Single twidth = txtwidth.Width;&lt;BR /&gt; if (twidth &amp;gt; widesttxt)&lt;BR /&gt;widesttxt = twidth;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;// round up to nearest 10, convert to int, and add 10&lt;BR /&gt;int columnwidth = (int)(Math.Ceiling(widesttxt / 10.0d) * 10) + 10;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 21:45:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/width-of-text/m-p/7217960#M30676</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2017-07-10T21:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Width of text</title>
      <link>https://forums.autodesk.com/t5/net-forum/width-of-text/m-p/7218695#M30677</link>
      <description>&lt;P&gt;Obviosly too late &lt;SPAN class="st"&gt;but nevertheless&lt;/SPAN&gt; like to share my solution with you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my Table i'll add content first and remember the longest size.&lt;/P&gt;
&lt;P&gt;Then at the end set the column width to the greatest value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll use one MText to get the sizes&amp;nbsp; but there is no need to add this MText to the database&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using (var mText = new MText())&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mText.SetDatabaseDefaults(_db);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mText.Location = Point3d.Origin;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mText.Attachment = AttachmentPoint.BottomLeft;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Loop&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mText.TextStyleId = titleCell.TextStyleId.Value;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mText.Width = 0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mText.Contents = titleCell.Contents[0].TextString;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wCol = (mText.ActualWidth &amp;gt; wCol) ? mText.ActualWidth : wCol;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; wCol += 2 * TableTextMargin + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; table.Columns[i].Width=wCol;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table.GenerateLayout();&lt;BR /&gt;&amp;nbsp;//table.RecordGraphicsModified(true);&lt;BR /&gt;table.RecomputeTableBlock(true);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 07:48:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/width-of-text/m-p/7218695#M30677</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2017-07-11T07:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Width of text</title>
      <link>https://forums.autodesk.com/t5/net-forum/width-of-text/m-p/7218868#M30678</link>
      <description>&lt;P&gt;&lt;A href="https://www.theswamp.org/index.php?topic=50493.msg556106#msg556106" target="_blank"&gt;https://www.theswamp.org/index.php?topic=50493.msg556106#msg556106&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Autodesk.AutoCAD.GraphicsInterface.TextStyle();&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;without the mangling&lt;/P&gt;
&lt;P&gt;and the text does not need to be in the database&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        //================================================
        [CommandMethod("TextExtentsTest2")]
        static public void TextWidth() {
            var ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            var ts = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
            ts.FromTextStyleTableRecord("Standard");
            ts.TextSize = 25;
            ed.WriteMessage("AP " + ts.ExtentsBox("AP", true, false, null).MaxPoint.X);
            ed.WriteMessage("\nAPPLE " + ts.ExtentsBox("APPLE", true, false, null).MaxPoint.X);
            ed.WriteMessage("\nAPPLESAUCE " + ts.ExtentsBox("APPLESAUCE", true, false, null).MaxPoint.X);
        }
        //================================================
 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 09:24:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/width-of-text/m-p/7218868#M30678</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2017-07-11T09:24:54Z</dc:date>
    </item>
  </channel>
</rss>

