AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

.Net Document.CloseAndDiscard() throws error AutoCAD Map 3D 2014

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
creid
886 Views, 5 Replies

.Net Document.CloseAndDiscard() throws error AutoCAD Map 3D 2014

This was working in Map 3D 2013...

Basically, what I want to do is:

  1. open a dxf file
  2. copy it's database to a new dwg file
  3. close the dxf

 

I modified the code a little bit to try and make it work with Map 2014, but without success.

Here is my code now:

 

// Open dxf Document
Document doc = AcadUtil.DocumentManager.Open(dxfFileName, false);

// Lock Document so nothing interferes
using (DocumentLock docLock = doc.LockDocument())
{
    // Save drawing as DWG file
    using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
    {
        doc.Database.SaveAs(fileName + ".dwg", DwgVersion.Newest);
        tr.Commit();
    }

    // Set document active so we can close it
    if (Application.DocumentManager.MdiActiveDocument != doc)
    {
        Application.DocumentManager.MdiActiveDocument = doc;
    }

    // Dispose db
    doc.Database.Dispose();

    // Close document
    doc.CloseAndDiscard();
}

 

Code throws error on doc.CloseAndDiscard();

FatalExecutionEngineError was detected... (see attached screenshot for error details)

 

I have tryed multiple different things, and now I don't know what to do to make this work.

I read about system variable FIBERWORLD... It is set to 1.

 

What am I doing wrong??

 

Thanks for your help. 

5 REPLIES 5
Message 2 of 6
creid
in reply to: creid

Update:

I had misplaced my closing bracket for "using (DocumentLock...)"

Still getting the same error though

 

// Open dxf Document
Document doc = AcadUtil.DocumentManager.Open(dxfFileName, false);

// Lock Document so nothing interferes
using (DocumentLock docLock = doc.LockDocument())
{
    // Save drawing as DWG file
    using (Transaction tr = doc.Database.TransactionManager.StartTransaction()​)
    {
        doc.Database.SaveAs(fileName + ".dwg", DwgVersion.Newest);
        tr.Commit();
    }
}
// Set document active so we can close it
if (Application.DocumentManager.MdiActiveDocument != doc)
{
   Application.DocumentManager.MdiActiveDocument = doc;
}

// Dispose db
doc.Database.Dispose();

// Close document
doc.CloseAndDiscard();

 

 

Message 3 of 6
amanero
in reply to: creid

Hello,

 

I would suggest to comment the line where you dispose de document's database. That may be causing problems.

 

Regards.

Luis Alberto Manero, Geograma.com
Message 4 of 6
creid
in reply to: amanero

Thanks for the reply!
I had tried with and without disposing the doc's database. I just tried it again without disposing it and I'm still getting the same error.
Message 5 of 6
amanero
in reply to: creid

Hello Creid,

 

Based on your code, I have made a little change and it works for me:

 

        [CommandMethod("test")]
        public void test()
        {
            Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open("my document location");
            // Lock Document so nothing interferes
            using (DocumentLock docLock = doc.LockDocument())
            {
                // Save drawing as DWG file
                using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
                {
                    doc.Database.SaveAs("output.dwg", DwgVersion.Newest);
                    tr.Commit();
                }
            }
            /*
            // Set document active so we can close it
            if (Application.DocumentManager.MdiActiveDocument != doc)
            {
                Application.DocumentManager.MdiActiveDocument = doc;
            }

            // Dispose db
            doc.Database.Dispose();
            */
            // Close document
            doc.CloseAndDiscard();


        }

 

Could you give a try?

Luis Alberto Manero, Geograma.com
Message 6 of 6
creid
in reply to: amanero

Running my code outside debug environment by simply importing my dll in Map 3D 2014 worked!!!

Something in debug must corrupt the stack somehow...

 

Running my code further revealed another issue I had. I was declaring the FDO Provider (OSGeo.SQLServerSpatial) version in my config file.

Map 3D 2013 uses 3.7 but Map 3D 2014 uses 3.8.

I even realised you don't have to declare the FDO Provider's version at all and it still works!

 

Thanks for your help it is much appreciated!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost