MessageBox from inside a C# Inventor plugin

MessageBox from inside a C# Inventor plugin

oransen
Collaborator Collaborator
1,023 Views
4 Replies
Message 1 of 5

MessageBox from inside a C# Inventor plugin

oransen
Collaborator
Collaborator

A simple question, in here I'd like to show a message box...

        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This method is called by Inventor when it loads the addin.
            // The AddInSiteObject provides access to the Inventor Application object.
            // The FirstTime flag indicates if the addin is loaded for the first time.

            // Initialize AddIn members.
            m_inventorApplication = addInSiteObject.Application;

            // ********************************  
            // how to put a message box here?
            // ********************************  

        }

 

...I've tried using the normal Forms.MessageBox.Show stuff but it does not exist in this context. Is there a native Inventor message box function?

 

0 Likes
Accepted solutions (2)
1,024 Views
4 Replies
Replies (4)
Message 2 of 5

JhoelForshav
Mentor
Mentor

Hi @oransen 

Have you tried adding a reference to System.Windows.Forms in your project? 🙂

0 Likes
Message 3 of 5

oransen
Collaborator
Collaborator

That does not seem to be available, only Input and Markup

 

oransen_0-1629287679845.png

 

...and...

 

oransen_1-1629287727938.png

 

I wonder what I am missing....

 

 

 

0 Likes
Message 4 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @oransen 

You need to add it to your references in your Visual Studio project.

references.PNG

Right-click references in your project and add reference. It should be in a path like:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Windows.Forms.dll

Depending on your .NET-framework.

Message 5 of 5

Michael.Navara
Advisor
Advisor
Accepted solution

@JhoelForshav  you are right. But usually you need reference to System.Drawing too.

When you insert new form to your project, all required references are added automatically. Unwanted Form1 can be deleted.

 

@oransen You can use build-in "message box" inventorApp.CommandManager.PromptMessage(...), but its usage is little bit obscure. See API reference for more information.

Advantage of this is when Inventor is in silent mode, this PromptMessage is not displayed and don't block application.

When you use MessageBox, this is displayed always and user MUST close them. This may be a trouble when you run some automatic task without user interaction.