*Joel Roderick
Message 1 of 3 (248 Views)

Insert Row (VB.NET)

248 Views, 2 Replies
03-14-2006 12:09 PM
I am pretty new to .net and am having some issues with transactions (I

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 =
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 =
tbl = trans.GetObject(pResults.ObjectId, OpenMode.ForWrite) <----
****crashes here****
tbl.InsertRows(1, 1.0, 1)

Thanks for the help,

Joel Roderick
Water Technology, Inc.
Distinguished Contributor
Posts: 212
Registered: ‎10-03-2003
Message 2 of 3 (248 Views)

Re: Insert Row (VB.NET)

03-15-2006 05:56 AM in reply to: *Joel Roderick
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()
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
End Try
End Sub
*Joel Roderick
Message 3 of 3 (248 Views)

Re: Insert Row (VB.NET)

03-15-2006 06:16 AM in reply to: *Joel Roderick
Look like I needed to lock the document before opening the object...
So this line solved the problem:

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!