Hi,
I'm inserting a blockref and text to a drawing using a modeless windows form.
So I lock the document first before doing anything
I make the blockref and insert it using entityjig, add the newly created blockref, then rotate it with jig, commit and then add xdata to it
No problem so far, and then, in the same sub, I add a single line text (DBText), and set xdata for it (calling the same sub below)
The problem is that AutoCAD crashes with an unhandled exception when setting the xdata for the text entity.
If I don't set xdata for the Text, everything works fine.
Any ideas ??
Public Sub SetXData(mcaja As Entity, appname As String, idc As Long, ncaja As String)
Dim rb As ResultBuffer
Dim adoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim tr As Transaction = adoc.TransactionManager.StartTransaction()
Using tr
Dim obj As DBObject = tr.GetObject(mcaja.ObjectId, OpenMode.ForWrite)
AddRegAppTableRecord(appname, adoc)
rb = New ResultBuffer(New TypedValue(1001, appname), New TypedValue(1000, ncaja), New TypedValue(1071, idc))
obj.XData = rb
rb.Dispose()
tr.Commit()
End Using
End Sub
Public Shared Sub AddRegAppTableRecord(regAppName As String, ByRef doc As Document)
'Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
Dim ratab As RegAppTable = CType(tr.GetObject(db.RegAppTableId, OpenMode.ForRead, False), RegAppTable)
If Not ratab.Has(regAppName) Then
ratab.UpgradeOpen()
Dim ratrec As New RegAppTableRecord()
ratrec.Name = regAppName
ratab.Add(ratrec)
tr.AddNewlyCreatedDBObject(ratrec, True)
End If
tr.Commit()
End Using
End Sub
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Solved by FRFR1426. Go to Solution.
Hi,
Try to change the idc parameter to Integer. The 1071 dxf code is to be used with 32 bits signed integers.
if this doesn't solve your issue, you should handle the exception in a Try / Catch block to get more information about this exception.
mcaja is already an entity, why are you opening it a second time?
And you don't need to start a transaction in each Sub. In AddRegAppTableRecord, you can simply do:
Dim ratab As RegAppTable = CType(db.RegAppTableId.GetObject(OpenMode.ForRead), RegAppTable)
[..]
doc.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(ratrec, True)
Thank you Gilles, but changing idc to integer did not help.
Try catch won't work on debug mode since autocad shuts down and no error is reported.
on release mode, autocad crashes with a "fatal error unhandled access violations reading 0x0010"
so the try/catch isn't helping there either.
Thanks for the tip about the top transaction.
mcaja is a different entity everytime I call the setxdata sub.
The first time mcaja is a blockref, and the second time is the dbtext entity.
With the dbtext entity it crashes.
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).
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 also have been disposed with the transaction (this should occur some time after the calling to Dispose).
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.
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.
Now I'm using the top transaction and got rid of the Using statement and it's working just fine. Thank you again.
Can't find what you're looking for? Ask the community or share your knowledge.