I didn't see this problem on my end
Try for comparing:
#region "Batch example"
[CommandMethod("ProcFiles", CommandFlags.Session)]
public void Yeah()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
FileInfo[] myFiles = GetAllFiles(@"C:\Test\BATM\BatchRemFields", true);
BatchFolderFiles(myFiles);
}
public FileInfo[] GetAllFiles(string dirName, bool include)
{
DirectoryInfo dir = new DirectoryInfo(dirName);
if (!dir.Exists)
{
return null;
}
else
{
FileInfo[] myFiles = dir.GetFiles("*.dwg", include ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
return myFiles;
}
}
public void BatchFolderFiles(FileInfo[] Files)
{
acadApp.MainWindow.Visible = true;
//get current document
Document cdoc = acadApp.DocumentManager.MdiActiveDocument;
Document dwg = null;
try
{
// iterate through files
foreach (FileInfo file in Files)
{
// Open file
dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(file.FullName, false);
//Activate file to be proceed. It is very important
if (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument != dwg)
{
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = dwg;
}
//-------------------------------------------------//
// your code goes here
//e.g.:
using (DocumentLock dwglock = dwg.LockDocument())
{
using (Database db = dwg.Database)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
using (BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord)
{
using (Line ln = new Line(new Point3d(0, 0, 0), new Point3d(100, 100, 0)))
{
ln.ColorIndex = 1;
btr.AppendEntity(ln);
tr.AddNewlyCreatedDBObject(ln, true);
}
using (DBText txt = new DBText())
{
txt.SetDatabaseDefaults();
txt.Position = new Point3d(100, 100, 0);
txt.TextString = "Batch example";
txt.Height = 12.5;
txt.Rotation = Math.PI / 4;
btr.AppendEntity(txt);
tr.AddNewlyCreatedDBObject(txt, true);
}
}
tr.Commit();
}
}
}
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = cdoc;
dwg.CloseAndSave(file.FullName);
}
}
catch (System.Exception ex)
{
acadApp.ShowAlertDialog(ex.Message + "\n" + ex.StackTrace);
//If eroror then close without saving changes
dwg.CloseAndDiscard();
}
finally
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Check result");
}
}
_____________________________________
C6309D9E0751D165D0934D0621DFF27919