2 Replies Latest reply on Jan 30, 2018 4:41 PM by Dennis Beeren

    How to get ActiveDoc in EnableMethod(string s) of CommandItem

    Dennis Beeren

      I would like to set the enable setting of a command item (toolbar button) based on the parameter s and the active doc type (swDocumentTypes_e), but I am not able to get the active doc in the EnableMethod. This Method is in the class implementing ISwAddin. Here's the code of my EnableMethod():

       

      /**
               * Called before loading command item
               * to determine if this command item has to 
               * be enabled for the current document type.
               * 
               * @param s: 1 -> parts | 2 -> assemblies | 3 -> parts & assemblies |
               *           4 -> drawings | 5 -> parts & drawings | 6 -> assemblies & drawings
               *           7 -> parts & assemblies & drawings
               * */
              public int EnableMethod(string s)
              {
                  ModelDoc2 model = mySWApp.ActiveDoc();
      
                  if (model != null)
                  {
                      int docType = model.GetType();
                      int i = int.Parse(s);
      
                      if (docType == (int)swDocumentTypes_e.swDocPART && (i == 1 || i == 3 || i == 5 || i == 7))
                      {
                          return 1;
                      }
                      else if (docType == (int)swDocumentTypes_e.swDocASSEMBLY && (i == 2 || i == 3 || i == 6 || i == 7))
                      {
                          return 1;
                      }
                      else if ((docType == (int)swDocumentTypes_e.swDocASSEMBLY && i > 3))
                      {
                          return 1;
                      }
                      else
                      {
                          return 0;
                      }
                  }
                  else
                  {
                      return 0;
                  }
              }
      

       

      I wonder what I am doing wrong here and what would be a way to do this. I would like to determine for each command item if it should be enabled, based on the document type. Any help is appreciated.