ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
DNDale Northern20/09/2010

I am trying to create a mate in SolidWorks 2010 from a VB.Net application. My intention is to have this process run unattended, so pre-selection of faces is not an option.  For testing purposes I have two simple parts, both rectangular and about an inch thick and both with a single hole.  The code creates a new blank assembly, and then inserts these parts into the assembly.  I am selecting each of the cut-extrude holes with the following code:

boolstatus = Modeldoc.Extension.SelectByID2("Cut-Extrude1@TestPlate-1@API_Test3", "BODYFEATURE", 0, 0, 0, True, 0, Nothing, 0)

boolstatus = Modeldoc.Extension.SelectByID2("Cut-Extrude1@TestBar-1@API_Test3", "BODYFEATURE", 0, 0, 0, True, 0, Nothing, 0)

At this point, the only available mate is 'Lock' .  And I've confirmed that my code can indeed create the mate with the following code:

matefeature = assembly.AddMate3(swMateType_e.swMateLOCK, swMateAlign_e.swMateAlignALIGNED, False, 0, 0, 0, 0, 0, 0, 0, 0, False, matestatus)

If I use the same code with swMateCONCENTRIC, the mate fails.  Looking at a recorded macro from the assembly, creating a concentric mate needs faces and not bodies.  So my problem is, how do I select a face from a given body?  The SolidWorks example located here:

http://help.solidworks.com/2010/English/api/sldworksapi/get_component_face_by_name_example_vb.htm

uses a line 'Face.Select (0)' which is not a valid member of either Face or Face2.  I turned off Option Strict, and was able to use Face.Select but I'm not sure if it worked.

If I record a macro to create the mate in my assembly, the macro uses SelectByID2 with no entity name and just the X, Y, Z coordinates.  This is useless to me, as I'd like to dynamically select faces from different SolidWorks parts based on feature name.

Has anyone had success in creating a mate reference from scratch?  Do I need to select the faces to create the mate?  Can I select the faces from a solid body?

Thanks!