<?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 Setting Xdata for Text Entity problem in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6472343#M35079</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm inserting a blockref and text to a drawing using a modeless windows form.&lt;/P&gt;&lt;P&gt;So I lock the document first before doing anything&lt;/P&gt;&lt;P&gt;I make the blockref and insert it using entityjig, add the newly created blockref, then rotate it with jig, commit &amp;nbsp;and then add xdata to it&lt;/P&gt;&lt;P&gt;No problem so far, and&amp;nbsp;then, in the same sub, I add a single line text (DBText), and set xdata for it (calling the same&amp;nbsp;sub below)&lt;/P&gt;&lt;P&gt;The problem is that AutoCAD crashes with an unhandled exception when setting the xdata for the text entity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I don't set xdata for the Text, everything works fine.&lt;/P&gt;&lt;P&gt;Any ideas ??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Sub SetXData(mcaja As Entity, appname As String, idc As Long, ncaja As String)&lt;BR /&gt;Dim rb As ResultBuffer&lt;BR /&gt;Dim adoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;Dim tr As Transaction = adoc.TransactionManager.StartTransaction()&lt;/P&gt;&lt;P&gt;Using tr&lt;BR /&gt;Dim obj As DBObject = tr.GetObject(mcaja.ObjectId, OpenMode.ForWrite)&lt;BR /&gt;AddRegAppTableRecord(appname, adoc)&lt;BR /&gt;rb = New ResultBuffer(New TypedValue(1001, appname), New TypedValue(1000, ncaja), New TypedValue(1071, idc))&lt;BR /&gt;obj.XData = rb&lt;BR /&gt;rb.Dispose()&lt;BR /&gt;tr.Commit()&lt;BR /&gt;End Using&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Public Shared Sub AddRegAppTableRecord(regAppName As String, ByRef doc As Document)&lt;BR /&gt;'Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;Dim ed As Editor = doc.Editor&lt;BR /&gt;Dim db As Database = doc.Database&lt;/P&gt;&lt;P&gt;Dim tr As Transaction = doc.TransactionManager.StartTransaction()&lt;BR /&gt;Using tr&lt;BR /&gt;Dim ratab As RegAppTable = CType(tr.GetObject(db.RegAppTableId, OpenMode.ForRead, False), RegAppTable)&lt;BR /&gt;If Not ratab.Has(regAppName) Then&lt;BR /&gt;ratab.UpgradeOpen()&lt;BR /&gt;Dim ratrec As New RegAppTableRecord()&lt;BR /&gt;ratrec.Name = regAppName&lt;BR /&gt;ratab.Add(ratrec)&lt;BR /&gt;tr.AddNewlyCreatedDBObject(ratrec, True)&lt;BR /&gt;End If&lt;BR /&gt;tr.Commit()&lt;BR /&gt;End Using&lt;BR /&gt;End Sub&lt;/P&gt;</description>
    <pubDate>Tue, 02 Aug 2016 07:38:59 GMT</pubDate>
    <dc:creator>Mago</dc:creator>
    <dc:date>2016-08-02T07:38:59Z</dc:date>
    <item>
      <title>Setting Xdata for Text Entity problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6472343#M35079</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm inserting a blockref and text to a drawing using a modeless windows form.&lt;/P&gt;&lt;P&gt;So I lock the document first before doing anything&lt;/P&gt;&lt;P&gt;I make the blockref and insert it using entityjig, add the newly created blockref, then rotate it with jig, commit &amp;nbsp;and then add xdata to it&lt;/P&gt;&lt;P&gt;No problem so far, and&amp;nbsp;then, in the same sub, I add a single line text (DBText), and set xdata for it (calling the same&amp;nbsp;sub below)&lt;/P&gt;&lt;P&gt;The problem is that AutoCAD crashes with an unhandled exception when setting the xdata for the text entity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I don't set xdata for the Text, everything works fine.&lt;/P&gt;&lt;P&gt;Any ideas ??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Sub SetXData(mcaja As Entity, appname As String, idc As Long, ncaja As String)&lt;BR /&gt;Dim rb As ResultBuffer&lt;BR /&gt;Dim adoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;Dim tr As Transaction = adoc.TransactionManager.StartTransaction()&lt;/P&gt;&lt;P&gt;Using tr&lt;BR /&gt;Dim obj As DBObject = tr.GetObject(mcaja.ObjectId, OpenMode.ForWrite)&lt;BR /&gt;AddRegAppTableRecord(appname, adoc)&lt;BR /&gt;rb = New ResultBuffer(New TypedValue(1001, appname), New TypedValue(1000, ncaja), New TypedValue(1071, idc))&lt;BR /&gt;obj.XData = rb&lt;BR /&gt;rb.Dispose()&lt;BR /&gt;tr.Commit()&lt;BR /&gt;End Using&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Public Shared Sub AddRegAppTableRecord(regAppName As String, ByRef doc As Document)&lt;BR /&gt;'Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;Dim ed As Editor = doc.Editor&lt;BR /&gt;Dim db As Database = doc.Database&lt;/P&gt;&lt;P&gt;Dim tr As Transaction = doc.TransactionManager.StartTransaction()&lt;BR /&gt;Using tr&lt;BR /&gt;Dim ratab As RegAppTable = CType(tr.GetObject(db.RegAppTableId, OpenMode.ForRead, False), RegAppTable)&lt;BR /&gt;If Not ratab.Has(regAppName) Then&lt;BR /&gt;ratab.UpgradeOpen()&lt;BR /&gt;Dim ratrec As New RegAppTableRecord()&lt;BR /&gt;ratrec.Name = regAppName&lt;BR /&gt;ratab.Add(ratrec)&lt;BR /&gt;tr.AddNewlyCreatedDBObject(ratrec, True)&lt;BR /&gt;End If&lt;BR /&gt;tr.Commit()&lt;BR /&gt;End Using&lt;BR /&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 07:38:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6472343#M35079</guid>
      <dc:creator>Mago</dc:creator>
      <dc:date>2016-08-02T07:38:59Z</dc:date>
    </item>
    <item>
      <title>Re : Setting Xdata for Text Entity problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6472506#M35080</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try to change the idc parameter to Integer. The 1071 dxf code is to be used with 32 bits signed integers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if this doesn't solve your issue, you should handle the exception in a Try / Catch block to get more information about this exception.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 09:39:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6472506#M35080</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-08-02T09:39:13Z</dc:date>
    </item>
    <item>
      <title>Re : Setting Xdata for Text Entity problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6472914#M35081</link>
      <description>&lt;P&gt;&lt;SPAN&gt;mcaja is already an entity, why are you opening it a second time?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And you don't need to start a transaction in each Sub. In&amp;nbsp;AddRegAppTableRecord, you can simply do:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim ratab As RegAppTable = CType(db.RegAppTableId.GetObject(OpenMode.ForRead), RegAppTable)&lt;BR /&gt;[..]&lt;BR /&gt;doc.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(ratrec, True)&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Aug 2016 12:57:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6472914#M35081</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2016-08-02T12:57:31Z</dc:date>
    </item>
    <item>
      <title>Re : Setting Xdata for Text Entity problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6473781#M35082</link>
      <description>&lt;P&gt;Thank you Gilles, but changing idc to integer did&amp;nbsp;not help.&lt;/P&gt;&lt;P&gt;Try catch won't work on debug mode since autocad shuts down and no error is reported.&lt;/P&gt;&lt;P&gt;on release mode, autocad crashes with a&amp;nbsp;"fatal error unhandled access violations reading 0x0010"&lt;/P&gt;&lt;P&gt;so the try/catch isn't helping there either.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 17:37:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6473781#M35082</guid>
      <dc:creator>Mago</dc:creator>
      <dc:date>2016-08-02T17:37:27Z</dc:date>
    </item>
    <item>
      <title>Re : Setting Xdata for Text Entity problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6473800#M35083</link>
      <description>&lt;P&gt;Thanks for the tip about the top transaction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;mcaja is a different entity everytime I call the setxdata sub.&lt;/P&gt;&lt;P&gt;The first time mcaja is a blockref, and the second time is the dbtext entity.&lt;/P&gt;&lt;P&gt;With the dbtext entity it crashes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 17:42:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6473800#M35083</guid>
      <dc:creator>Mago</dc:creator>
      <dc:date>2016-08-02T17:42:35Z</dc:date>
    </item>
    <item>
      <title>Re : Setting Xdata for Text Entity problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6474085#M35084</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Generally you should not pass objects deriving from DBObject as parameters (use ObjectId instead) except when the method is called from within a transaction (in this case, you should use this top transaction in the called method).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;If I do not misunderstand, you create some entities (a block reference and a text) in a transaction then you pass these entities to another method. If this transaction have been disposed when the entities are passed to SetXData() they&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt; also&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt; have been disposed with&amp;nbsp; the transaction (this should occur some time after the calling to Dispose).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;So, try passing ObjectIds as parameter or call the SetXData method from within the top transaction, in this case do not start a new transaction to re-open mcaja. The newly created entity is opened for write so that you can directly set its Xdata property.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 19:51:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6474085#M35084</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-08-02T19:51:36Z</dc:date>
    </item>
    <item>
      <title>Re : Setting Xdata for Text Entity problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6474864#M35085</link>
      <description>&lt;P&gt;Thank you Maxence and Gilles. I was creating the dbtext entity in an additional transaction and within an using statement ( Using Mytext as Dbtext = New Dbtext()... End Using), before passing it to the setXData sub. That was causing the fatal error.&lt;BR /&gt;Now I'm using the top transaction and got rid of the Using statement and it's working just fine. Thank you again.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 06:35:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6474864#M35085</guid>
      <dc:creator>Mago</dc:creator>
      <dc:date>2016-08-03T06:35:02Z</dc:date>
    </item>
    <item>
      <title>Re : Setting Xdata for Text Entity problem</title>
      <link>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6474968#M35086</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can keep the using statement (it's a good practice to create new DBObjects in a using statement in case an error occurs before they're added to the transaction), you just need to call the SetXData() method from within this scope.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 07:47:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/setting-xdata-for-text-entity-problem/m-p/6474968#M35086</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-08-03T07:47:07Z</dc:date>
    </item>
  </channel>
</rss>

