<?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 Re: c# code to add new attribute value to a block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671038#M23148</link>
    <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;Sorry, but it's still not clear to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you want to create a custom AutoCAD command or, again, do that from a standalone executable, which is a completely different (and not so easy) process?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is the block selected by the user a particular block?&lt;/SPAN&gt; &lt;SPAN&gt;If so, is it dynamic?&lt;/SPAN&gt; &lt;SPAN&gt;What's its name?&lt;/SPAN&gt; D&lt;SPAN&gt;oes it contain one or more attributes?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;Is it to add an attribute or modify the value of an existing attribute?&lt;/SPAN&gt; &lt;SPAN&gt;In any case, what is the label of the attribute?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;And, if possible, show what you have done so far.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2019 09:54:17 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2019-03-20T09:54:17Z</dc:date>
    <item>
      <title>c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8670586#M23145</link>
      <description>&lt;P&gt;I wanted to add new attribute value to block by opening a autocad drawing &amp;amp; selecting block for which the new attribute value should be added&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 05:53:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8670586#M23145</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-20T05:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8670716#M23146</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In view of all your recent posts, could you elaborate about the context in which you wish to do this (in-process vs out-of-process)?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 07:18:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8670716#M23146</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-20T07:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8670914#M23147</link>
      <description>&lt;P&gt;I want to open a autocad drawing and select the block &amp;amp; in the program I want a textbox &amp;amp; a button the value given the user in the textbox should be added to the selected block by clicking on the button&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 09:08:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8670914#M23147</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-20T09:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671038#M23148</link>
      <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;Sorry, but it's still not clear to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you want to create a custom AutoCAD command or, again, do that from a standalone executable, which is a completely different (and not so easy) process?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is the block selected by the user a particular block?&lt;/SPAN&gt; &lt;SPAN&gt;If so, is it dynamic?&lt;/SPAN&gt; &lt;SPAN&gt;What's its name?&lt;/SPAN&gt; D&lt;SPAN&gt;oes it contain one or more attributes?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;Is it to add an attribute or modify the value of an existing attribute?&lt;/SPAN&gt; &lt;SPAN&gt;In any case, what is the label of the attribute?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;And, if possible, show what you have done so far.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 09:54:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671038#M23148</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-20T09:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671049#M23149</link>
      <description>&lt;P&gt;imagine I have a autocad drawing it contains "n" number of block &amp;amp; each block has many attributes but now the user wants to add a new attribute value for a particular block which he wants to be added so he has to select the block first &amp;amp; then add the new attribute to that block&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 10:00:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671049#M23149</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-20T10:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671065#M23150</link>
      <description>&lt;P&gt;Do you want to only add an attribute reference to the selected block reference or add an attribute definition to the block definition and then synchronize all the references?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 10:13:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671065#M23150</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-20T10:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671089#M23151</link>
      <description>&lt;P&gt;I would like to add an attribute reference to the selected block reference.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 10:33:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671089#M23151</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-20T10:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671688#M23152</link>
      <description>&lt;P&gt;You certainly know that this kind of attribute reference will be erased if the ATTSYNC command is run for this block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example of AutoCAD plugin (i.e., a class library DLL which have to be netloaded in AutoCAD) containg custom command which shows a little dialog box to let the user enter the attribute value, then it prompts the user to select a block reference and specify the attribute insertion point.&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace AmazingRequestSample
{
    public class Commands
    {
        [CommandMethod("ADDATTREF")]
        public static void AddAttributeReference()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // display a dialog box to get the attribute value
            string attValue;
            using (var dialog = new AttributeValueDialog())
            {
                if (Application.ShowModalDialog(dialog) != System.Windows.Forms.DialogResult.OK)
                    return;
                attValue = dialog.AttributeValue;
            }

            // prompts the user to select a block reference
            var peo = new PromptEntityOptions("\nSelect block reference: ");
            peo.SetRejectMessage("\nSelected object is not a block reference.");
            peo.AddAllowedClass(typeof(BlockReference), true);
            var per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK)
                return;

            // prompts the user to specify the attribute insertion point
            var ppr = ed.GetPoint("\nSpecify the attribute insertion point: ");
            if (ppr.Status != PromptStatus.OK)
                return;
            var insPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);

            // create the attribute reference and add it to the attribute collection of the selected block
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var br = (BlockReference)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
                var attRef = new AttributeReference(insPoint, attValue, "TAG", db.Textstyle)
                { LockPositionInBlock = false };
                br.AttributeCollection.AppendAttribute(attRef);
                tr.AddNewlyCreatedDBObject(attRef, true);
                tr.Commit();
            }
        }
    }
}
&lt;/PRE&gt;
&lt;P&gt;The dialog box&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AttributeValueDialog.png" style="width: 267px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/616191iC0B79BA348AAC462/image-size/large?v=v2&amp;amp;px=999" role="button" title="AttributeValueDialog.png" alt="AttributeValueDialog.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;using System.Windows.Forms;

namespace AmazingRequestSample
{
    public partial class AttributeValueDialog : Form
    {
        public AttributeValueDialog()
        {
            InitializeComponent();
            AcceptButton = buttonOk;
            CancelButton = buttonCancel;
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;
        }

