I'm not knowledgeable enough to suggest anything other than an asynchronous call to Close Command via IExtensionApplication.Initialize()
public void Initialize()
{
Document doc = acApp.DocumentManager.MdiActiveDocument;
if (doc.Name.Contains("TheDawgNameYouDontWantOpened"))
doc.SendStringToExecute("Close\n", false, false, true);
}
The Initialize method doesn't suit for this task.
** Edit - Perhaps it would be better to call that when the DocumentCreated Event is raised instead.
I already tried this method earlier, but received Fatal Error:
static void docMng_DocumentCreated(object sender, App.DocumentCollectionEventArgs e) {
if (e.Document != null)
e.Document.CloseAndDiscard();
}
And...
public void CloseDwgIf(Document doc)
{
if (doc.Name.Contains("TheDawgNameYouDontWantOpened"))
doc.SendStringToExecute("Close\n", false, false, true);
}
I already tried this method earlier too, but received Fatal Error again:
static void docMng_DocumentCreated(object sender, App.DocumentCollectionEventArgs e) {
if (e.Document != null)
e.Document.SendStringToExecute("Close\n", false, false, true);
}
BlackBox, try the your code before advising, please.
I mistakenly named the Class the same as one of the Methods within (
which has since been corrected, I changed TheSwamp.Sample.Events.CloseDwgIf to TheSwamp.Sample.Events.CloseDwgAtOpen)... I'll try to be more clear about when posting code written with Notepad++ in lieu of Visual Studio, Andrey.
My
Class-name-corrected code does properly Close Drawing1.dwg at Netload; however, I suspect this is due to all necessary initialization of said drawing being completed prior to Netload, as subsequent Qnew calls result in a new drawing, with Close at the command line, but no fatal error(s) result as you claim.
My code may not ultimately work for your needs here (
I was quite explicit in my initial post), but if fatal errors persist on your end, then there is something wrong with your code, my friend.
Not sure what version you're currently using, but you might consider
AutoLISP and VBA Security Controls in AutoCAD 2013 SP1.
As for your issue of the original suspect files, rather than attempting to 'veto' a drawing from opening (
if that's even possible from .NET API?), methinks your effort would be better served renaming the suspect file(s) if found via FindFile() call(s) when the DocumentCreated Event is raised which happens to be prior to any built-in user defined files are loaded in the startup sequence.
Once the malicious code has soiled your own .LSP, and .MNL files though, the only alternative is to be
'highly reactive' I'm afraid
. I sure hope you have good, nightly backups to restore from.