Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
bindlmi
in reply to: jjstr8

The proposal with the UserInterfaceEvents:
This works very well, even if it doesn't look as elegant as the other suggestions.
Here is the code for the UserInterfaceEvent:

    public class Plugin : ApplicationAddInServer
    {
        public static Inventor.Application m_inventorApplication;
        public static ControlDefinitions m_ConDefs;
        private UserInterfaceEvents m_UserInterfaceEvents;

        public void Activate(ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            try
            {
                // define globals
                m_inventorApplication = addInSiteObject.Application;
                m_ConDefs = m_inventorApplication.CommandManager.ControlDefinitions;
                m_UserInterfaceEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents;

                // attach to UserInterfaceEvent
                m_UserInterfaceEvents.OnEnvironmentChange += UserInterfaceEvents_OnEnvironmentChange;

            }
            catch
            {
            }

        }

        private void UserInterfaceEvents_OnEnvironmentChange(Inventor.Environment environment, EnvironmentStateEnum environmentState, EventTimingEnum beforeOrAfter, NameValueMap context, out HandlingCodeEnum handlingCode)
        {
            handlingCode = HandlingCodeEnum.kEventNotHandled;

            try
            {
                if ((environmentState == EnvironmentStateEnum.kActivateEnvironmentState || environmentState == EnvironmentStateEnum.kResumeEnvironmentState) && beforeOrAfter == EventTimingEnum.kAfter)
                {
                    switch (environment.InternalName)
                    {
                        // activate my commmand only in drawings
                        case "DLxDrawingEnvironment":
                            m_ConDefs["myDrawingButtonInternalName"].Enabled = true;
                            break;
                        default:
                            m_ConDefs["myDrawingButtonInternalName"].Enabled = false;
                            break;
                    }
                }
            }
            catch
            {
            }
        }

        public void Deactivate()
        {
            m_UserInterfaceEvents.OnEnvironmentChange -= UserInterfaceEvents_OnEnvironmentChange;
        }
	}

Many thanks for your help. If you have any ideas about the other suggestions, I'd be happy to test them.