.NET

Reply
Contributor
jon-p
Posts: 18
Registered: ‎01-04-2013
Message 11 of 26 (311 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-16-2014 08:41 AM in reply to: xpeter88

The following are the references i have:

Imports System.Runtime.CompilerServices
Imports System.Reflection
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.DatabaseServices
Imports System.Threading.Tasks
Imports System.IO

Project References are:

AcCui, AcDbMgd, AcMgd, AcWindows, AdWindows, Autodesk.Autocad.Interop, and Autodesk.Autocad.interop.common

Granted, these are probably more than are required for the Save functionality, but i thought i'd include them just be safe... :smileyhappy:

 

If you're having issues with:

1. something called fme - change that to string.format()

2. Rocexception - change that to argumentexception

3. loginfo - change to console.writeline() or whatever your logging method is

 

if you have any other compile issues, post the messages and i can help you with them.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 12 of 26 (286 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-16-2014 12:10 PM in reply to: xpeter88

I have reference to accoremgd.dll (using A2014)

in addition to usual dll's

then this code should work:

                <CommandMethod("SaveActiveDrawing",CommandFlags.Session)> _
                Public Sub SaveActiveDrawing()
            Dim acDocMgr as DocumentCollection=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
            Dim acDoc As Document = acDocMgr.MdiActiveDocument
            Dim strDWGName As String = acDoc.Name
           'Lock document
            Dim docLock As DocumentLock = acDoc.LockDocument
            Using docLock
                Dim obj As Object = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("DWGTITLED")

                '' Check to see if the drawing has been named
                If System.Convert.ToInt16(obj) = 0 Then
                    '' If the drawing is using a default name (Drawing1, Drawing2, etc)
                    '' then provide a new name
                    strDWGName = "c:\MyDrawing.dwg"
                End If
                '' save thumbnail preview
              acDoc.Database.UpdateThumbnail=15
                '' Save the active drawing
                acDoc.Database.SaveAs(strDWGName, True, DwgVersion.Current, _
                	acDoc.Database.SecurityParameters)
                'Close Database
          acDoc.Database.CloseInput(True)

            End Using 
            'Close Document
            try
            	DocumentExtension.CloseAndDiscard(acDoc)
            Catch
            	End try
  
        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 13 of 26 (257 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-20-2014 10:05 AM in reply to: jon-p

Hmm no this does not work for me as well. Still the same error. I am running 2012 AutoCAD so I do not have AcCoreMgd.dll. That was present in 2013+ I think.

 

Is it really so difficult to SaveAs one drawing?

Contributor
jon-p
Posts: 18
Registered: ‎01-04-2013
Message 14 of 26 (254 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-20-2014 10:08 AM in reply to: xpeter88

Peter,

Did my code not work for you?  And, yes, in my experience, it really is that difficult to save a drawing... :smileysad:

-Jon

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 15 of 26 (248 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-20-2014 10:27 AM in reply to: jon-p

@Jon-P: unfortunately not, or not yet,...I was trying to fix all the error in code that I had but some of them I was not able to fix. I am still learning to VBA but I was expecting that it will be easier to "just" save the drawing.

Contributor
jon-p
Posts: 18
Registered: ‎01-04-2013
Message 16 of 26 (245 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-20-2014 10:34 AM in reply to: xpeter88

Do you have any specific errors? If you post them, I might be able to help you resolve them.

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 17 of 26 (233 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-21-2014 04:38 AM in reply to: jon-p

yes, sure, I will share them if you want to help me with them as soon as I get home :smileyhappy:

 

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 18 of 26 (217 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-21-2014 08:49 AM in reply to: xpeter88

@Jon-P: Here is what issues I have with code you posted. References and imports are exactly what you wrote.

 

2/3 issues you wrote I have fixed, that one missing is FMe if I replace FMe by string.format() it does not help. Except this one there is a few more :smileyhappy:

 

 

Error 4 'Exception' is ambiguous, imported from the namespaces or types 'Autodesk.AutoCAD.Runtime, System'. C:\Users\xxx\Documents\Visual Studio 2010\Projects\SaveAsExample\SaveAsExample\myCommands.vb 52 33 SaveAsExample

 

 

Error 6 'FMe' is not a member of 'String'. C:\Users\*\Documents\Visual Studio 2010\Projects\SaveAsExample\SaveAsExample\myCommands.vb 76 35 SaveAsExample

 

 

Error 5 'GetRealFilename' is not a member of 'Autodesk.AutoCAD.DatabaseServices.Database'. C:\Users\*\Documents\Visual Studio 2010\Projects\SaveAsExample\SaveAsExample\myCommands.vb 72 45 SaveAsExample

 

Error 3 'Save' is not a member of 'Autodesk.AutoCAD.ApplicationServices.Document'. C:\Users\*\Documents\Visual Studio 2010\Projects\SaveAsExample\SaveAsExample\myCommands.vb 51 25 SaveAsExample

 

Error 2 Extension methods can be defined only in modules. C:\Users\*\Documents\Visual Studio 2010\Projects\SaveAsExample\SaveAsExample\myCommands.vb 34 10 SaveAsExample

 

 

Error 7 Extension methods can be defined only in modules. C:\Users\*\Documents\Visual Studio 2010\Projects\SaveAsExample\SaveAsExample\myCommands.vb 86 10 SaveAsExample

 

Error 9 Extension methods can be defined only in modules. C:\Users\*\Documents\Visual Studio 2010\Projects\SaveAsExample\SaveAsExample\myCommands.vb 101 10 SaveAsExample

 

 

Error 8 Type 'Interop.AcadDocument' is not defined. C:\Users\*\Documents\Visual Studio 2010\Projects\SaveAsExample\SaveAsExample\myCommands.vb 89 25 SaveAsExample

 

I really cannot believe that to save the drawing as is so complicated 

Mentor
mzakiralam
Posts: 225
Registered: ‎11-09-2012
Message 19 of 26 (213 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-21-2014 10:16 AM in reply to: xpeter88

Error4 can be solved if you defined the namespace before Exception. Modified code should be "System.Exception" or "Autodesk.AutoCAD.Runtime.Exception". This is occuring as System namespace and Autodesk.AutoCAD.Runtime both contains 'Exception'. So while compiler start to compile it gets cofused.

 

For other error , you should also post your whole code. Then people can help you easily. But from your error message it is evident that you are trying to use some method or properties from a class which is not belongs to that class. As an example, Error5: 'GetRealFilename' is not a member of 'Autodesk.AutoCAD.DatabaseServices.Database'. I suppose that you are trying to get the current drawing name. If so then you can get the drawing path from document class. from below code snippet you can get the active document name. Please share your code so that one can help you.

Dim doc as Document = Application.DocumentManager.MdiActiveDocument
Dim fileName as string = Path.GetFileName(doc.Name)

 

Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 20 of 26 (207 Views)

Re: VB.NET SAVEAS / eFileAccessErr

01-21-2014 10:31 AM in reply to: mzakiralam

thanks I fixex error 4

the code is here (was posted by Jon-P in this topic just bit updated when I tried to fix the errors)

 

Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports System.Runtime.CompilerServices
Imports System.Reflection
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports System.Threading.Tasks
Imports System.IO
' This line is not mandatory, but improves loading performances
<Assembly: CommandClass(GetType(AutoCAD_VB_plug_in1.MyCommands))> 
Namespace AutoCAD_VB_plug_in1

    Public Class MyCommands
        ''' <summary>
        ''' saves the current drawing
        ''' </summary>
        ''' <param name="db">the database / drawing</param>
        ''' <remarks>We only had to write this because the autocad api is retarded</remarks>
        <Extension()>
        Public Sub SaveDamnYou(ByVal db As Database)
            Dim doc As Document = Nothing

            Try
                doc = DocumentManager.GetDocument(db)
            Catch
                'db is in batch mode
            End Try

            'If we have a document, attempt to call a quick save
            If doc IsNot Nothing Then
                If doc.IsReadOnly Then
                    Throw New ArgumentException("Save failed. Drawing is Read-Only.")
                Else

                    Try
                        doc.Save()
                    Catch ex As System.Exception
                        doDBSave(db)
                    End Try


                End If
            Else
                'If no document, attempt to save the database itself
                doDBSave(db)
            End If

        End Sub

        ''' <summary>
        ''' Attempts to save the database to itself, or logs an error if it fails
        ''' </summary>
        ''' <param name="db"></param>
        ''' <remarks></remarks>
        Public Sub doDBSave(ByVal db As Database)
            Try
                Dim DwgFilePath As String = db.GetRealFilename
                db.SaveAs(DwgFilePath, True, DwgVersion.Current, db.SecurityParameters)
            Catch ex As Autodesk.AutoCAD.Runtime.Exception

                Console.WriteLine("Acad Error Status: {0}".FMe(ex.ErrorStatus))
                Throw
            End Try
        End Sub

        ''' <summary>
        ''' Saves the document via COM
        ''' </summary>
        ''' <param name="doc">document to be saved </param>
        ''' <remarks>Used by the above save routine to allow a lock document to be saved, because the API is SUPER retarded</remarks>
        <Extension()>
        Public Sub Save(ByVal doc As Document)

            Dim adoc As Interop.AcadDocument = CType(doc.AcadDocument, Interop.AcadDocument)
            'adoc.Save()
            adoc.SendCommand("_QSAVE ")

        End Sub

        ''' <summary>
        ''' gets the real filename of the database. instead of .sv$ filenames
        ''' </summary>
        ''' <param name="db">the database / drawing</param>
        ''' <returns>returns the real filename</returns>
        ''' <remarks>http://through-the-interface.typepad.com/through_the_interface/2008/03/getting-the-ful.html</remarks...
        <Extension()>
        Public Function GetRealFilename(ByVal db As Database) As String
            Dim doc As Document = Nothing
            Try
                doc = DocumentManager.GetDocument(db)
            Catch
                'This error indicates that there is no document object
            End Try
            'is this open in batch mode?
            If doc Is Nothing Then
                Return db.Filename
            Else
                Return doc.Name
            End If
        End Function

    End Class
End Namespace

 

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