Hello all,
I'm looking to make a macro that creates a symmetric mate using preselected faces/planes. I can't seem to get the mate to add. Does anyone currently have a macro that does this? Here's the applicable code:
'Set marks for symmetric mate
boolstatus = SelMgr.SetSelectedObjectMark(1, 1, swSelectionMarkSet)
boolstatus = SelMgr.SetSelectedObjectMark(2, 1, swSelectionMarkSet)
boolstatus = SelMgr.SetSelectedObjectMark(3, 4, swSelectionMarkSet)
'Mate
Set swMate = activeDoc.AddMate3(swMateSYMMETRIC, swMateAlignCLOSEST, False, 0, 0, 0, 1, 1, 0, 0, 0, False, longstatus)
I always get back an error code of 0, which signifies unknown error. Very helpful... I've gotten parallel and width mates to add, but symmetric is proving difficult.
Thanks in advance for anyone willing to help!
SolidworksApi macros
Just curious, but what exactly would the purpose of this be? If you preselect 3 planes/faces and select "Mate", it should add a symmetric mate by default.
Patrick,
This is part of a larger macro that will mate differently depending on how many faces are selected. 1 face mates parallel to the closest of the 3 main planes, 2 faces mate parallel, 3 mate symmetric, 4 mate width. This would all happen with the push of one hotkey, not depending on any menu interaction. I've gotten 1, 2, and 4 to work, but not 3.
Dale
Long shot but did you ever get this to work?
Yes. But only for a specific set of circumstances. The symmetry plane must be a plane; it cannot be a face. The other 2 can be planes or faces, but not pts or edges or anything like that. Also, the API still uses the last of the 3 selections being the symmetry plane, like Solidworks itself did before 2015, so that's a bit weird nowdays.
I'm looking at the code we're using now, and it's pretty much the exact same thing as I had posted back then, so I'm not sure what my issue was back then.
If you could share your current code that would be great. I have been trying to get it to work for last two days and I'm loosing my hair.
Our current code is really just the same as I had posted before, but I added a check to see if the last selection is a plane.
'Set marks for symmetric mate
boolstatus = SelMgr.SetSelectedObjectMark(1, 1, swSelectionMarkSet)
boolstatus = SelMgr.SetSelectedObjectMark(2, 1, swSelectionMarkSet)
boolstatus = SelMgr.SetSelectedObjectMark(3, 4, swSelectionMarkSet)
'if third selection is a face, no go
If Not SelMgr.GetSelectedObjectType3(3, -1) = swSelDATUMPLANES Then
swApp.SendMsgToUser2 "Symmetry plane must be a plane for macro to work." + Chr(13) + "Exiting Macro.", swMbWarning, swMbOk
Exit Sub
End If
'Mate
Set swMate = activeDoc.AddMate3(swMateSYMMETRIC, swMateAlignCLOSEST, False, 0, 0, 0, 1, 1, 0, 0, 0, False, longstatus)