.NET

Reply
Valued Contributor
Zanzabar
Posts: 56
Registered: ‎12-22-2008
Message 1 of 3 (823 Views)
Accepted Solution

VB.Net 2013 eLockViolation

823 Views, 2 Replies
05-01-2013 05:24 AM

So I seem to be having some issues with using VB.net. I looked at the helloWorld sample, as well as the makeEnts sample and I can't seem to resolve the fack that I get a eLockViolation error that pops up and mentioned JIT issues. So what I was trying to do is simple run a routine to load a forum which allows the user to select which new layers to create. That being said the code I use to create the layers within the forum fails every time. If I move the code to create the layers into the main file shopSetup.vb instead of shopSetupForm.vb then it work. I know that it isn't a problem with the code specfically but maybe that the form doesn't have access to the currently open document or something? I am not sure really and I am just kind of guessing. Please let me know thank you.

 

***********************************************************
shopSetup.vb
***********************************************************
Option Explicit On

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager

Namespace shopSetup
    Public Class shopSetup
        <Autodesk.AutoCAD.Runtime.CommandMethod("Setup")> _
        Public Sub setupCommand()
            Dim userForm As New shopSetupForm()
            Application.ShowModelessDialog(userForm)
        End Sub
    End Class
End Namespace





***********************************************************
shopSetup.vb
***********************************************************

Option Explicit On

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager


Public Class shopSetupForm
    Private Sub okButton_Click(sender As System.Object, e As System.EventArgs) Handles okButton.Click
        Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
        Dim tm As DBTransMan = db.TransactionManager
        Dim ta As Transaction = tm.StartTransaction()
        Try
            Dim LT As LayerTable = tm.GetObject(db.LayerTableId, OpenMode.ForRead, False)
            If LT.Has("ASDK_MYLAYER") = False Then
                Dim LTRec As New LayerTableRecord()
                LTRec.Name = "ASDK_MYLAYER"
                LT.UpgradeOpen()
                LT.Add(LTRec)
                tm.AddNewlyCreatedDBObject(LTRec, True)
                ta.Commit()
            End If
        Finally
            ta.Dispose()
        End Try
        'Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
        'Dim tm As DBTransMan = db.TransactionManager
        'Dim ta As Transaction = tm.StartTransaction()
        'If slabCheckBox.Checked = True Then
        '    Dim LT As LayerTable = tm.GetObject(db.LayerTableId, OpenMode.ForRead, False)
        '    Dim layers As New List(Of String) From {"SLAB-EDGE", "SLAB-GRID", "SLAB-MISC", "SLAB-DEFPOITNS"}
        '    Try
        '        For Each layerName In layers
        '            If LT.Has(layerName) = False Then
        '                Dim LTRec As New LayerTableRecord
        '                LTRec.Name = layerName
        '                LT.UpgradeOpen()
        '                LT.Add(LTRec)
        '                tm.AddNewlyCreatedDBObject(LTRec, True)
        '                ta.Commit()
        '            End If
        '        Next
        '    Finally
        '        ta.Dispose()
        '    End Try
        'End If

        'Me.Close()
    End Sub

    Private Sub quitButton_Click(sender As System.Object, e As System.EventArgs) Handles quitButton.Click, quitButton.Click
        Me.Close()
    End Sub
End Class

 I have inclued both the code for simple review and also the entire vb directory for further review. Thank you in advance for your help. This is my first .net application so I am still learning a bit, I do like the .net format more then the C++ format due to the decrease in complexity of the pointers, as well as all the issues I was having with setting up a project etc.

Hi,

 

To acces an AutoCAD document from a modeless dialog, you need to lock the Document: (see here).

 

Dim doc As Document = Application.DocumentManager.MdiActiveDocument 
Dim db As Database = doc.Database Dim tm As DBTransMan = db.TransactionManager
Using doc.LockDocument() Using ta As Transaction = tm.StartTransaction()
' your code here
End Using
EndUsing
*Expert Elite*
_gile
Posts: 2,114
Registered: ‎04-29-2006
Message 2 of 3 (739 Views)

Re : VB.Net 2013 eLockViolation

05-01-2013 09:54 PM in reply to: Zanzabar

Hi,

 

To acces an AutoCAD document from a modeless dialog, you need to lock the Document: (see here).

 

Dim doc As Document = Application.DocumentManager.MdiActiveDocument 
Dim db As Database = doc.Database Dim tm As DBTransMan = db.TransactionManager
Using doc.LockDocument() Using ta As Transaction = tm.StartTransaction()
' your code here
End Using
EndUsing
Gilles Chanteau
Valued Contributor
Zanzabar
Posts: 56
Registered: ‎12-22-2008
Message 3 of 3 (717 Views)

Re : VB.Net 2013 eLockViolation

05-02-2013 05:31 AM in reply to: _gile

Excellent, I bet that has already been posted but since I was searching in the ObjectArx forum instead of the .Net forum I never found it. I guess we all live and learn.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
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!