Database Saveas and system access error?

Database Saveas and system access error?

carl_golenbergUH8S6
New Member New Member
134 Views
3 Replies
Message 1 of 4

Database Saveas and system access error?

carl_golenbergUH8S6
New Member
New Member

I'm running some code that copies files and then edits the databases. I've done this a lot at my other job but for some reason at my new one all attempts to save databases fail, every time.

first I copy in the files:

For Each suggestedFile In SuggestedNewFiles
    If Not String.IsNullOrWhiteSpace(suggestedFile) Then
        Dim newFileLocation = IO.Path.Combine(newFolderLocation, suggestedFile)
        If IO.File.Exists(newFileLocation) Then
            Dim result = MsgBox("File already exists: " + newFileLocation + vbCrLf + "Do you want to overwrite it?", MsgBoxStyle.YesNo)
            If result = MsgBoxResult.No Then
                Exit Sub
            End If
        End If
        'Create the new file with the template
        IO.File.Copy(Statics.LayoutTemplateFile, newFileLocation, True)
        If Not IO.File.Exists(newFileLocation) Then
            MsgBox(String.Format("Failed to create file: {0}", suggestedFile), MsgBoxStyle.OkOnly)
            Exit Sub
        End If
    End If
Next

then I open the database and while I can work I cannot save the file

 

For Each suggestedFile In SuggestedNewFiles
    Dim newFileLocation = IO.Path.Combine(newFolderLocation, suggestedFile)
    Dim TitleblockLocation As String = ""
    TitleblockLocation = GetTitleblockLocation(newFolderLocation)

    Using sectionLayoutsDb As Database = New Database(False, True)
        sectionLayoutsDb.ReadDwgFile(NewFilename, System.IO.FileShare.ReadWrite, True, "")
        If sectionLayoutsDb Is Nothing Then
            Exit Sub
        End If


        HostApplicationServices.WorkingDatabase = thisDb
        '''working code here

        sectionLayoutsDb.SaveAs(newFileLocation, DwgVersion.Current)
        sectionLayoutsDb.CloseInput(True)
    End Using
Next

No matter where I put the saveas it complains.

0 Likes
135 Views
3 Replies
Replies (3)
Message 2 of 4

ActivistInvestor
Mentor
Mentor

Try using the overload of SaveAs() that takes a Boolean as the second argument, and also wrap the call to SaveAs() in a Try/Catch to see what exception it is throwing. If this worked in another environment but is failing in the current environment, it is most likely a permissions issue.

0 Likes
Message 3 of 4

carl_golenbergUH8S6
New Member
New Member

I was catching it; it's a System.AccessViolationException

I'll check it in another environment

0 Likes
Message 4 of 4

daniel_cadext
Advisor
Advisor

Db may be partially read into memory, try calling sectionLayoutsDb.CloseInput(true), just after sectionLayoutsDb.ReadDwgFile

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes