AutoCAD Electrical General Discussion

AutoCAD Electrical General Discussion

Reply
New Member
ariegsecker
Posts: 2
Registered: ‎01-17-2014
Message 1 of 2 (88 Views)

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

88 Views, 1 Replies
01-17-2014 10:26 AM

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
*Expert Elite*
pendean
Posts: 22,187
Registered: ‎11-06-2003
Message 2 of 2 (64 Views)

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

01-18-2014 07:58 AM in reply to: ariegsecker
Customization forums for your questions are here: http://forums.autodesk.com/t5/AutoCAD-Customization
Dean Saadallah Blog | Facebook | Google+ | Twitter | PINS
Announcements
Manufacturing Community
The Manufacturing Community provides additional access to tips, tutorials, blogs and networking with peers.
Need installation help?

Start with some of our most frequented solutions to get help installing your software.

New AutoCAD Electrical Category!

The AutoCAD Electrical forum has moved into it's very own category page, and can no longer be found within the Additional Product Forums.