10 Replies Latest reply on Jun 24, 2016 3:46 AM by Mario Zahren

    Epdm AddIn -> Button on Datacard

    Mario Zahren

      Hello everybody.

      I have created an addin that should be activated by a push of a button on the data card. This addin writes values in variable fields.

      Therefore I use the function "poCmdMgr.AddHook (EdmCmdType.EdmCmd_CardButton);"

       

      In debug mode everything is going well if I have a file selected but if I do start a search, I get the following error message "0x080004003 - an invalid pointer was supplied to the method"

       

      Here the code I have created

       

      using System;
      using Microsoft.VisualBasic;
      using EdmLib;
      using System.Runtime.InteropServices;
      
      namespace CardButtonControl
      {
          public class CardButton : IEdmAddIn5
          {
              public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
              {  
                  poInfo.mbsAddInName = "CardButtons";
                  poInfo.mbsCompany = "Mario Boelingen";
                  poInfo.mbsDescription = "Knöpfe auf Datenkarte.";
                  poInfo.mlAddInVersion = 1002;
      
                  poInfo.mlRequiredVersionMajor = 14;
                  poInfo.mlRequiredVersionMinor = 3;
      
                  poCmdMgr.AddHook(EdmCmdType.EdmCmd_CardButton);
              }
      
              public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)
              {
                  IEdmVault5 vault = new EdmVault5() as IEdmVault5;
                  vault.LoginAuto("hegenscheidt", 0);
      
                  const string varNameProduktArt = "HS_Produktart";
                  const string varNameProduktArtLong = "HS_ProduktartLang";
                  const string varNameArtikelart = "HS_Artikelart";
                  const string varNameArtikelArtLong = "HS_ArtikelartLang";
                  const string varNameProdKlasse = "HS_Produktklasse";
                  const string varNameProdKlasseLong = "HS_ProduktklasseLang";
                  const string varNameArtikelGruppe = "HS_Artikelgruppe";
                  const string varNameArtikelGruppeLong = "HS_ArtikelGrpLang";
                  const string varNameProduktBereich = "HS_Produktbereich";
                  const string varNameTeileArt = "HS_Teileart";
      
                  string varValProduktArt = null;
                  string varValProduktArtLong = null;
                  string varValArtikelArt = null;
                  string varValArtikelArtLong = null;
                  string varValProdKlasse = null;
                  string varValProdKlasseLong = null;
                  string varValArtikelGruppe = null;
                  string varValArtikelGruppeLong = null;
                  string varValProduktBereich = null;
                  string varValTeileArt = null;
                  
                  string ConfigName = null;
                  string filePath = null;
      
                  int index = 0;
                  int last = 0;
                  index = Information.LBound(ppoData);
                  last = Information.UBound(ppoData);
                  int FileID = 0;
                  int FolderID = 0;
      
                  FileID = ((EdmCmdData)ppoData.GetValue(index)).mlObjectID1;
                  FolderID = ((EdmCmdData)ppoData.GetValue(index)).mlObjectID2;
                  ConfigName = ((EdmCmdData)ppoData.GetValue(index)).mbsStrData1;
                  filePath = ((EdmCmdData)ppoData.GetValue(index)).mbsStrData2;
      
                  IEdmFile8 File = default(IEdmFile8);
                  IEdmFolder5 ppoRetParentFolder;
                  File = (IEdmFile8)vault.GetFileFromPath(filePath, out ppoRetParentFolder);
      
                  IEdmEnumeratorVariable8 varEnum1 = default(IEdmEnumeratorVariable8);
                  varEnum1 = (IEdmEnumeratorVariable8)File.GetEnumeratorVariable();
      
                  try
                  {
                      switch (poCmd.mbsComment)
                      {
                          #region case Pb1SetFertMech
                          case "Pb1SetFertMech":
                              varValProduktArt = "004";
                              varValProduktArtLong = "Fertigungsteile";
                              varValArtikelArt = "F";
                              varValArtikelArtLong = "Fertigungsartikel";
                              varValProdKlasse = "110045";
                              varValProdKlasseLong = "anonymer Maschinenvorrat PB I";
                              varValArtikelGruppe = "025";
                              varValArtikelGruppeLong = "Eigenfert. anonym Maschine";
                              varValProduktBereich = "PB 1";
                              varValTeileArt = "Fertigungsteil Mech.";
                              
                              varEnum1.SetVar(varNameProduktArt, ConfigName, varValProduktArt);
                              varEnum1.SetVar(varNameProduktArtLong, ConfigName, varValProduktArtLong);
                              varEnum1.SetVar(varNameArtikelArt, ConfigName, varValArtikelArt);
                              varEnum1.SetVar(varNameArtikelArtLong, ConfigName, varValArtikelArtLong);
                              varEnum1.SetVar(varNameProdKlasse, ConfigName, varValProdKlasse);
                              varEnum1.SetVar(varNameProdKlasseLong, ConfigName, varValProdKlasseLong);
                              varEnum1.SetVar(varNameArtikelGruppe, ConfigName, varValArtikelGruppe);
                              varEnum1.SetVar(varNameArtikelGruppeLong, ConfigName, varValArtikelGruppeLong);
                              varEnum1.SetVar(varNameProduktBereich, ConfigName, varValProduktBereich);
                              varEnum1.SetVar(varNameTeileArt, ConfigName, varValTeileArt);
                              varEnum1.CloseFile(true);
                              break;
                              #endregion
      
                          #region case Pb1SetFertAufgl
                          case "Pb1SetFertAufgl":
                              blablabla
                          #endregion
                      }
      
                  }
      
                  catch (COMException exp)
                  {
                      string errorName, errorDesc;
                      vault.GetErrorString(exp.ErrorCode, out errorName, out errorDesc);
                      vault.MsgBox(0, errorDesc, EdmMBoxType.EdmMbt_OKOnly, errorName);
                  }
      
              }
      
          }
      
      }
      

       

      What am I doing wrong??

      Any help would bo great!

       

      Mario

        • Re: Epdm AddIn -> Button on Datacard
          Lee CS Young

          A card button hook will get called on pressing search, enter, and cancel. You need to specifically check that it's your button being pressed. You should set a string for the button command in the card editor, and then check that string in code.

           

          if (poCmd.mbsComment == "MyCommandString")
          {
           //dowork
          }
          
            • Re: Epdm AddIn -> Button on Datacard
              Mario Zahren

              Hello Lee.

               

              Thanks for the answer but unfortunately it does not work. Please take a look at line 22.

               

              using System;
              using Microsoft.VisualBasic;
              using EdmLib;
              using System.Runtime.InteropServices;
              
              namespace CardButtonControl
              {
                  public class CardButton : IEdmAddIn5
                  {
                      public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
                      {  
                          poInfo.mbsAddInName = "CardButtons";
                          poInfo.mbsCompany = "Mario Boelingen";
                          poInfo.mbsDescription = "Knöpfe auf Datenkarte.";
                          poInfo.mlAddInVersion = 1002;
                          poInfo.mlRequiredVersionMajor = 14;
                          poInfo.mlRequiredVersionMinor = 3;
                          poCmdMgr.AddHook(EdmCmdType.EdmCmd_CardButton);
                      }
                      public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)
                      {
                          if (!(String.IsNullOrEmpty(poCmd.mbsComment))) //I also tried  -> if(poCmd.mbsComment != "") <-
                          {
                              IEdmVault5 vault = new EdmVault5() as IEdmVault5;
                              vault.LoginAuto("hegenscheidt", 0);
              
                              const string varNameProduktArt = "HS_Produktart";
                              const string varNameProduktArtLong = "HS_ProduktartLang";
                              const string varNameArtikelArt = "HS_Artikelart";
                              const string varNameArtikelArtLong = "HS_ArtikelartLang";
                              const string varNameProdKlasse = "HS_Produktklasse";
                              const string varNameProdKlasseLong = "HS_ProduktklasseLang";
                              const string varNameArtikelGruppe = "HS_Artikelgruppe";
                              const string varNameArtikelGruppeLong = "HS_ArtikelGrpLang";
                              const string varNameProduktBereich = "HS_Produktbereich";
                              const string varNameTeileArt = "HS_Teileart";
              
                              string varValProduktArt = "";
                              string varValProduktArtLong = "";
                              string varValArtikelArt = "";
                              string varValArtikelArtLong = "";
                              string varValProdKlasse = "";
                              string varValProdKlasseLong = "";
                              string varValArtikelGruppe = "";
                              string varValArtikelGruppeLong = "";
                              string varValProduktBereich = "";
                              string varValTeileArt = "";                
                              string ConfigName = "";
                              string filePath = "";
                              int index = 0;
                              int last = 0;
                              index = Information.LBound(ppoData);
                              last = Information.UBound(ppoData);
                              int FileID = 0;
                              int FolderID = 0;
              
                              FileID = ((EdmCmdData)ppoData.GetValue(index)).mlObjectID1;
                              FolderID = ((EdmCmdData)ppoData.GetValue(index)).mlObjectID2;
                              ConfigName = ((EdmCmdData)ppoData.GetValue(index)).mbsStrData1;
                              filePath = ((EdmCmdData)ppoData.GetValue(index)).mbsStrData2;
                              IEdmFile8 File = default(IEdmFile8);
                              IEdmFolder5 ppoRetParentFolder;
                              File = (IEdmFile8)vault.GetFileFromPath(filePath, out ppoRetParentFolder);
                              IEdmEnumeratorVariable8 varEnum1 = default(IEdmEnumeratorVariable8);
                              varEnum1 = (IEdmEnumeratorVariable8)File.GetEnumeratorVariable();
              
                              try
                              {
                                  switch (poCmd.mbsComment)
                                  {
                                      #region case Pb1SetFertMech
                                      case "Pb1SetFertMech":
                                          varValProduktArt = "004";
                                          varValProduktArtLong = "Fertigungsteile";
                                          varValArtikelArt = "F";
                                          varValArtikelArtLong = "Fertigungsartikel";
                                          varValProdKlasse = "110045";
                                          varValProdKlasseLong = "anonymer Maschinenvorrat PB I";
                                          varValArtikelGruppe = "025";
                                          varValArtikelGruppeLong = "Eigenfert. anonym Maschine";
                                          varValProduktBereich = "PB 1";
                                          varValTeileArt = "Fertigungsteil Mech.";
                                          
                                          varEnum1.SetVar(varNameProduktArt, ConfigName, varValProduktArt);
                                          varEnum1.SetVar(varNameProduktArtLong, ConfigName, varValProduktArtLong);
                                          varEnum1.SetVar(varNameArtikelArt, ConfigName, varValArtikelArt);
                                          varEnum1.SetVar(varNameArtikelArtLong, ConfigName, varValArtikelArtLong);
                                          varEnum1.SetVar(varNameProdKlasse, ConfigName, varValProdKlasse);
                                          varEnum1.SetVar(varNameProdKlasseLong, ConfigName, varValProdKlasseLong);
                                          varEnum1.SetVar(varNameArtikelGruppe, ConfigName, varValArtikelGruppe);
                                          varEnum1.SetVar(varNameArtikelGruppeLong, ConfigName, varValArtikelGruppeLong);
                                          varEnum1.SetVar(varNameProduktBereich, ConfigName, varValProduktBereich);
                                          varEnum1.SetVar(varNameTeileArt, ConfigName, varValTeileArt);
                                          varEnum1.CloseFile(true);
                                          break;
                                          #endregion
              
                                      #region case Pb1SetFertAufgl
                                      case "Pb1SetFertAufgl":
                                          //blablabla
                                      #endregion
                                  }
                              }
                              catch (COMException exp)
                              {
                                  string errorName, errorDesc;
                                  vault.GetErrorString(exp.ErrorCode, out errorName, out errorDesc);
                                  vault.MsgBox(0, errorDesc, EdmMBoxType.EdmMbt_OKOnly, errorName);
                              }
                          }
                          else
                          {
                              return;
                          }
                      }
                  }
              }
              
              

               

              The result is the same.

              Any ideas?

               

              Mario

            • Re: Epdm AddIn -> Button on Datacard
              Lee CS Young

              Have a look at this topic in the help file. Note the setup of the datacard and source. You're also not checking to make sure it's a card button that's being called.

               

              1. if (poCmd.meCmdType == EdmCmdType.EdmCmd_CardButton)

               

              • Re: Epdm AddIn -> Button on Datacard
                Artem Taturevych

                Hi Mario,

                 

                What line is causing the exception?

                 

                You also do not need to create a vault instance and login in the add-in but get the instance from the poCmd.

                 

                IEdmVault5 vault = new EdmVault5() as IEdmVault5; 

                vault.LoginAuto("hegenscheidt", 0); 

                 

                IEdmVault5 vault = poCmd.mpoVault as IEdmVault5;

                Thanks,

                Artem

                  • Re: Epdm AddIn -> Button on Datacard
                    Mario Zahren

                    Hi Artem,

                    unfortunately I do not know where the problem occurs because I do not see that in the debugger.

                    I debug the class with notepad.exe in mode "Debug Add-ins" in epdm.

                    Here the code:

                     

                    public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)
                    {
                        if (poCmd.meCmdType == EdmCmdType.EdmCmd_CardButton)
                        { 
                            if (!(string.IsNullOrEmpty(poCmd.mbsComment)))
                            {
                                IEdmVault5 vault = poCmd.mpoVault as IEdmVault5;
                                try
                                {
                                    //Code
                                }
                                catch (COMException exp)
                                {
                                    string errorName, errorDesc;
                                    vault.GetErrorString(exp.ErrorCode, out errorName, out errorDesc);
                                    vault.MsgBox(0, errorDesc, EdmMBoxType.EdmMbt_OKOnly, errorName);
                                }
                            }
                                        return;
                        }
                                    return;
                    }    
                    

                     

                    FYI

                    The AddIn is loaded in "Debug Add-ins".

                    Then I try to search for something e.g. logged in users...

                    Perhaps this helps?

                    Mario