9 Replies Latest reply on Jan 28, 2016 8:29 PM by Meredith McKay

    SLDPRT duplicates

    Meredith McKay

      Hey I am trying to do a directory search using c# for soildwork parts that are duplicates or are the same part but with custom properties. I already compared parts of the same size with each other but that is not very accurate. Is there anyway for me to access solidworks hash data or part dimensions or unique part numbers that solidworks assigns to a created part. I am fairly new to solidworks and i have been told of the compare part option in solidoworks but i want to compare all parts with one another and find the duplicates. Please help.

        • Re: SLDPRT duplicates
          Artem Taturevych

          If you want to find exact duplicates (like copy paste file to different directory or/and rename than you can use the MD5 checksum (How to Calculate MD5 Checksum for a File)

           

          But if you want to find similar parts by geometry you have to compare each one either by display data or by parasolid geometry - this is going to be very performance intensive process.

           

          SolidWorks doesn't provide a file id to the users. I believe what they are using is the file creation time stamp.

           

          Thanks,

          Artem

          • Re: SLDPRT duplicates
            Meredith McKay

            foreach (string path in filepaths)

                            {

                                SldWorks.SldWorks swApp = new SldWorks.SldWorks();

                                //Makes the object visible

                                swApp.Visible = false;

                                ModelDoc2 swDoc = null;

                                PartDoc swPart = null;

                                DrawingDoc swDrawing = null;

                                AssemblyDoc swAssembly = null;

                                bool boolstatus = false;

                                int longstatus = 0;

                                int longwarnings = 0;

             

             

                                swDoc = ((ModelDoc2)(swApp.OpenDoc6(path, 1, 0, "", ref longstatus, ref longwarnings)));

                                swApp.ActivateDoc2("89920104", false, ref longstatus);

                                swDoc = ((ModelDoc2)(swApp.ActiveDoc));

                                swDoc = ((ModelDoc2)(swApp.ActiveDoc));

                                ModelView myModelView = null;

                              

                                    myModelView = ((ModelView)(swDoc.ActiveView));

                                    myModelView.FrameLeft = 0;

                                    myModelView.FrameTop = 21;

                                    myModelView = ((ModelView)(swDoc.ActiveView));

                                    myModelView.FrameState = ((int)(swWindowState_e.swWindowMaximized));

                                    //swDoc.FileSummaryInfo();

             

             

                                    var creationDate = swDoc.SummaryInfo((int)(swSummInfoField_e.swSumInfoCreateDate));

                                dates.Add(creationDate);

                                    closeSW();

                            }

             

            So i wrote this code in c# with the help of a macro and it purpse is to get filepaths from the list and then open a solidworks instance and get creation date and then add it to a list. Which i want to use to find duplicate files. But i dont get creation dates for any of the parts. Please Help.

            • Re: SLDPRT duplicates
              Matthew Cempa

              You can do some comparison using geometric properties like volume, surface area, center of mass and  moment of inertia to determine if the parts are the same.  Based on this you could flag the parts for a closer personal look.  Or... you could try to do a Boolean subtract by bringing both parts into one.  If you get no resulting bodies left over using both combinations they are the same.    Not quite sure how I'd approach that but I'm sure it could be done.