6 Replies Latest reply on Aug 9, 2017 11:57 AM by Simon Turner

    EdmBomInfo Quirk

    Aaron Larson

      Hi Folks - I'm at a loss.  I have no idea why the same 2 lines of code have different results from an EPDM API Form example to an add-in hook that I'm trying to write. Here they are:

       

      EdmBomInfo[] derivedBOMs = null;

      aFile.GetDerivedBOMs (out derivedBOMs);

       

      In the API example here these 2 lines work.  This is a add-in forms application that allows a user to select a file and access the BOMs.  When I try to replicate this in another add-in that is looking for a state change hook the 'out' argument gives me the error:

      "Error CS1503 Argument 1: cannot convert from 'out EdmLib.EdmBomInfo[]' to 'out System.Array' "

       

      Why the difference?  How do I get around it?  Other pertinent info... this is in C# and I'm mostly a hack, not a programmer.

       

      *Edit - There seems to be a similar issue here complete with solution... but due to my hackiness I can't relate it to my issue. 

        • Re: EdmBomInfo Quirk
          Simon Turner

          In my experience this is normally due to the version of Interop files that you are using.

          Use the pre-defined EPDM.Interop.epdm.dll from C:\Program Files\SOLIDWORKS PDM

            • Re: EdmBomInfo Quirk
              Aaron Larson

              Thanks for the idea Simon.  When I look at my references, and those of the example (for EPDM 2015 which we are on) I see that it uses this: Interop.EdmLib.  This is different than EPDM.Interop.epdm.dll I believe.  When I try to use the latter instead, I get errors all over to my IEdmAddin5 implementation and usage.

               

               

              Maybe the image helps.  Here also is the complete code (after I've tried your suggestion):

              using System;
              using System.Collections.Generic;
              using System.Text;
              using System.Diagnostics;
              using EPDM.Interop.epdm;
              using System.Runtime.InteropServices;
              
              
              namespace SpecificationTrigger
              {
                  [Guid("5a2b2b2c-afc8-4216-b361-26620e209ad8"), ComVisible(true)]
                  public class SWEPDMAddin : IEdmAddIn5
                  {
                      IEdmFile7 aFile;
                      IEdmBom bom;
                      IEdmBomMgr bomMgr;
                      IEdmBomView bomView;
              
              
                      public void IEdmAddIn5.GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
                      {
                          //Fill in the AddIn's description
                          poInfo.mbsAddInName = "SpecificationTrigger";
                          poInfo.mbsCompany = "Enter Company Name";
                          poInfo.mbsDescription = "Addin";
                          poInfo.mlAddInVersion = 1;
              
              
                          //Minimum Conisio version needed for .Net Add-Ins is 6.4
                          poInfo.mlRequiredVersionMajor = 6;
                          poInfo.mlRequiredVersionMinor = 4;
              
              
                          //poCmdMgr.AddCmd(1, "Test Menu from SpecificationTrigger", (int)EdmMenuFlags.EdmMenu_Nothing, "", "", 0, 0);
              
              
                          //uncomment this line to add all hooks
                          AddAllHooks(poCmdMgr);
                      }
              
              
              
              
                     public void IEdmAddIn5.OnCmd(ref EdmCmd poCmd, ref System.Array ppoData)
                      {
                          Debug.Print("Command Type: " + poCmd.meCmdType.ToString() + "\n  " + System.DateTime.Now.ToString());
              
              
                          IEdmVault5 edmVault = poCmd.mpoVault as IEdmVault5;
                          
              
              
                          try
                          {
                              switch (poCmd.meCmdType)
                              {
                                  case EdmCmdType.EdmCmd_Menu:
                                      //edmVault.MsgBox(0, " SpecificationTrigger", EdmMBoxType.EdmMbt_OKOnly, "SolidWorks EPDM Addin");
                                      break;
                                  case EdmCmdType.EdmCmd_PreState:
                                      for (int i = 0; i < ppoData.Length; i++)
                                      {
                                          EdmCmdData data = (EdmCmdData)ppoData.GetValue(i);
                                          IEdmFile7 aFile = (IEdmFile7)edmVault.GetObject(EdmObjectType.EdmObject_File, data.mlObjectID1);
                                          //Get BOMs and versions for the file
                                          EdmBomInfo[] derivedBOMs;
                                          //aFile.GetDerivedBOMs(out derivedBOMs);
                                          int arrSize = 0;
                                          int k = 0;
                                          int id = 0;                            
                                          //arrSize = derivedBOMs.Length;
                                          //id = derivedBOMs[k].mlBomID;
                                      }
                                          break;
                              }
                          }
                          catch (COMException exp)
                          {
                              string errorName, errorDesc;
                              edmVault.GetErrorString(exp.ErrorCode, out errorName, out errorDesc);
                              edmVault.MsgBox(0, errorDesc, EdmMBoxType.EdmMbt_OKOnly, errorName);
                          }
                      }
              
              
                      void AddAllHooks(IEdmCmdMgr5 poCmdMgr)
                      {           
                          poCmdMgr.AddHook(EdmCmdType.EdmCmd_PreState, null);
                      }
                  }
              
              
              
              
              }
              
                • Re: EdmBomInfo Quirk
                  Simon Turner

                  I thought that might be the case.

                  You referenced the EDMInterface.dll file which auto-created the Interop.EDMLib file. The signatures of the EPDM functions will be slightly different to the ones in the EPDM.Interop.epdm.dll file that SolidWorks have supplied. That is the reason for the errors that you were seeing in your original post.

                  You should really persevere with using EPDM.Interop.epdm.dll and try to correct the new errors. It's not too hard.

                  For example, change this line:

                  public void IEdmAddIn5.OnCmd(ref EdmCmd poCmd, ref System.Array ppoData)

                  to this:

                  public void IEdmAddIn5.OnCmd(ref EdmCmd poCmd, ref EdmCmdData[] ppoData)

                   

                  You can see that rather than passing generic arrays, you are now receiving strongly typed objects.

                    • Re: EdmBomInfo Quirk
                      Aaron Larson

                      YES!  I can see now that the error went away and the GetDerivedBOMs method accepted the argument.  It gave me the following error after the change but adjusting the target framework for the project to framework version 4 allows me to rebuild.

                       

                      Warning The primary reference "EPDM.Interop.epdm" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.

                       

                      Thank you sir for your expert eye!  I now only have to solve the error below and I'll be up and running!  Again, this didn't show up in the API example but am having the error now in my addin.

                       

                      bomMgr = (IEdmBomMgr)vault2.CreateUtility(EdmUtility.EdmUtil_BomMgr);
                      

                       

                       

                      Error CS0656 Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.Convert'