.NET

Reply
Valued Contributor
95 Posts
3 Kudos
Registered: ‎04-04-2012
Post 1 of 6

Enable/Disable PopMenuItem

280 Views, 5 Replies
12-24-2012 12:57 AM

ObjectARX Version: 2010

Language: C#

 

Hi, I am using PopMenuItem (MenuBar item) by loading custom CUIX.

But I can only load it to the menubar.

I would like to enable or disable the menu item according to the system status.

For example, if no drawing document is open, "Save" menuitem in the "File" menu becomes disable (non-clickable).

And as I open or create a document, "Save" menuitem becomes enable (clickable).

I want to use this for my custom menubar menu.

How could I do this?

 

If you could give me a sample code snippet, it would be appreciated.

 

Thank you in advance,

 

Jake

Moderator
1,468 Posts
277 Kudos
Registered: ‎04-09-2008
Post 2 of 6

Re: Enable/Disable PopMenuItem

12-24-2012 01:02 AM in reply to: dynamicscope

PopupMenuItem has property Enable, which can help you.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
95 Posts
3 Kudos
Registered: ‎04-04-2012
Post 3 of 6

Re: Enable/Disable PopMenuItem

12-25-2012 08:34 PM in reply to: Alexander.Rivilis

It looks like, in ARX 2010, PopMenuItem does not have "Enable" property.

 

capture.PNG

Moderator
1,468 Posts
277 Kudos
Registered: ‎04-09-2008
Post 4 of 6

Re: Enable/Disable PopMenuItem

12-25-2012 10:19 PM in reply to: dynamicscope

I did not write about the class Autodesk.AutoCAD.Customization.PopMenuItem, but the class Autodesk.AutoCAD.Interop.PopMenuItem wich can be accessible with Autodesk.AutoCAD.Interop.dll:

26-12-2012 8-17-29.png


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
95 Posts
3 Kudos
Registered: ‎04-04-2012
Post 5 of 6

Re: Enable/Disable PopMenuItem

12-26-2012 12:00 AM in reply to: Alexander.Rivilis

I see.. I see..

 

Did not know there was  Autodesk.AutoCAD.Interop.PopMenuItem as well.

I will check that out.

 

Thank you.

Moderator
1,468 Posts
277 Kudos
Registered: ‎04-09-2008
Post 6 of 6

Re: Enable/Disable PopMenuItem

12-26-2012 03:15 AM in reply to: dynamicscope

Disable/enable menu item Save:

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcX = Autodesk.AutoCAD.Interop;

[assembly: CommandClass(typeof(Rivilis.MenuTest))]

namespace Rivilis
{

  public class MenuTest
  {
    [CommandMethod("ToggleSave")]
    public void ToggleSave()
    {
      AcX.AcadApplication app = AcAp.Application.AcadApplication as AcX.AcadApplication;
      if (app != null) {
        AcX.AcadMenuGroups groups = app.MenuGroups;
        foreach (AcX.AcadMenuGroup group in groups) {
          // We want work only with menugroup ACAD
          if (group.Name.ToUpper().CompareTo("ACAD") == 0)  { 
            AcX.AcadPopupMenus menus = group.Menus;
            if (menus.Count > 0) {
              foreach (AcX.AcadPopupMenu menu in menus) {
                foreach (AcX.AcadPopupMenuItem menuitem in menu) {
                  string label = menuitem.Label;
                  string caption = menuitem.Caption;
                  string tagstring = menuitem.TagString;
                  if (tagstring.ToUpper().CompareTo("ID_SAVE") == 0) {
                    // Toggle status of PopupMenuItem
                    menuitem.Enable = !menuitem.Enable; 
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!