I use .NET framework and C# language to customize Autocad software.
I have problem with save drawing file.
Autocad 2024
In Autocad developing i have problem with saving active drawing file.
I’m trying to use the following code to save file.
But, i give exception error like:
“Autodesk.AutoCAD.Runtime.Exception: ‘eFileAccessErr'” Or, “internal error: !dbobji!.cpp@8668: eNotOpenForWrite”
`
// (C) Copyright 2024 by
//
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(Strore_lab01.MyCommands))]
namespace Strore_lab01
{
// This class is instantiated by AutoCAD for each document when
// a command is called by the user the first time in the context
// of a given document. In other words, non static data in this class
// is implicitly per-document!
public class MyCommands
{
[CommandMethod("SaveActiveDrawing")]
public static void SaveActiveDrawing()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
string strDWGName = acDoc.Name;
object obj = Application.GetSystemVariable("DWGTITLED");
// Check to see if the drawing has been named
if (System.Convert.ToInt16(obj) == 0)
{
// If the drawing is using a default name (Drawing1, Drawing2, etc)
// then provide a new name
strDWGName = "c:\MyDrawing.dwg";
}
// Save the active drawing
acDoc.Database.SaveAs(strDWGName, true, DwgVersion.Current, acDoc.Database.SecurityParameters);
}
}
}
`
1