Have a play with this :
Compiled and tested in AC2012 with .NET Framework 4 in VS2010
//
// CodeHimBelonga KDUB 2011.11.13.
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcUtils = Autodesk.AutoCAD.Internal.Utils;
[assembly: CommandClass(typeof (KDUB_Testing.DXF4into.MyCommands))]
namespace KDUB_Testing.DXF4into
{
public class MyCommands
{
[CommandMethod("DXF4", CommandFlags.Modal | CommandFlags.Session)]
public void DXF4Into1() {
var doc = AcadApp.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
var db = doc.Database;
string[] fnlist = SelectDXFFile();
if (fnlist == null) {
return;
}
foreach (string fn in fnlist) {
ed.WriteMessage("\n" + fn);
var TmpDb = new Database(false, true);
TmpDb.DxfIn(fn, fn + ".log");
Matrix3d Transform = Matrix3d.Identity;
using (DocumentLock docLock = doc.LockDocument()) {
using (Transaction tr = doc.TransactionManager.StartTransaction()) {
db.Insert(Transform, TmpDb, true);
tr.Commit();
}
}
}
}
public string[] SelectDXFFile() {
var dialog = new OpenFileDialog {
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "dxf",
DereferenceLinks = true,
Filter = "DXF Files (*.dxf)|*.dxf|All files (*.*)|*.*",
Title = "Select dxf file",
Multiselect = true
};
if (dialog.ShowDialog() != DialogResult.OK) {
return null;
}
return dialog.FileNames;
}
}
}