AnsweredAssumed Answered

How to get mate name for select/delete

Question asked by Drew Miller on Dec 30, 2014
Latest reply on Dec 30, 2014 by Drew Miller

Using 2014 and VBA with an open assembly. 

 

I am looking through mates and finding mates that are of inplace type and have a certain matecomponentname.

Once the correct conditions are met then I would like to be able to select and delete the mate.  If I know the name of the mate then

it can be selected using selectbyid2.  Problem is I can't seem to get to the mate's name (for example "InPlace1").. there must be an easier way to get the right mate and delete it?

 

        Components = swAssy.GetComponents(False)

 

 

        For Each SingleComponent In Components

            Set thisComponent = SingleComponent

            Debug.Print "Name of component: " & thisComponent.Name2

            Mates = thisComponent.GetMates()

            If (Not IsEmpty(Mates)) Then

                For Each SingleMate In Mates

                    If TypeOf SingleMate Is SldWorks.Mate2 Then

                        Set swMate = SingleMate

                        typeOfMate = swMate.Type

                        Select Case typeOfMate

                            Case 0

                                Debug.Print "  Mate type: Coincident"

                            Case 1

                                Debug.Print "  Mate type: Concentric"

                            Case 2

                                Debug.Print "  Mate type: Perpendicular"

                            Case 3

                                Debug.Print "  Mate type: Parallel"

                            Case 4

                                Debug.Print "  Mate type: Tangent"

                            Case 5

                                Debug.Print "  Mate type: Distance"

                            Case 6

                                Debug.Print "  Mate type: Angle"

                            Case 7

                                Debug.Print "  Mate type: Unknown"

                            Case 8

                                Debug.Print "  Mate type: Symmetric"

                            Case 9

                                Debug.Print "  Mate type: CAM follower"

                            Case 10

                                Debug.Print "  Mate type: Gear"

                            Case 11

                                Debug.Print "  Mate type: Width"

                            Case 12

                                Debug.Print "  Mate type: Lock to sketch"

                            Case 13

                                Debug.Print "  Mate type: Rack pinion"

                            Case 14

                                Debug.Print "  Mate type: Max mates"

                            Case 15

                                Debug.Print "  Mate type: Path"

                            Case 16

                                Debug.Print "  Mate type: Lock"

                            Case 17

                                Debug.Print "  Mate type: Screw"

                            Case 18

                                Debug.Print "  Mate type: Linear coupler"

                            Case 19

                                Debug.Print "  Mate type: Universal joint"

                            Case 20

                                Debug.Print "  Mate type: Coordinate"

                            Case 21

                                Debug.Print "  Mate type: Slot"

                            Case 22

                                Debug.Print "  Mate type: Hinge"

                            ' Add new mate types introduced after SolidWorks 2010 FCS here

                        End Select

                    End If

                    If TypeOf SingleMate Is SldWorks.MateInPlace Then

                        Set swMateInPlace = SingleMate

   

                        numMateEntities = swMateInPlace.GetMateEntityCount

                        For i = 0 To numMateEntities - 1

                            Debug.Print "  Mate component name: " & swMateInPlace.MateComponentName(i)

                            Debug.Print "    Type of mate inplace: " & swMateInPlace.MateEntityType(i)

                        Next i

                        Debug.Print ""

                        'get mate name somehow

                        boolstatus = swModel.extension.SelectByID2(matename, "MATE", 0, 0, 0, False, 0, Nothing, 0)

                        swModel.EditDelete

                    End If

                Next

            End If

            Debug.Print ""

        Next

Outcomes