2 Replies Latest reply on Nov 24, 2016 5:36 AM by Artem Taturevych

    MacroFeature - Display error message

    Alexandre Gragnano

      Hello,

       

      I would like to display an error message after that the user clicks on OK button like this:

       

      error.png

       

      I tried: 2017 SOLIDWORKS API Help - Regenerate Method (ISwComFeature)

       

      dynamic ISwComFeature.Regenerate(object objApp, object objDoc, object objFeat)
      {
          var feat = (Feature)objFeat;
          var data = (MacroFeatureData)feat.GetDefinition();
          if (data.GetSelectionCount() == 0)
              return "Selection is empty";
          ...
          return true;
      }
      

       

      Result: Does not display any error message contrary to the documentation says :

      Return Value

      Any one of the following values:

      • True if the rebuild is successful (independent and modify)
      • False if the rebuild failed
      • String, as displayed in an error message to the user (see Remarks)
      • Body, if a body was created

       

      I tried: 2017 SOLIDWORKS API Help - OnClose Method (IPropertyManagerPage2Handler9)

       

      void IPropertyManagerPage2Handler9.OnClose(int reason)
      {
          if (reason == (int)swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay)
          {
              var mgr = (SelectionMgr)ModelDoc.SelectionManager;
              if (mgr.GetSelectedObjectCount2(mark) == 0)
                  throw new COMException("Selection is empty", 1);
              ...
          }
      }
      

       

      Result: Cancel the property page close but does not display any error message.

       

      Have you got an idea ?

      Thank you

        • Re: MacroFeature - Display error message
          Alexandre Gragnano

          OK,
          I found how to display it at creation time:

           

          void IPropertyManagerPage2Handler9.OnClose(int reason)
          {
              if (reason == (int)swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay)
              {
                  if (Feature == null)
                  {
                      Feature = ModelDoc.FeatureManager.InsertMacroFeature3
                      (
                          BaseName: "MacroFeature",
                          ProgId: "Namespace.MacroFeature",
                          MacroMethods: null,
                          ParamNames: new string[] { ParamName },
                          ParamTypes: new int[] { ParamType },
                          ParamValues: new string[] { ParamValue },
                          DimTypes: null,
                          DimValues: null,
                          EditBodies: null,
                          IconFiles: null,
                          Options: 0
                      );
                      if (Feature == null)
                      {
                          throw new COMException(null, 1);
                      }
                  }
                  else
                  {
                      var data = (MacroFeatureData)Feature.GetDefinition();
                      if (data != null)
                      {
                          var access = data.AccessSelections(ModelDoc, null);
                          if (access == true)
                          {
                              ... // Change data
                              var modify = Feature.ModifyDefinition(data, ModelDoc, null);
                              if (modify == false)
                              {
                                  throw new COMException(null, 1);
                              }
                          }
                      }
                  }
              }
          }
          

           

          With:

          dynamic ISwComFeature.Regenerate(object objApp, object objDoc, object objFeat)  
          {  
              var feat = (Feature)objFeat;  
              var data = (MacroFeatureData)feat.GetDefinition();  
              if (data.GetSelectionCount() == 0)  
                  return "Selection is empty";  
              ...  
              return true;  
          }
          

           

          It works at creation time but not at edition time.