AutoCAD Electrical Forum
Welcome to Autodesk’s AutoCAD Electrical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Electrical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Paper Size array does not update on second running of custom plugin

1 REPLY 1
Reply
Message 1 of 2
ariegsecker
285 Views, 1 Reply

Paper Size array does not update on second running of custom plugin

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.

C# .NET Framework 4
1 REPLY 1
Message 2 of 2
pendean
in reply to: ariegsecker

Customization forums for your questions are here: http://forums.autodesk.com/t5/AutoCAD-Customization

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost