Hello,
This is my first post so I apologize for any issues within it.
I am currently trying to write a custom plug in for AutoCAD electrical 2013. It is essentially for performing commands with a large number of drawings. My problem is this:
I can start the plugin and get it loaded perfectly fine. Everything works just as expected, the first time. The plugin connects to AutoCAD to gather information such as Printers available/supported and paper size. When the paper size array connects the first time it returns 46 items. Which is what it is meant to do. I print the documents, and close the plugin. Then using the command line I open the plugin again. This time the paper sizes do not populate. I honestly have no idea why, I assumed it would just go and regather the information. Any help on how to reset the array or whatever I might need to do would be greatly appreciated as I'm on a deadline for this project.
If possible C# code would be preferred as reading VB is difficult since I don't know that language. But any help in any form is welcome. Also I am coding with .NET Framework 4. My code for the fetching of paper sizes is this:
privatevoid refreshPrintPaperSizeComboBox()
{
printPaperSizeComboBox.Items.Clear();
AcadApplication acadApp = ConnectToAutoCAD();
string[] results = (acadApp.ActiveDocument.ActiveLayout.GetCanonicalMediaNames() asstring[]);
for (int i = 0; i < results.Length; i++)
{
printPaperSizeComboBox.Items.Add(acadApp.ActiveDocument.ActiveLayout.GetLocaleMediaName(results[i]));
}
}
The ConnectToAutoCAD() function is this:
private AcadApplication ConnectToAutoCAD()
{
AcadApplication acadApp = null;
string sAcadID = "AutoCAD.Application";
try
{
acadApp = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject(sAcadID);
}
catch
{
try
{
System.Type AcadProg = System.Type.GetTypeFromProgID(sAcadID);
acadApp = (AcadApplication)System.Activator.CreateInstance(AcadProg, true);
}
catch
{
MessageBox.Show("No Instance of " + sAcadID + " found!");
}
}
if (acadApp != null)
{
acadApp.Visible = true;
}
return acadApp;
}
Thank you again for any help.