<?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 Error while changing block definition of an Block reference in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4542907#M47239</link>
    <description>&lt;P&gt;Good afternoon. I'm trying to change block the definition of an block reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;blockreference.BlockTableRecord = newBlock.ObjectId;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In most cases this works well. However I found a case that it not work as well. When I try to change the definition from a new block that I have created in my test DWG, it disappears from the model. I wonder what is causing this problem?&lt;/P&gt;</description>
    <pubDate>Mon, 21 Oct 2013 17:34:32 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-10-21T17:34:32Z</dc:date>
    <item>
      <title>Error while changing block definition of an Block reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4542907#M47239</link>
      <description>&lt;P&gt;Good afternoon. I'm trying to change block the definition of an block reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;blockreference.BlockTableRecord = newBlock.ObjectId;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In most cases this works well. However I found a case that it not work as well. When I try to change the definition from a new block that I have created in my test DWG, it disappears from the model. I wonder what is causing this problem?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2013 17:34:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4542907#M47239</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-10-21T17:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Error while changing block definition of an Block reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4543967#M47240</link>
      <description>&lt;P&gt;It would be easier to identify the problem if you could post some sample code and (ideally) also a sample DWG that causes the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 05:16:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4543967#M47240</guid>
      <dc:creator>StephenPreston</dc:creator>
      <dc:date>2013-10-22T05:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Error while changing block definition of an Block reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4546759#M47241</link>
      <description>&lt;P&gt;Hi.&lt;BR /&gt;I'm sending the DWG with the bug. The code I'm using is similar with the code below. I tried to change the block definition of my ordinary blocks to my TEST block and I had the same problem that I reported.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CommandMethod("CBLOCK", CommandFlags.Modal | CommandFlags.NoPaperSpace)]&lt;BR /&gt;public static void ChageBlock()&lt;BR /&gt;{&lt;BR /&gt;var doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;var db = doc.Database;&lt;BR /&gt;var ed = doc.Editor;&lt;BR /&gt;&lt;BR /&gt;var pso = new PromptSelectionOptions&lt;BR /&gt;{&lt;BR /&gt;MessageForAdding = "\nSelect block reference(s)",&lt;BR /&gt;AllowDuplicates = false,&lt;BR /&gt;AllowSubSelections = false,&lt;BR /&gt;ForceSubSelections = false,&lt;BR /&gt;RejectObjectsOnLockedLayers = true,&lt;BR /&gt;RejectObjectsFromNonCurrentSpace = true,&lt;BR /&gt;RejectPaperspaceViewport = true,&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;var selectionResult = ed.GetSelection(pso, new SelectionFilter(new[] { new TypedValue((int)DxfCode.Start, "INSERT"), }));&lt;BR /&gt;&lt;BR /&gt;var options = new PromptEntityOptions("\nSelect block reference");&lt;BR /&gt;options.SetRejectMessage("\nSelect only block reference");&lt;BR /&gt;options.AddAllowedClass(typeof(BlockReference), false);&lt;/P&gt;&lt;P&gt;if (selectionResult.Status!= PromptStatus.OK)&lt;BR /&gt;return;&lt;/P&gt;&lt;P&gt;using (var tx = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;//get references&lt;BR /&gt;var blkRefs = new ObjectIdCollection(selectionResult.Value.GetObjectIds())&lt;BR /&gt;.Cast&amp;lt;ObjectId&amp;gt;()&lt;BR /&gt;.Select(objId =&amp;gt; tx.GetObject(objId, OpenMode.ForRead))&lt;BR /&gt;.OfType&amp;lt;BlockReference&amp;gt;()&lt;BR /&gt;.Where(x =&amp;gt; x.BlockTableRecord.IsValid)&lt;BR /&gt;.ToArray();&lt;/P&gt;&lt;P&gt;//block table record&lt;BR /&gt;var blks = ((BlockTable)tx.GetObject(db.BlockTableId, OpenMode.ForRead))&lt;BR /&gt;.Cast&amp;lt;ObjectId&amp;gt;()&lt;BR /&gt;.Select(objId =&amp;gt; tx.GetObject(objId, OpenMode.ForRead))&lt;BR /&gt;.OfType&amp;lt;BlockTableRecord&amp;gt;()&lt;BR /&gt;.Where(bk =&amp;gt; !bk.IsFromExternalReference &amp;amp;&amp;amp; (bk.Name == "*Model_Space" || !bk.Name.StartsWith("*")))&lt;BR /&gt;.Distinct()&lt;BR /&gt;.ToArray();&lt;/P&gt;&lt;P&gt;//Get the target block&lt;BR /&gt;var block = blks.First(bk =&amp;gt; bk.Name == "TEST");&lt;BR /&gt;&lt;BR /&gt;foreach (var blockReference in blkRefs)&lt;BR /&gt;{&lt;BR /&gt;blockReference.UpgradeOpen();&lt;/P&gt;&lt;P&gt;//set the id of the test block&lt;BR /&gt;blockReference.BlockTableRecord = block.ObjectId;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;tx.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2013 14:23:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4546759#M47241</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-10-22T14:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Error while changing block definition of an Block reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4547375#M47242</link>
      <description>PS: I'm using AutoCad 2013</description>
      <pubDate>Tue, 22 Oct 2013 16:24:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4547375#M47242</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-10-22T16:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Error while changing block definition of an Block reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4567695#M47243</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code works ok for the sample drawing.&lt;/P&gt;
&lt;P&gt;After the "BlockTableRecord" has been set, those&amp;nbsp;&lt;SPAN style="font-size: 11px; line-height: 14px;"&gt;block references overlap on each other. It appears to disappear as the position of all the block references are set to (0,0).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 11px; line-height: 14px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 11px; line-height: 14px;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2013 11:15:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4567695#M47243</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2013-10-28T11:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Error while changing block definition of an Block reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4568079#M47244</link>
      <description>&lt;P&gt;Hi Balaji.&lt;BR /&gt;&lt;BR /&gt;Thanks. But now I have another problem. If you copy the reference of block "ABC", for example, and put it in some place in the drawing, there is 2 references of the same block, ok? The first reference is the one that I created the block table record, using BLOCK command, and another one is a copy from the first reference. If you run my code, you will realize that the first copy "disappears" and the second one works correctly, because it do not overlap with TEST block reference. Do you know the reason?&lt;BR /&gt;&lt;BR /&gt;With best regards,&lt;BR /&gt;&lt;BR /&gt;André Cristino.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2013 13:58:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4568079#M47244</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-10-28T13:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Error while changing block definition of an Block reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4569883#M47245</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;André,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The coordinates of a block reference are relative to the containing block record origin. For this reason, you will observe a shift when the "BlockTableRecord" is modified for an existing block reference. You can understand this by trying to&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 11px;"&gt;move the entities in the "TEST" and "ABC" blocks to the origin. Please try your code with the attached drawing that has this change.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 11px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 11px;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2013 05:27:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-while-changing-block-definition-of-an-block-reference/m-p/4569883#M47245</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2013-10-29T05:27:43Z</dc:date>
    </item>
  </channel>
</rss>

