A error “System.AccessViolationException” occur in Acdbmgd.dll

A error “System.AccessViolationException” occur in Acdbmgd.dll

bairuize
Explorer Explorer
659 Views
9 Replies
Message 1 of 10

A error “System.AccessViolationException” occur in Acdbmgd.dll

bairuize
Explorer
Explorer

I use this code but meet A error .“System.AccessViolationException” occur in Acdbmgd.dll 

Imports Autodesk.AutoCAD.DatabaseServices

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


Public Class Class1

 

<CommandMethod("exsat")>
Public Shared Sub testSolidsSelect()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim tr As Transaction = db.TransactionManager.StartTransaction()
Dim sImage_Type = "SAT"
Dim satFullName As String = "D:\123.sat"


Dim curtab As String = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("ctab").ToString()
Dim values(3) As TypedValue
values(0) = New TypedValue(DxfCode.Operator, "<and")
values(1) = New TypedValue(DxfCode.Start, "region")
values(2) = New TypedValue(DxfCode.LayoutName, curtab)
values(3) = New TypedValue(DxfCode.Operator, "and>")

Dim selFilter As New SelectionFilter(values)
Dim prompSelRes As PromptSelectionResult = ed.SelectAll(selFilter)
If prompSelRes.Status <> PromptStatus.OK Then Return
Dim oSset As SelectionSet = prompSelRes.Value
ed.WriteMessage(vbLf + "{0}", oSset.Count)


ed.SetImpliedSelection(oSset)

Dim AcApp As Autodesk.AutoCAD.Interop.AcadApplication = DirectCast(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, Autodesk.AutoCAD.Interop.AcadApplication)
Dim ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument = AcApp.ActiveDocument
Dim pickSset As AcadSelectionSet = ThisDrawing.ActiveSelectionSet
ThisDrawing.Export(satFullName, sImage_Type, pickSset)
pickSset.Clear()
pickSset = Nothing
ThisDrawing = Nothing
AcApp = Nothing
ed.Regen()
End Sub
End Class

 

 

0 Likes
660 Views
9 Replies
Replies (9)
Message 2 of 10

bairuize
Explorer
Explorer

could somebody help me. best wishes to you

0 Likes
Message 3 of 10

ActivistInvestor
Mentor
Mentor

Did you try stepping through the code to see exactly what line is triggering the exception?  Without knowing more one thing you might try is to use the previous selection set rather than the active selection set.

Message 4 of 10

bairuize
Explorer
Explorer
Thanks for your help!
I changed the previous selection set, it has no influence.
Now my code is generating .SAT normally. But when it run to "end sub", VS will report errors "System.AccessViolationException".
0 Likes
Message 5 of 10

ActivistInvestor
Mentor
Mentor

Please post your code using the insert code button on the toolbar because your code is too difficult to read when it is not formatted.

 

It looks like you are starting a transaction and not committing, aborting or disposing it and that is most likely the problem. From what I can tell there isn't any need for a transaction to do what you need.

0 Likes
Message 6 of 10

cuongtk2
Advocate
Advocate

"d:/filepath.dat" , or "\\"

0 Likes
Message 7 of 10

bairuize
Explorer
Explorer
Imports Autodesk.AutoCAD.DatabaseServices

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


Public Class Class1


    <CommandMethod("exsat")>
    Public Shared Sub testSolidsSelect()
        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim tr As Transaction = db.TransactionManager.StartTransaction()
        Dim sImage_Type = "SAT"
        Dim satFullName As String = "D:/123.sat"
        Try

            ''Dim curlay As String = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("clayer").ToString()
            Dim curtab As String = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("ctab").ToString()
            Dim values(3) As TypedValue
            values(0) = New TypedValue(DxfCode.Operator, "<and")
            values(1) = New TypedValue(DxfCode.Start, "region")
            values(2) = New TypedValue(DxfCode.LayoutName, curtab)
            values(3) = New TypedValue(DxfCode.Operator, "and>")

            Dim selFilter As New SelectionFilter(values)
            Dim prompSelRes As PromptSelectionResult = ed.SelectAll(selFilter)
            If prompSelRes.Status <> PromptStatus.OK Then Return

            Dim oSset As SelectionSet = prompSelRes.Value
            ed.WriteMessage(vbLf + "{0}", oSset.Count)
            '  Console.WriteLine(oSset.Count.ToString() + "    " + "b")


            ed.SetImpliedSelection(oSset)

            Dim AcApp As Autodesk.AutoCAD.Interop.AcadApplication = DirectCast(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, Autodesk.AutoCAD.Interop.AcadApplication)
            Dim ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument = AcApp.ActiveDocument
            Dim pickSset As AcadSelectionSet = ThisDrawing.PickfirstSelectionSet

            ThisDrawing.Export(satFullName, sImage_Type, pickSset)
            pickSset.Clear()
            pickSset = Nothing
            ThisDrawing = Nothing
            AcApp = Nothing
            ' ed.Regen()
        Catch ex As Autodesk.AutoCAD.Runtime.Exception
            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.ToString & vbLf & ex.Message)
        Finally
            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Find file " & satFullName & " to see result")
        End Try

    End Sub
End Class
0 Likes
Message 8 of 10

bairuize
Explorer
Explorer
Thanks for your help!
I post my new code,and I corrected the code as you suggested.But there still occur the error "System.AccessViolationException "
0 Likes
Message 9 of 10

bairuize
Explorer
Explorer
Thanks for your help!
I have posted the code according to your suggestion
0 Likes
Message 10 of 10

ActivistInvestor
Mentor
Mentor
Dim tr As Transaction = db.TransactionManager.StartTransaction()

 

Remove the above line from your code.

0 Likes