.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
How to disable the macro dialogbox by program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi, I have a program (C#.NET) that opens files in a batch by using the DocumentManager.Open() method.
The first problem is , if one of the files has a macro, the vba dialogbox appears which interrupts the progress. How can I disable the macro and block the dialogbox?
Another problem is, it will take a very long time to open a file by the CAD application after processing 10 or 20 files later. I have closed the file and disposed the document object by using the Dispose() method after opening. The application looks like crashing and the memory used by CAD is up to 200~300M which is only 50~80M when the first sevral files was processed.
Anyone can help?
Thanks.
Re: How to disable the macro dialogbox by program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.D ocumentManager.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.D ocumentManager.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.D ocumentManager.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.S howAlertDialog("Check result");
}
}
C6309D9E0751D165D0934D0621DFF27919
Re: How to disable the macro dialogbox by program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thank you, Hallex. I will take a look
Re: How to disable the macro dialogbox by program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: How to disable the macro dialogbox by program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
The first problem has been resolved. It is another function of my program that leads the issue, and I have disabled the module. The program works fine now.
Deleting the embedded VBA is just the method which I am using by. Before openning dwg-files, you have to read them to the database first, delete the embedded vba, then save them. Is there another method better to disable the dialogbox directly?
Please forgive my poor english. Thank you all.