        public string AttributeValue =&amp;gt; textBoxAttValue.Text;
    }
}&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:20:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8671688#M23152</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-20T14:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673437#M23153</link>
      <description>&lt;P&gt;Thank you so much for ur quick response&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 05:26:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673437#M23153</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-21T05:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673483#M23154</link>
      <description>&lt;P&gt;&lt;FONT style="background-color: #ffffff;"&gt;I'm getting error in the below line&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT style="background-color: #ffffff;"&gt;var attRef = new AttributeReference(insPoint, attValue, "TAG", db.Textstyle) { LockPositionInBlock = false };&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT style="background-color: #ffffff;"&gt;Use of unassigned local variable "attValue" but i have assigned the variable&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 06:38:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673483#M23154</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-21T06:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673597#M23155</link>
      <description>&lt;P&gt;I do not have such error.&lt;/P&gt;
&lt;P&gt;Is it an error at edition time (which prevent the compilation in Visual Studio) or an exception thrown at running time?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 07:53:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673597#M23155</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-21T07:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673653#M23156</link>
      <description>&lt;P&gt;I&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #666666; font-family: 'Artifakt',Tahoma,Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;t is an error at edition time &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 08:27:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673653#M23156</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-21T08:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673830#M23157</link>
      <description>&lt;P&gt;Your project should contains 2 classes:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Commands.cs where the command is defined&lt;/LI&gt;
&lt;LI&gt;AttributeValueDialog.cs the dialog box decription&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AmazingRequestSample.png" style="width: 305px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/616565iA9DB5A207E7AFAD6/image-size/large?v=v2&amp;amp;px=999" role="button" title="AmazingRequestSample.png" alt="AmazingRequestSample.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 10:09:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673830#M23157</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-21T10:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673866#M23158</link>
      <description>&lt;P&gt;Even I have done the same thing. But I m getting a error&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Error.jpg" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/616570i11685CEC2B0E4332/image-size/large?v=v2&amp;amp;px=999" role="button" title="Error.jpg" alt="Error.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 10:29:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673866#M23158</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-21T10:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673937#M23159</link>
      <description>&lt;P&gt;You didn't correctly the code i posted.&lt;/P&gt;
&lt;P&gt;Replace:&lt;/P&gt;
&lt;PRE&gt;            string attValue;
            using (var dialog = new AttributeValueDialog())
            {
                if (Application.ShowModalDialog(dialog) != System.Windows.Forms.DialogResult.OK)
                    attValue = dialog.AttributeValue;
            }&lt;/PRE&gt;
&lt;P&gt;with:&lt;/P&gt;
&lt;PRE&gt;            string attValue;
            using (var dialog = new AttributeValueDialog())
            {
                if (Application.ShowModalDialog(dialog) != System.Windows.Forms.DialogResult.OK)
                    return;
                attValue = dialog.AttributeValue;
            }&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Mar 2019 11:01:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673937#M23159</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-21T11:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673948#M23160</link>
      <description>&lt;P&gt;Ya I m sorry. Thank you for correcting me&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 11:07:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8673948#M23160</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-21T11:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8680634#M23161</link>
      <description>&lt;P&gt;Thank you sooo much it worked successfully&lt;/P&gt;
&lt;P&gt;Now I want an enhancement in that code. I want to add the attribute value by selecting multiple blocks how can we do that??&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 08:26:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8680634#M23161</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-25T08:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8680765#M23162</link>
      <description>&lt;P&gt;You can use a &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-DE15FB0E-8669-4D58-9261-DB4CF86F89F3" target="_blank" rel="noopener"&gt;selection set&lt;/A&gt; got with Editor.GetSelection() and a &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-D9FB23AE-D853-4D00-A910-4F66FCC4607A" target="_blank" rel="noopener"&gt;selection filter&lt;/A&gt; instead of Editor.GetEntity() and then, for each selected entity, prompt the user to specify the insertion point and add the attribute reference.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 09:22:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8680765#M23162</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-25T09:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8680775#M23163</link>
      <description>&lt;P&gt;Can u send me the code&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 09:27:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8680775#M23163</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-25T09:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: c# code to add new attribute value to a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8681061#M23164</link>
      <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN class=""&gt;Claiming a code is not a good way to learn&lt;/SPAN&gt;&lt;/SPAN&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("ADDATTREF")]
        public static void AddAttributeReference()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // display a dialog box to get the attribute value
            string attValue;
            using (var dialog = new AttributeValueDialog())
            {
                if (Application.ShowModalDialog(dialog) != System.Windows.Forms.DialogResult.OK)
                    return;
                attValue = dialog.AttributeValue;
            }

            // prompts the user to select block references
            var filter = new SelectionFilter(new[] { new TypedValue(0, "INSERT") });
            var psr = ed.GetSelection(filter);
            if (psr.Status != PromptStatus.OK)
                return;
            dynamic acadApp = Application.AcadApplication;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                foreach (SelectedObject so in psr.Value)
                {
                    var br = (BlockReference)tr.GetObject(so.ObjectId, OpenMode.ForWrite);
                    br.Highlight();
                    // prompts the user to specify the attribute insertion point
                    var ppr = ed.GetPoint("\nSpecify the attribute insertion point: ");
                    br.Unhighlight();
                    if (ppr.Status != PromptStatus.OK)
                        continue;
                    var insPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
                    var attRef = new AttributeReference(insPoint, attValue, "TAG", db.Textstyle)
                    { LockPositionInBlock = false };
                    br.AttributeCollection.AppendAttribute(attRef);
                    tr.AddNewlyCreatedDBObject(attRef, true);
                    db.TransactionManager.QueueForGraphicsFlush();
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2019 11:22:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-code-to-add-new-attribute-value-to-a-block/m-p/8681061#M23164</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-25T11:22:28Z</dc:date>
    </item>
  </channel>
</rss>

