.NET

Reply
Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 1 of 6 (239 Views)

Enable/Disable PopMenuItem

239 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
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 2 of 6 (236 Views)

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
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 3 of 6 (194 Views)

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
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 4 of 6 (185 Views)

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
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 5 of 6 (176 Views)

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
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 6 of 6 (161 Views)

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

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

Ask the Community