.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert Row (VB.NET)

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
518 Views, 2 Replies

Insert Row (VB.NET)

I am pretty new to .net and am having some issues with transactions (I
think)...

I want to add a row to an existing table. AutoCAD crashes when I try to
open the object for write. Am I using the transaction improperly?

Here is the code I have so far:

Dim editor As Editor =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim pOptions As PromptEntityOptions = New PromptEntityOptions("Select a
table: ")
Dim pResults As PromptEntityResult = editor.GetEntity(pOptions)
Dim tbl As Table
Dim trans As Transaction
trans =
HostApplicationServices.WorkingDatabase().TransactionManager.StartTransaction()
tbl = trans.GetObject(pResults.ObjectId, OpenMode.ForWrite) <----
****crashes here****
tbl.InsertRows(1, 1.0, 1)
trans.Commit()
trans.Dispose()


Thanks for the help,

--
Joel Roderick
Water Technology, Inc.
www.watertechnologyinc.com
2 REPLIES 2
Message 2 of 3
Mikko
in reply to: Anonymous

This might help.

<CommandMethod("AddTableRow")> _
Public Shared Sub AddTableRow()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim tm As Transaction = db.TransactionManager.StartTransaction()
Try
Dim res As PromptSelectionResult = ed.GetSelection
If res.Status PromptStatus.OK Then
Exit Sub
End If
Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
Dim tempIdArray() As ObjectId
tempIdArray = SS.GetObjectIds()
Dim tempId As ObjectId
Dim tbl As Table
For Each tempId In tempIdArray
Dim Ent As Entity = CType(tm.GetObject(tempId, OpenMode.ForWrite), Entity)
If UCase(Ent.GetType.Name.ToString) = "TABLE" Then
tbl = Ent
tbl.InsertRows(1, 1.0, 1)
End If
Next
tm.Commit()
Catch
Finally
tm.Dispose()
End Try
End Sub
Message 3 of 3
Anonymous
in reply to: Anonymous

Look like I needed to lock the document before opening the object...
So this line solved the problem:

editor.Document.LockDocument()

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost