It's looks like first three values of IMateEntity2.EntityParams doesn't keep information about point which was selected for mate creation. How can I get access for this information?
Here's a couple of things you could try:
- Verify that you actually select the "MateGroup" feature from the while loop. I imagine it would throw an error on the next line if it didn't, but it doesn't hurt to check
- In your SelectByID2, try replacing your "mark" parameter of 1 with "i" or "i+1". Honestly not sure how this parameter is used, but it may need to be a unique value for each selected item?
- In your SelectByID2, extend your "name" parameter by adding something like "@Assem1" or whatever suits your particular assembly. You could also probably make this dynamic if you want by pulling the name from your existing variables. The reason I am thinking this might be the culprit is the "EntityParams" method returns an X, Y, Z that are in the assembly space.
Thank you for your answer. I think that my problem related not with "name" parameter but with EntityParams. First three values are coordinates of "mate entity" not of point which was selected. I'm interesting how I can get this original point to select the same part of body which was selected in that mate. I afraid that SolidWorks doesn't keep this information.
Please look at the picture.
Basically, you should almost never use SelectByID.
It sounds to me like your final goal is to select the entities used for the mate.
Please study the code below. Sorry, it's VBA rather than C.
Preconditions: User has selected a mate
Postconditions: The mate is un-selected and the entities used for the mate are selected.
Dim swApp As SldWorks.SldWorks Dim tmpFeat As SldWorks.Feature Dim swSelMgr As SldWorks.SelectionMgr Dim tmpMent As SldWorks.MateEntity2 Dim i As Long Sub main() Set swApp = Application.SldWorks Set swSelMgr = swApp.ActiveDoc.SelectionManager Set tmpFeat = swSelMgr.GetSelectedObject6(1, -1) Set swMate = tmpFeat.GetSpecificFeature2 Set tmpFeat = Nothing swApp.ActiveDoc.ClearSelection2 True For i = 0 To swMate.GetMateEntityCount - 1 Set tmpMent = swMate.MateEntity(i) tmpMent.Reference.Select2 True, 1 Next i End Sub
Thank you. Your code works fine. But I need to select the same entity on another document and this component may has another name. But I know that geometry location on that document will be the same as in the original document with mates. So if I get this point I will be able to select the same entity on other document.
So, just to make sure I understand, you are saying that:
Comp1.sldprt and Comp2.sldprt are in an assembly. There is a mate between faces of these components.
Comp3.sldprt is a different file, but is "similar" geometry to Comp2.sldprt. You want to select a face on Comp3 that is similar to a face on Comp2.
Is this correct?
This is certainly tricky. As you have found, SolidWorks doesn't remember the point selected when mates are created.
It sounds like you are always looking for a face? One approach that may work to find some point close to the center of the face:
1. Get the face
2. Get the bounding box for the face.
3. Get the midpoint of the bounding box
3. Use GetClosestPointOn with the midpoint coordinates to get a point that is actually on the face.