3 Replies Latest reply on Nov 6, 2015 3:25 PM by Jim Sculley

    IEdmFile7::NeedsRegeneration is Broken

    Jim Sculley

      I have a set of files I use for EPDM API testing.  The file structure looks like this:

       

      ABC.SLDASM (with drawing ABC.SLDDRW)

          +--A.SLDPRT (with drawing A.SLDDRW)

          |

          +--B.SLDPRT

          |

          +--C.SLDASM (with drawing C.SLDDRW)

              +--D.SLDPRT (with drawing D.SLDDRW)

              |

              +--E.SLDPRT

       

      I wrote a simple test add-in that adds a right click menu option to check the regeneration status for one or more files.  The relevant code looks like this:

       

      private void checkRegenStatus(EdmCmd poCmd, EdmCmdData[] cmdData) 
      {      foreach (EdmCmdData d in cmdData)      {         int fileID = d.mlObjectID1;          int folderID = d.mlObjectID3;          IEdmFile11 nextFile = (IEdmFile11)vault.GetObject(EdmObjectType.EdmObject_File, fileID);          IEdmFolder9 folder = (IEdmFolder9)vault.GetObject(EdmObjectType.EdmObject_Folder, folderID);          if (nextFile.NeedsRegeneration(0, folder.LocalPath));          {              MessageBox.Show("File " + nextFile.Name + "needs regeneration.");          }            if (nextFile.NeedsRegeneration(0, folderID))          {              MessageBox.Show("File " + nextFile.Name + " needs regeneration.");         }      }  } 
      

       

       

      When I select all of my test files and run the add-in, no message boxes are displayed, which is correct since all files are up to date.

       

      Next I open one of my test part files (say E.SLDPRT), make a change, save it and check it in.  If I now try to check out C.sldasm (or its parent ABC.SLDASM) the checkout dialog displays a warning that C.SLDASM is not rebuilt.

       

      However, when I select all of my test files and run the add-in, no message boxes are displayed, which is incorrect since C.SLDASM require regeneration.

       

      I have run this test on all the files in my test vault (85 files) and the only files that cause NeedsRegeneration to return a value of true are files that have not been saved in the current version of SolidWorks.  These are also the only files that cause the rebuild warning to appear in the EPDM preview window.

       

      I've tested with both SW/EPDM 2015 SP2.1 and SW/EPDM 2016 SP0 and the results are the same.

       

      Is anyone using IEdmFile7::NeedsRegeneration successfully? For me it appears to be horribly broken.

       

      Jim S.

        • Re: IEdmFile7::NeedsRegeneration is Broken
          Lee CS Young

          It's broken. I tested here and I am getting inconsistent results between versions of the same file.

          • Re: IEdmFile7::NeedsRegeneration is Broken
            Artem Taturevych

            Hi Jim,

             

            Yes, this seems to be broken. I was struggling with this function some time ago. But @Daniel Seaman from SW API Support suggested a good workaround to identify regeneration status based on the fact that the version of the reference doesn't match the version of the file.

             

            I have written the following extension method. Seems to be working OK for me:

             

            public static class EpdmExtension

                {

                    public static bool IsOutDated(this IEdmFile5 file, int version, int folderId)

                    {

                        if ((file as IEdmFile7).NeedsRegeneration(version, folderId))

                        {

                            return true;

                        }

             

                        IEdmReference5 reference = file.GetReferenceTree(folderId, version);

             

                        return TraverseReference(reference);

                    }

             

                    private static bool TraverseReference(IEdmReference5 reference)

                    {

                        string prjName = "";

                        IEdmPos5 pos = reference.GetFirstChildPosition(ref prjName, true, false, 0);

                        while (!pos.IsNull)

                        {

                            IEdmReference5 child = reference.GetNextChild(pos);

                            if (TraverseReference(child))

                            {

                                return true;

                            }

             

                            IEdmFile5 refFile = child.File;

                            int versionRef = child.VersionRef;

                            int curVer = refFile.CurrentVersion;

             

             

                            if (curVer != versionRef)

                            {

                                return true;

                            }

                        }

             

                        return false;

                    }

                }

             

            Usage:

             

            bool needsRegen = nextFile.IsOutDated(0, folder.Id);

             

            Hope this helps.

             

            Thanks,

            Artem