Jump to content

Recommended Posts

Posted (edited)

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 
DocumentDocument doc = AcadUtil.DocumentManager.Open(dxfFileName, false);

// Lock Document so nothing interferes
using (DocumentLock docLock = doc.LockDocument())
{ 

[indent]// Save drawing as DWG file
using (Transaction tr = doc.Database.TransactionManager.StartTransaction()​)
{        
[/indent]

[indent][indent]doc.Database.SaveAs(fileName + ".dwg", DwgVersion.Newest);
tr.Commit();    
[/indent]
}
[/indent]}

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

[indent]Application.DocumentManager.MdiActiveDocument = doc;    
[/indent]
}

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

// Close document
doc.CloseAndDiscard();

 

Code throws error on doc.CloseAndDiscard();

FatalExecutionEngineError was detected...

 

 

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.

Edited by Geomap_Chris
Posted
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 
DocumentDocument doc = AcadUtil.DocumentManager.Open(dxfFileName, false);

// Lock Document so nothing interferes
using (DocumentLock docLock = doc.LockDocument())
{ 

[indent]// Save drawing as DWG file
using (Transaction tr = doc.Database.TransactionManager.StartTransaction()​)
{        
[/indent]

[indent][indent]doc.Database.SaveAs(fileName + ".dwg", DwgVersion.Newest);
tr.Commit();    
[/indent]
}
[/indent]}

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

[indent]Application.DocumentManager.MdiActiveDocument = doc;    
[/indent]
}

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

// Close document
doc.CloseAndDiscard();

 

Code throws error on doc.CloseAndDiscard();

FatalExecutionEngineError was detected...

 

 

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.

 

You haven't posted your complete code, so hard to know for certain.

 

Is there a particular reason you're not using ReadDwgFile() Method to open DXF as a side Database in lieu of opening in the Editor?

 

Quick example:

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;

using System.IO;

namespace FOO
{
   public class BAR
   {
       void BAZ(string filePath)
       {
           if (!File.Exists(filePath))
               return;

           Document acDoc = Application.DocumentManager.MdiActiveDocument;
           Editor ed = acDoc.Editor;

           using (Database db = new Database(false, true))
           {
               try
               {
                   db.ReadDwgFile(filePath, System.IO.FileShare.Read, false, "");
               }
               catch (System.Exception)
               {
                   ed.WriteMessage(
                     "\nUnable to read drawing file."
                   );
                   return;
               }

               using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
               {
                   BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                   BlockTableRecord btr = 
                       (BlockTableRecord)tr.GetObject(bt[blockTableRecord.ModelSpace], OpenMode.ForRead);

                   foreach (ObjectId id in btr)
                   {
                       [color="red"]//<-- do something useful here[/color]
                   }
               }
           }
       }
   }
}

 

 

 

Cheers

Posted

My last response was regarding your #2 "copy it's database to a new dwg file" - but looking more closely at the code you did post, you're simply calling SAVEAS Command.

 

Have you tried instead simply using doc.Database.TransactionManager.StartOpenCloseTransaction()?

Posted

Sorry I said "copy the database" but what I really need to do is open a dxf file and then save it as a dwg. Nothing too fancy ;) I don't need to go through all the objects of the BlockTableRecord.

 

An even simpler version of this code worked flawlessly in Map 3D 2013, not even using transactions nor disposing the DocumentLock...

 


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


doc.LockDocument();


doc.Database.SaveAs(fileName + ".dwg", DwgVersion.Newest);


doc.CloseAndDiscard();


drawingFiles.Add(fileName + ".dwg");

 

Thanks for your help!!

Posted

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!

Posted

Verticals (for example, Civil 3D) are like an onion... Civil 3D is built on top of Map 3D, which is itself built on top of AutoCAD... You need only access the appropriate 'onion' layer (in this instance AutoCAD, not Map) in order to perform a given task. :thumbsup:

 

If you're NETLOADing your assembly (a plug-in, not stand alone app), then there's no need to even use AcadUtil (COM Object, which also makes your code environment dependent, i.e., x86 or x64), when you can use the Application.DocumentManager Object which is native to .NET API and compile to AnyCPU... I forget which framework implements dynamics (4.0?), but that is yet another way of precluding environment dependency (early/late binding), whilst utilizing COM (if that's the route you really want to take).

 

Also, you may find the Autoloader Mechanism to be of use, here's a recent thread that may help.

 

Cheers

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...