<?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: Update BlockTableRecord without Transaction in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7144808#M31034</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST")]
        public void Test()
        {
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            using (var btr = (BlockTableRecord)SymbolUtilityServices.GetBlockModelSpaceId(db).Open(OpenMode.ForWrite))
            {
                foreach (ObjectId id in btr)
                {
                    if ((id.ObjectClass.Name == "AcDbLine"))
                    {
                        using (var line = (Line)id.Open(OpenMode.ForWrite))
                        {
                            double radius = line.Length / 2.0;
                            var center = line.GetPointAtDist(radius);
                            line.Erase();
                            using (var circle = new Circle(center, Vector3d.ZAxis, radius))
                            {
                                btr.AppendEntity(circle);
                            }
                        }
                    }
                }
            }
        }&lt;/PRE&gt;
&lt;P&gt;Anyway, I do not know why you can not or do not want to use a transaction, but instead of a regular transaction, you can use an OpenCloseTransaction which is mainly a wrapper for the Open / Close process used in the upper code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST2")]
        public void Test2()
        {
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var btr = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                foreach (ObjectId id in btr)
                {
                    if ((id.ObjectClass.Name == "AcDbLine"))
                    {
                        var line = (Line)tr.GetObject(id, OpenMode.ForWrite);
                        double radius = line.Length / 2.0;
                        var center = line.GetPointAtDist(radius);
                        line.Erase();
                        var circle = new Circle(center, Vector3d.ZAxis, radius);
                        btr.AppendEntity(circle);
                        tr.AddNewlyCreatedDBObject(circle, true);
                    }
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
    <pubDate>Mon, 12 Jun 2017 06:57:39 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2017-06-12T06:57:39Z</dc:date>
    <item>
      <title>Update BlockTableRecord without Transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7144355#M31031</link>
      <description>&lt;P&gt;It possible to open BlockTableRecord for selected BlockReference, then DELETE all entities and ADD new entities without any of Transaction?&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2017 19:24:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7144355#M31031</guid>
      <dc:creator>CJModis</dc:creator>
      <dc:date>2017-06-11T19:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: Update BlockTableRecord without Transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7144415#M31032</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried it ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-NET/files/GUID-BF06F786-DDA6-4603-B5E5-25A35A4130A3-htm.html" target="_blank"&gt;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-NET/files/GUID-BF06F786-DDA6-4603-B5E5-25A35A4130A3-htm.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2017 21:02:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7144415#M31032</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2017-06-11T21:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Update BlockTableRecord without Transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7144422#M31033</link>
      <description>&lt;P&gt;Yes. i try it. I can delete entities from BlockTableRecord, but i can not add new entities&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2017 21:10:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7144422#M31033</guid>
      <dc:creator>CJModis</dc:creator>
      <dc:date>2017-06-11T21:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Update BlockTableRecord without Transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7144808#M31034</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST")]
        public void Test()
        {
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            using (var btr = (BlockTableRecord)SymbolUtilityServices.GetBlockModelSpaceId(db).Open(OpenMode.ForWrite))
            {
                foreach (ObjectId id in btr)
                {
                    if ((id.ObjectClass.Name == "AcDbLine"))
                    {
                        using (var line = (Line)id.Open(OpenMode.ForWrite))
                        {
                            double radius = line.Length / 2.0;
                            var center = line.GetPointAtDist(radius);
                            line.Erase();
                            using (var circle = new Circle(center, Vector3d.ZAxis, radius))
                            {
                                btr.AppendEntity(circle);
                            }
                        }
                    }
                }
            }
        }&lt;/PRE&gt;
&lt;P&gt;Anyway, I do not know why you can not or do not want to use a transaction, but instead of a regular transaction, you can use an OpenCloseTransaction which is mainly a wrapper for the Open / Close process used in the upper code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST2")]
        public void Test2()
        {
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var btr = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                foreach (ObjectId id in btr)
                {
                    if ((id.ObjectClass.Name == "AcDbLine"))
                    {
                        var line = (Line)tr.GetObject(id, OpenMode.ForWrite);
                        double radius = line.Length / 2.0;
                        var center = line.GetPointAtDist(radius);
                        line.Erase();
                        var circle = new Circle(center, Vector3d.ZAxis, radius);
                        btr.AppendEntity(circle);
                        tr.AddNewlyCreatedDBObject(circle, true);
                    }
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Jun 2017 06:57:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7144808#M31034</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-06-12T06:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Update BlockTableRecord without Transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7145484#M31035</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/716136"&gt;@CJModis&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Yes. i try it. I can delete entities from BlockTableRecord, but i can not add new entities&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You can delete entities from a BlockTableRecord without having to open it. It's the entities that you are deleting that you must open for write.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To add entities to a BlockTableRecord, you have to open it for write. If the BlockTableRecord is a record for an anonymous block, there's little point to deleting its contents. You should just create another new anonymous BlockTableRecord and populate it, then change the BlockTableRecord property of the BlockReference to reference the new BlockTableRecord. When the old one is no longer referenced by an BlockReferences, it will be discarded automatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;About avoiding the use of Transactions, please see this &lt;A href="https://forums.autodesk.com/t5/net/update-xrecord-when-entity-is-modified/m-p/7091473#M53374" target="_blank"&gt;previous post&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 12:35:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7145484#M31035</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-06-12T12:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Update BlockTableRecord without Transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7145507#M31036</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Activist_Investor написано:&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;To add entities to a BlockTableRecord, you have to open it for write. If the BlockTableRecord is a record for an anonymous block, there's little point to deleting its contents. You should just create another new anonymous BlockTableRecord and populate it, then change the BlockTableRecord property of the BlockReference to reference the new BlockTableRecord. When the old one is no longer referenced by an BlockReferences, it will be discarded automatically.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Are there any examples for this?&amp;nbsp;exactly for anonymous blocks&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 12:41:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7145507#M31036</guid>
      <dc:creator>CJModis</dc:creator>
      <dc:date>2017-06-12T12:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Update BlockTableRecord without Transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7145519#M31037</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;CJModis написано:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Activist_Investor написано:&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;To add entities to a BlockTableRecord, you have to open it for write. If the BlockTableRecord is a record for an anonymous block, there's little point to deleting its contents. You should just create another new anonymous BlockTableRecord and populate it, then change the BlockTableRecord property of the BlockReference to reference the new BlockTableRecord. When the old one is no longer referenced by an BlockReferences, it will be discarded automatically.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Are there any examples for this?&amp;nbsp;exactly for anonymous blocks&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Don't need)) I translated it and understand what did you mean&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 12:43:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-blocktablerecord-without-transaction/m-p/7145519#M31037</guid>
      <dc:creator>CJModis</dc:creator>
      <dc:date>2017-06-12T12:43:41Z</dc:date>
    </item>
  </channel>
</rss>

