AddMate3 depends on selection method?

Hi,

I'm working on a macro that will attach the mates referred to bytwo MateReferences.

I've found that once I have the two Entity objects to matetogether, let's call them swEntity1 and swEntity2, I can selectthem with swModel.Extension.SelectByID2 and create the mate usingswAssy.AddMate3. I can also select the first entity withswEntity1.Select4 (using an appropriate SelectData object thatspecifies Mark=1), and second with SelectByID2, and it works.

What doesn't work is selecting both entities using Select4.In this case, AddMate3 reports success and I get a non-nullMate2 object, but no mate is shown in the SolidWorks interface(nothing in the feature tree, component can still be manuallymoved).

I'd really rather not have to use SelectByID2 in this case, sinceit requires me to build a long selection string with information Idon't necessarily have available. Any hints as to why selectingusing Select4 on the Entity objects that I already have isn'tworking?

To summarize, this works:

swModel.ClearSelection2 (True)
Dim selectResult As Boolean

' Select the first Entity
Dim selectData As SldWorks.selectData
Set selectData = swModel.SelectionManager.CreateSelectData
selectData.Mark = 1
selectResult = swEntity1.Select4(False, selectData):Debug.Assert(selectResult)

' Select the second Entity, using SelectByID2
Dim swFeat2 As SldWorks.Feature
Set swFeat2 = swEntity2
selectResult = swModel.Extension.SelectByID2(swFeat2.Name &"@Test component 2" & "@Sample assy for MR macro", "PLANE", 0#,0#, 0#, True, 1, Nothing, swSelectOptionDefault): Debug.Assert(selectResult)

' Create the mate
Dim firstMate As SldWorks.Mate2
Dim errorStatus As Long
Set firstMate = swAssy.AddMate3(swMateCOINCIDENT, swAlignNONE,False, 0, 0, 0, 0, 0, 0, 0, 0, False, errorStatus)

... and this doesn't work:

swModel.ClearSelection2 (True)
Dim selectResult As Boolean

' Select the first Entity
Dim selectData As SldWorks.selectData
Set selectData = swModel.SelectionManager.CreateSelectData
selectData.Mark = 1
selectResult = swEntity1.Select4(False, selectData):Debug.Assert(selectResult)

' Select the second Entity, using Select4
selectResult = swEntity2.Select4(True, selectData):Debug.Assert(selectResult)

' Create the mate
Dim firstMate As SldWorks.Mate2
Dim errorStatus As Long
Set firstMate = swAssy.AddMate3(swMateCOINCIDENT, swAlignNONE,False, 0, 0, 0, 0, 0, 0, 0, 0, False, errorStatus)

BTW I am aware that the API docs specifically mention doing theselection with SelectById2. But then why does my first method work?

Thanks

- rdo
SolidworksApi macros