@Ed__Jobe wrote:
Thanks @BlackBox_ Can you enlighten me on other methods that you are referring to which runs AcCoreConsole? I just know how to start it with a command line in a bat file. Where are you calling the command method? How are you loading the assembly before the dwg?
Enlighten? Probably not. Haha
I appreciate that Civil 3D team provides the standalone batch utility for batch processing via Core Console, but always found it cumbersome that I had to quit acad.exe, so I rolled my own LISP to do similar for a selection of drawings in parallel:
https://forums.augi.com/showthread.php?172630-Assign-Layer-State-to-Viewport&p=1339054&viewfull=1#po...
I also have a few tasks that I've grown accustom to running outside of CAD, using File Explorer shell menu; here's one of them:
https://www.theswamp.org/index.php?topic=51181.msg563128#msg563128
Don't forget that you can also load AutoCAD's ARX to do things in Core Console not possible by default, like call (layoutlist) in LISP/Script:
https://www.theswamp.org/index.php?topic=57471.msg609440#msg609440
As for .NET, here's a quick Sample, which calls a method on load (if active document is valid), and on subsequent documents opened (works in full AutoCAD or Core Console). Rather than revise the code to instead call CommandMethod, I'd simply NETLOAD the assembly and use Script to invoke the Command:
namespace Sample
{
class Events : IExtensionApplication
{
private static DocumentCollection acDocs = acApp.DocumentManager;
public void Initialize()
{
acApp.Idle += onIdle;
}
public void Terminate()
{
}
[CommandMethod("FOO", "DoSomethingUseful", CommandFlags.Session)]
public static void DoSomethingUseful()
{
//<-- do something useful
}
public static void onIdle(object sender, EventArgs e)
{
acApp.Idle -= onIdle;
Settings.Load();
acDocs.DocumentCreated += onDocumentCreated;
Document doc = acDocs.MdiActiveDocument;
if (doc != null)
{
doc.CommandWillStart += onCommandWillStart;
doc.Editor.WriteMessage("\nCore Console tools loaded. \n");
DoSomethingUseful();
}
}
private static void onDocumentCreated(object sender, DocumentCollectionEventArgs e)
{
if (e.Document != null && !e.Document.IsReadOnly)
{
e.Document.CommandWillStart += onCommandWillStart;
DoSomethingUseful();
}
}
//<snip>
}
}
HTH