<?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: Attribute alignment in the existing block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/attribute-alignment-in-the-existing-block/m-p/7308958#M30103</link>
    <description>&lt;P&gt;Adding HostApplicationServices.WorkingDatabase&amp;nbsp; to my code fixed the issue.&lt;/P&gt;&lt;P&gt;I got the solution from this link &lt;A href="https://forums.autodesk.com/t5/net/modify-attributes/m-p/5631971/highlight/true#M44447" target="_blank"&gt;https://forums.autodesk.com/t5/net/modify-attributes/m-p/5631971/highlight/true#M44447&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This happens when AutoCAD is not expecting to be dealing with a database that is not associated with its current database list, or when AutoCAD wrongly decides that your side database is actually associated with its database list thus keeping a reference to the database. If this happens, you can set the working database yourself, but be *very careful* – make sure you set and reset the working database only where you need to do it, keep the redirection short and sweet and never forget to set it back&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply _gile. I am new to AutoCAD so I was using various bits of code to make it work.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Aug 2017 18:34:04 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-08-17T18:34:04Z</dc:date>
    <item>
      <title>Attribute alignment in the existing block</title>
      <link>https://forums.autodesk.com/t5/net-forum/attribute-alignment-in-the-existing-block/m-p/7306323#M30101</link>
      <description>&lt;P&gt;I am trying to run an Add ins in AutoCAD which modifies attribute text. The Text &amp;nbsp;always aligns to the right, after the program is run.&lt;/P&gt;&lt;P&gt;I want it to to set to the basecenter position. It is very similar to this issue discussed here (&lt;A href="https://forums.autodesk.com/t5/net/attribute-alignment/td-p/3182590" target="_blank"&gt;https://forums.autodesk.com/t5/net/attribute-alignment/td-p/3182590&lt;/A&gt;) but the solution is not working in my case.&lt;/P&gt;&lt;P&gt;Please help me with the solution , here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;private static void SetBlockAttributeValue(Autodesk.AutoCAD.DatabaseServices.Database acDb, string layout, string blockName, string attributeName, string attributeValue)&lt;BR /&gt;{&lt;BR /&gt;var center = new Point3d(1, 1, 0);&lt;BR /&gt;using (Transaction trans = acDb.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;// HostApplicationServices.WorkingDatabase = acDb;&lt;BR /&gt;DBDictionary dbDictionary = (DBDictionary)trans.GetObject(acDb.LayoutDictionaryId, OpenMode.ForRead);&lt;BR /&gt;foreach (DictionaryEntry de in dbDictionary)&lt;BR /&gt;{&lt;BR /&gt;if (string.Compare(de.Key.ToString(), layout, true) == 0)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Layout layout1 = (Layout)trans.GetObject((ObjectId)de.Value, OpenMode.ForWrite);&lt;BR /&gt;BlockTable blockTable;&lt;BR /&gt;blockTable = trans.GetObject(acDb.BlockTableId, OpenMode.ForRead) as BlockTable;&lt;BR /&gt;// BlockTable blockTable = (BlockTable)trans.GetObject(acDb.BlockTableId, OpenMode.ForRead);&lt;BR /&gt;BlockTableRecord blockTableRecord = (BlockTableRecord)trans.GetObject(layout1.BlockTableRecordId, OpenMode.ForWrite);&lt;BR /&gt;&lt;BR /&gt;using (AttributeDefinition acAttDef = new AttributeDefinition())&lt;BR /&gt;{&lt;BR /&gt;// acAttDef.Position = new Point3d(12, 4, 0);&lt;BR /&gt;acAttDef.TextString = attributeValue; //attributeValue;&lt;/P&gt;&lt;P&gt;acAttDef.Height = 1;&lt;BR /&gt;acAttDef.Justify = AttachmentPoint.BaseCenter;&lt;BR /&gt;blockTableRecord.AppendEntity(acAttDef);&lt;/P&gt;&lt;P&gt;blockTable.UpgradeOpen();&lt;BR /&gt;blockTable.Add(blockTableRecord);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;foreach (ObjectId entityId in blockTableRecord)&lt;BR /&gt;{&lt;BR /&gt;Entity entity = (Entity)trans.GetObject(entityId, OpenMode.ForRead);&lt;BR /&gt;if (entity.GetType() == typeof(BlockReference))&lt;BR /&gt;{&lt;BR /&gt;BlockReference blockReference = (BlockReference)entity;&lt;BR /&gt;AttributeCollection collection = blockReference.AttributeCollection;&lt;BR /&gt;foreach (ObjectId id in collection)&lt;BR /&gt;{&lt;BR /&gt;DBObject dbObject = trans.GetObject(id, OpenMode.ForWrite);&lt;BR /&gt;AttributeReference reference = (AttributeReference)dbObject;&lt;BR /&gt;if (reference != null)&lt;BR /&gt;{&lt;BR /&gt;if (string.Compare(reference.Tag, attributeName, true) == 0)&lt;BR /&gt;{&lt;BR /&gt;reference.UpgradeOpen();&lt;BR /&gt;// reference.TextString = attributeValue;&lt;BR /&gt;reference.SetAttributeFromBlock(acAttDef, blockReference.BlockTransform);&lt;BR /&gt;// reference.Position = acAttDef.Position.TransformBy(blockReference.BlockTransform);&lt;BR /&gt;reference.Justify = AttachmentPoint.BaseCenter;&lt;BR /&gt;reference.AlignmentPoint = center;&lt;BR /&gt;reference.AdjustAlignment(acDb);&lt;BR /&gt;// reference.TextString = attributeValue;&lt;BR /&gt;&lt;BR /&gt;reference.TextString = acAttDef.TextString;&lt;BR /&gt;blockReference.AttributeCollection.AppendAttribute(reference);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;trans.Commit();&lt;BR /&gt;//HostApplicationServices.WorkingDatabase = acDb;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 21:27:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attribute-alignment-in-the-existing-block/m-p/7306323#M30101</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-16T21:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute alignment in the existing block</title>
      <link>https://forums.autodesk.com/t5/net-forum/attribute-alignment-in-the-existing-block/m-p/7306975#M30102</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry but your code doesn't help to understand your request.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It add an attribute definition to a layout BlockTableRecord and then add a new attribute reference to all block references in this layout.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: please, when you post some code, use the "Insert code" button: &amp;lt;/&amp;gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 07:12:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attribute-alignment-in-the-existing-block/m-p/7306975#M30102</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-08-17T07:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute alignment in the existing block</title>
      <link>https://forums.autodesk.com/t5/net-forum/attribute-alignment-in-the-existing-block/m-p/7308958#M30103</link>
      <description>&lt;P&gt;Adding HostApplicationServices.WorkingDatabase&amp;nbsp; to my code fixed the issue.&lt;/P&gt;&lt;P&gt;I got the solution from this link &lt;A href="https://forums.autodesk.com/t5/net/modify-attributes/m-p/5631971/highlight/true#M44447" target="_blank"&gt;https://forums.autodesk.com/t5/net/modify-attributes/m-p/5631971/highlight/true#M44447&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This happens when AutoCAD is not expecting to be dealing with a database that is not associated with its current database list, or when AutoCAD wrongly decides that your side database is actually associated with its database list thus keeping a reference to the database. If this happens, you can set the working database yourself, but be *very careful* – make sure you set and reset the working database only where you need to do it, keep the redirection short and sweet and never forget to set it back&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply _gile. I am new to AutoCAD so I was using various bits of code to make it work.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 18:34:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attribute-alignment-in-the-existing-block/m-p/7308958#M30103</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-17T18:34:04Z</dc:date>
    </item>
  </channel>
</rss>

