Тема: Возникает ошибка при работе программы

Есть одна форма и на ней кнопка.
При нажатии кнопки должна чертится линия, но возникает ошибка в Автокаде:


"Необрабатываемое исключение в компоненте приложения. eLockViolation"

Код находится внутри формы (по привычке взятой из VBA).

Код:

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime



Public Class UserForm2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Me.Hide()
        '' Get the current database and start the Transaction Manager
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        Dim pPtRes As PromptPointResult
        Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")

        '' Prompt for the start point
        pPtOpts.Message = vbLf & "Enter the start point of the line: "
        pPtRes = acDoc.Editor.GetPoint(pPtOpts)
        Dim ptStart As Point3d = pPtRes.Value

        '' Exit if the user presses ESC or cancels the command
        If pPtRes.Status = PromptStatus.Cancel Then Exit Sub

        '' Prompt for the end point
        pPtOpts.Message = vbLf & "Enter the end point of the line: "
        pPtOpts.UseBasePoint = True
        pPtOpts.BasePoint = ptStart
        pPtRes = acDoc.Editor.GetPoint(pPtOpts)
        Dim ptEnd As Point3d = pPtRes.Value

        If pPtRes.Status = PromptStatus.Cancel Then Exit Sub

        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

            Dim acBlkTbl As BlockTable
            Dim acBlkTblRec As BlockTableRecord

            '' Open Model space for write
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _
                                         OpenMode.ForRead)

            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                            OpenMode.ForWrite)

            '' Define the new line
            Dim acLine As Line = New Line(ptStart, ptEnd)
            acLine.SetDatabaseDefaults()

            '' Add the line to the drawing
            acBlkTblRec.AppendEntity(acLine)
            acTrans.AddNewlyCreatedDBObject(acLine, True)

            '' Zoom to the extents or limits of the drawing
            acDoc.SendStringToExecute("._zoom _all ", True, False, False)

            '' Commit the changes and dispose of the transaction
            acTrans.Commit()
        End Using



    End Sub
End Class


В чем ошибка подскажите пожалуйста???

Re: Возникает ошибка при работе программы

Dim docloc As DocumentLock = AcDoc.LockDocument()
Using docloc
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() 

''....остальной код здесь

End using
end using

Re: Возникает ошибка при работе программы

fixo пишет:


Код   


Dim docloc As DocumentLock = AcDoc.LockDocument()
Using docloc
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

''....остальной код здесь

End using
end using


В Visual Studio вылазит ошибка:

Name 'AcDoc' is not declared
Name 'acCurDb' is not declared

Это значит, что они не объявленны??? А как их объявить???

Re: Возникает ошибка при работе программы

Вместо AcDoc напиши acDoc. А acCurDb у тебя объявлено ниже - перенеси объявления в начало метода.

Re: Возникает ошибка при работе программы

Огромное спасибо fixo и Александру Ривилису!!! :)
Код заработал!!!

Re: Возникает ошибка при работе программы

fixo пишет:


Код   


Dim docloc As DocumentLock = AcDoc.LockDocument()
Using docloc
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

''....остальной код здесь

End using
end using




А как этот кусок кода перевести на C#???
Та же самая ошибка возникает что и на VB.net

Re: Возникает ошибка при работе программы

using (DocumentLock doclock = AcDoc.LockDocument()) {
//
// Тут твой код
//
} 

Re: Возникает ошибка при работе программы

Спасибо Александру Ривилису за помощь!
Все заработало!
:)