18 Replies Latest reply on Jul 5, 2013 7:41 AM by Andrey Abdyushev

    Creating Add-in for C#

    Andrey Abdyushev

      Dll created by C #. Program code below:

       

      using System;

      using System.Collections.Generic;

      using System.Linq;

      using System.Text;

      using EdmLib;

       

       

      namespace SetInventarNumber_library

      {

          public class SetSerNo

          {

              private void IEdmAddin_GetAddInInfo(EdmLib.EdmAddInInfo poInfo, EdmLib.IEdmVault5 poVault, EdmLib.IEdmCmdMgr5 poCmdMgr)

              {

                  poInfo.mbsAddInName = "My first add-in";

                  poInfo.mbsCompany = "My";

                  poInfo.mbsDescription = "This is a very nice add-in.";

                  poInfo.mlAddInVersion = 1;

                  poInfo.mlRequiredVersionMajor = 5;

                  poInfo.mlRequiredVersionMinor = 2;

                  poCmdMgr.AddCmd( 1, "My first menu command");

              }

              private void IEdmAddIn5_OnCmd(EdmLib.EdmCmd poCmd, EdmLib.EdmCmdData ppoData)

              {

                  EdmVault5 Vault;

                  Vault = (EdmVault5)poCmd.mpoVault;

                  Vault.MsgBox(poCmd.mlParentWnd, "Hello World!");

                  string str = UpSreNo(Vault);

                  Vault.MsgBox(poCmd.mlParentWnd, str);

              }

       

              //************************************************************************************************//

              private string UpSreNo(EdmVault5 Vault)

              {

                  IEdmSerNoGen6 Generator = Vault.CreateUtility(EdmUtility.EdmUtil_SerNoGen);

                  string next_number = Generator.GenerateSerNo("Инвентарный номер подлинника");

                  return next_number;

              }

          }

      }

       

       

       

      when added to the Add - in an administrative tool gives an error:

      Please select at least one dll, which implements the interface IEdmAddin5

        • Re: Creating Add-in for C#
          Charley Saint

          Andrey,

           

          There are 2 things to check in the assembly properties for this error, make sure your assembly is COM visible:

          2013-07-01_0746.png

           

          Then make sure you have chosen not to embed interop types and the interop is copied locally:

          2013-07-01_0748.png

           

          After you compile you should get 2 dll's, select both when you are installing the add-in.

            • Re: Creating Add-in for C#
              Andrey Abdyushev

              I have not sent the correct code, it does not even compile. Here's the code is compiled. But this is C #, not VB. And you sent a sample solution to the problem VB.

               

              Below is the code with the implementation of the interface IEdmAddin5 in the language C #.

               

              using System;

              using System.Collections.Generic;

              using System.Linq;

              using System.Text;

              using EdmLib;

               

               

              namespace SetInventarNumber_library

              {

                  public class SetSerNo : IEdmAddIn5

                  {

                      public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)

                      {

                          poInfo.mbsAddInName = "My first add-in";

                          poInfo.mbsCompany = "SPC-ALMAZ-FAZOTRON";

                          poInfo.mbsDescription = "This is a very nice add-in.";

                          poInfo.mlAddInVersion = 1;

                          poInfo.mlRequiredVersionMajor = 5;

                          poInfo.mlRequiredVersionMinor = 2;

                          poCmdMgr.AddCmd(1, "My first menu command");

                      }

               

                      public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)

                      {

                          EdmVault5 Vault;

                          Vault = (EdmVault5)poCmd.mpoVault;

                          Vault.MsgBox(poCmd.mlParentWnd, "Hello World!");

                          string str = UpSreNo(Vault);

                          Vault.MsgBox(poCmd.mlParentWnd, str);

                      }

                      //************************************************************************************************//

                      private string UpSreNo(EdmVault5 Vault)

                      {

                          IEdmSerNoGen6 Generator = Vault.CreateUtility(EdmUtility.EdmUtil_SerNoGen);

                          string next_number = Generator.GenerateSerNo("Инвентарный номер подлинника");

                          return next_number;

                      }

                  }

              }

               

              In the first image, all as it should

              скриншот 1.png

              and that's what is shown in the second image is not in the C # project.

               

              The project compiles without errors. The result is a file SetInventarNumber_library.dll. But when you add the file to the administrative tool, there is the same error as before.

            • Re: Creating Add-in for C#
              Dan Miel

              Audrey

              There are templates for EPDM add-ins on the SolidWorks website that worked well for me. I set them up according to the instructions and when I start a new program in Visual Studio I select the template for the add-ins there are both VB and C# templates.

              Dan Miel

              EPDM 2013

              Visual Studio 2010

              • Re: Creating Add-in for C#
                Andrey Abdyushev

                But then there was the next problem.: Dll file is added, and in the context menu command is added "My first menu command", but when I call the command, nothing happens. Although the actions have to be generated in the method OnCMD:

                 

                 

                 

                 

                Or something I did not understand?

                public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)

                        {

                            EdmVault5 Vault = new EdmVault5();

                            Vault = (EdmVault5)poCmd.mpoVault;

                            Vault.MsgBox(poCmd.mlParentWnd, "Hello World!");

                 

                        }

                  • Re: Creating Add-in for C#
                    Charley Saint

                    Andrey,

                     

                    Sorry, one more setting still:

                    2013-07-03_0808_001.png

                    • Re: Creating Add-in for C#
                      Lee CS Young

                      And a couple of notes:

                       

                      public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)
                      {
                          // No need for the below line. The vault should be referenced from
                          // the EdmCmd struct.
                          // EdmVault5 Vault = new EdmVault5();
                          EdmVault5 Vault = (EdmVault5)poCmd.mpoVault;
                          // we should check for the correct type of command we're looking for.
                          if (poCmd.meCmdType == EdmCmdType.EdmCmd_Menu)
                          {
                              Vault.MsgBox(poCmd.mlParentWnd, "Hello World!");        
                          }
                      }
                      
                        • Re: Creating Add-in for C#
                          Andrey Abdyushev

                          Nothing is impossible. Describe the sequence of actions in full:

                          1. Create a new project (a class library Visual C #)

                          2. Add a link:

                          Библиотека.png

                           

                          Библиотека 2.png

                          3. Tune:

                          Сведения о сборке.png

                          Построение.png

                          4. I write code:

                          using System;

                          using System.Collections.Generic;

                          using System.Linq;

                          using System.Text;

                          using EdmLib;

                           

                          namespace TestAddin

                          {

                              public class Class1 : IEdmAddIn5

                              {

                                  public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)

                                  {

                                      poInfo.mbsAddInName = "My first add-in";

                                      poInfo.mbsCompany = "My organization";

                                      poInfo.mbsDescription = "This is a very nice add-in.";

                                      poInfo.mlAddInVersion = 1;

                                      poInfo.mlRequiredVersionMajor = 5;

                                      poInfo.mlRequiredVersionMinor = 2;

                                      poCmdMgr.AddCmd(1, "My first menu command v1");

                                  }

                                  public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)

                                  {

                                      EdmVault5 Vault = (EdmVault5)poCmd.mpoVault;

                                      if (poCmd.meCmdType == EdmCmdType.EdmCmd_Menu)

                                      {

                                          Vault.MsgBox(poCmd.mlParentWnd, "Hello World!");

                                      }

                                      Vault.MsgBox(poCmd.mlParentWnd, "Hello World!");

                                  }

                              }

                          }

                           

                          5. compile (Shift + F6)

                          6.Copy the 2 files in the directory "D: \ Testaddin": from the directory "Debug" - file TestAddin. dll, and from the directory obj\Debug file Interop.EdmLib.dll.

                          7. Go to the administration tool

                          добавление аадина.png

                          Добавление dll.png

                          добавилось.png

                          8. Reboot PC

                          9. Go to EPDM-client

                          запускаем.png

                          10. Nothing happens