<?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 Adjust attribute text width in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/adjust-attribute-text-width/m-p/4308283#M48921</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to adjust width of attribute text so that it is not out of contained block. The attribute is set at left alignment and width factor &amp;lt;=1. Please see picture below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG width="164" title="test.png" border="0" alt="test.png" align="center" src="https://forums.autodesk.com/t5/image/serverpage/image-id/54934i51DB30A566BAFE0F/image-size/original?v=mpbl-1&amp;amp;px=-1" height="118" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jun 2013 07:32:13 GMT</pubDate>
    <dc:creator>ditran7577</dc:creator>
    <dc:date>2013-06-25T07:32:13Z</dc:date>
    <item>
      <title>Adjust attribute text width</title>
      <link>https://forums.autodesk.com/t5/net-forum/adjust-attribute-text-width/m-p/4308283#M48921</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to adjust width of attribute text so that it is not out of contained block. The attribute is set at left alignment and width factor &amp;lt;=1. Please see picture below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG width="164" title="test.png" border="0" alt="test.png" align="center" src="https://forums.autodesk.com/t5/image/serverpage/image-id/54934i51DB30A566BAFE0F/image-size/original?v=mpbl-1&amp;amp;px=-1" height="118" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2013 07:32:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/adjust-attribute-text-width/m-p/4308283#M48921</guid>
      <dc:creator>ditran7577</dc:creator>
      <dc:date>2013-06-25T07:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adjust attribute text width</title>
      <link>https://forums.autodesk.com/t5/net-forum/adjust-attribute-text-width/m-p/4309149#M48922</link>
      <description>&lt;P&gt;You need to find out the attribte text's width, and then you need to find out the allowed/desired width. Once you get these 2 widths, you can calculate the WidthFactor of AttributeReference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I put together some quick code that does it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(AttributeWidthFactor.MyCommands))]

namespace AttributeWidthFactor
{
    public class MyCommands
    {
        [CommandMethod("AttWidth")]
        public static void SetAttrWidthFactor()
        {
            Document dwg = Application.DocumentManager.MdiActiveDocument;
            Editor ed = dwg.Editor;

            //Pick an attributereference in a block
            PromptNestedEntityOptions opt = new 
                PromptNestedEntityOptions("\nPick an attribute:");
            PromptNestedEntityResult res = ed.GetNestedEntity(opt);

            if (res.Status == PromptStatus.OK)
            {
                if (res.ObjectId.ObjectClass.DxfName.ToUpper() == "ATTRIB")
                {
                    //Ask user to pick a distance as desired width for 
                    //the attribute to fit in. Based on the block, the width 
                    //could be a known value
                    PromptPointOptions popt = new 
                        PromptPointOptions("\nPick width base point:");
                    PromptPointResult pres = ed.GetPoint(popt);
                    if (pres.Status != PromptStatus.OK) return;
                    Point3d basePt = pres.Value;

                    PromptDistanceOptions dopt = 
                        new PromptDistanceOptions("\nPick width: ");
                    dopt.UseBasePoint = true;
                    dopt.BasePoint = basePt;

                    PromptDoubleResult dres = ed.GetDistance(dopt);
                    if (dres.Status != PromptStatus.OK) return;

                    //This is the width we want to fit the attribute text's width
                    double w = dres.Value;

                    using (Transaction tran = 
                        dwg.TransactionManager.StartTransaction())
                    {
                        AttributeReference att = (AttributeReference)tran.GetObject(
                            res.ObjectId, OpenMode.ForWrite);

                        //Get attribute's width, assuming it is placed horizontally
                        double aw = Math.Abs(att.GeometricExtents.MaxPoint.X 
                            - att.GeometricExtents.MinPoint.X);

                        //This is the WidthFactor
                        double factor = w / aw;
                        att.WidthFactor = factor;

                        tran.Commit();
                    }
                }
                else
                {
                    Application.ShowAlertDialog("Not an attribute!");
                }
            }
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The code will stretch or narrow the attribute to fit it into a given width.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2013 21:24:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/adjust-attribute-text-width/m-p/4309149#M48922</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2013-06-25T21:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Adjust attribute text width</title>
      <link>https://forums.autodesk.com/t5/net-forum/adjust-attribute-text-width/m-p/4310946#M48923</link>
      <description>&lt;P&gt;Thanks a lot. It's OK.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 01:08:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/adjust-attribute-text-width/m-p/4310946#M48923</guid>
      <dc:creator>ditran7577</dc:creator>
      <dc:date>2013-06-27T01:08:26Z</dc:date>
    </item>
  </channel>
</rss>

