5 Replies Latest reply on Dec 16, 2017 6:21 AM by Rachid Mhamdi

    API to Compare not same Components

    Joe Pickens

      I am looking for a way to compare components for similarities. I was attempting to use the Compare Documents feature but that only works if the parts have origins located in the same respective place which in not the case for me is there any way for me to compare two similar part documents and assess them for commonalities. and im looking for API to do this cause i'm going through a massive amount of parts.

        • Re: API to Compare not same Components
          Artem Taturevych

          I would suggest the following scenario (sequence of checks) to validate the component is the same geometry)

          • Compare by path/configuration
            • True - components are equal
            • False
              • Compare by surface/volume
                • False - Components are different
                • True
                  • Compare the coincidence transformation of bodies in components via Body2::GetCoincidenceTransform2.
                    • Null - components are different
                    • Not null - components are equal. The only problem that symmetric components will be considered as an equal. If this is not acceptable for you. You need to verify the boolean difference between original body and transformed body of different component. If difference is null - components are difference, if not null - components are equal.

           

          So this is not very trivial task if you want to group the components by geometry rather than files, but I was able to implement the above scenario in the application I have developed with an acceptable performance for grouping thousands of components.

          • Re: API to Compare not same Components
            Roland Schwarz

            Count surfaces, edges, and vertices. It's called topology.

            • Re: API to Compare not same Components
              Joe Pickens

              I have been playing with some code and i think this is what i want to do to start but in trying to figure out how to get the face count

               

              Option Explicit

               

              Dim swApp As SldWorks.SldWorks

              Dim Model As SldWorks.ModelDoc2

              Dim ModelView As SldWorks.ModelView

              Dim FrameState As Variant

               

              Dim longstatus As Long

              Dim varEntCount As Variant

              Dim swUtil As gtcocswUtilities

              Dim swUtilPsl As gtcocswPowerSelect

               

              Sub main()

               

              Set swApp = Application.SldWorks

              Set Model = swApp.ActiveDoc

              'Set ModelView = Model.ActiveView

              'ModelView.FrameState = swWindowState_e.swWindowMaximized

               

              'Set Utilities Add In

              Set swUtil = swApp.GetAddInObject("Utilities.UtilitiesApp")

               

              'Get the powerSelect object

              Set swUtilPsl = swUtil.PowerSelect

              longstatus = swUtilPsl.Init()

               

              'Select only faces

              longstatus = swUtilPsl.SetSelectEntitiesTypes(gtPslSelectionType_Face)

               

              'Select all Features

              longstatus = swUtilPsl.SetFeatureTypeFilter(gtPslFeat_All)

               

              'Run the selection and get the number of edges, loops, faces, and features selected

               

              varEntCount = swUtilPsl.RunPowerSelect(gtResultShowUI, longstatus)

               

              'Select the results

              longstatus = swUtilPsl.SelectResults()

               

              longstatus = swUtilPsl.Close()

               

              End Sub

                • Re: API to Compare not same Components
                  Rachid Mhamdi

                  get the face count

                   

                  Dim swApp As Object

                  Sub main()

                  Dim k As Integer

                  Dim face As Object

                  Dim ii As Long

                  Dim m As Integer

                  Dim i As Long

                  Dim nom_face As String

                  Dim Bodies                      As Variant

                  Dim SwSurface As SldWorks.Surface

                  Dim bRet                    As Boolean

                  Dim swSelMgr                As SldWorks.SelectionMgr

                  Dim swSelData               As SldWorks.SelectData

                  Dim swModel                     As SldWorks.ModelDoc2

                  Dim swPart

                  Set swApp = CreateObject("SldWorks.Application")

                  Set swModel = swApp.ActiveDoc

                  Set swPart = swModel

                  'Set swAsModel = swModel

                  Set swSelMgr = swModel.SelectionManager

                  Set swSelData = swSelMgr.CreateSelectData

                          swModel.ClearSelection2 True

                      Bodies = swPart.GetBodies(swSolidBody)

                  For k = 0 To UBound(Bodies)

                          Set Body = Bodies(k)

                          Set face = Body.GetFirstFace

                         ' Traverse thru all body faces

                          Do While Not face Is Nothing

                                 nFa = nFa + 1

                               Set face = face.GetNextFace

                          Loop

                             Next k

                  Set swApp = Application.SldWorks

                  End Sub