.NET

Reply
*Joel Roderick
Message 1 of 3 (239 Views)

Insert Row (VB.NET)

239 Views, 2 Replies
03-14-2006 12:09 PM
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
Distinguished Contributor
Mikko
Posts: 212
Registered: ‎10-03-2003
Message 2 of 3 (239 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()
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
*Joel Roderick
Message 3 of 3 (239 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:

editor.Document.LockDocument()

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community