Read unopened dwg file give fileaccesserr

Read unopened dwg file give fileaccesserr

stefanveurink68AXD
Advocate Advocate
475 Views
2 Replies
Message 1 of 3

Read unopened dwg file give fileaccesserr

stefanveurink68AXD
Advocate
Advocate

Sorry for asking this, I'm sure i'm doing something stupid, but can't get it to work and can't find the answer. Tried several combinations, all give me a efileaccesserr when trying to read unopened dwg-file. 

 

for example by: 

Database db = new Database(false, true);
using (db)
{db.ReadDwgFile(path, FileOpenMode.OpenForReadAndAllShare, true, "");

or even with: 

DocumentCollection acDocMgr=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
Document acNewDoc = acDocMgr.Add(path);

it immediatly gives me the error. it's the first lines in my code. 

 

the "path"variable contains the path, as you might have expected. 

0 Likes
Accepted solutions (1)
476 Views
2 Replies
Replies (2)
Message 2 of 3

stefanveurink68AXD
Advocate
Advocate

By the way, should have mentioned I'm trying to read an dwg file that's not opened in autocad. I need to find out which layouts are in it. But to know that I first have to access it. 

 

Tried to docklock it but then I first need to call it a document, what i'm trying to do with the second piece of code. But don't even get the chance to call it a document cause even there I get the eFileAccesErr. If the dwg file would be open doclock it would be easy, there's no trouble with that.  

0 Likes
Message 3 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

There's nothing wrong in the little snippet you posted. The issue is elsewhere, perhaps in the file itself or its path.

 

You can try with someting like this:

        [CommandMethod("TEST")]
        public static void Test()
        {
            var ofd = new OpenFileDialog() { 
                Filter = "Drawings (*.dwg)|*.dwg", 
                Title = "File to get layouts from" };
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var layoutNames = new List<string>();
                using (var db = new Database(false, true))
                {
                    db.ReadDwgFile(ofd.FileName, FileOpenMode.OpenForReadAndAllShare, true, "");
                    using (var tr = db.TransactionManager.StartOpenCloseTransaction())
                    {
                        var layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                        foreach (DBDictionaryEntry entry in layouts)
                        {
                            layoutNames.Add(entry.Key);
                        }
                        tr.Commit();
                    }
                }
                AcAp.ShowAlertDialog(string.Join("\n", layoutNames));
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub