Solidworks macro - mating planes

I have no knowledge on how to create macros in Solidworks.

I have used the Macro recorder and came up with a macro which is nearly what I want. I would like to be in any assembly, select 2 parts, assemblies or a part and an assembly and have it mate the Top plane of one to the top plane of another, Front plane of other to Front plane etc.

Is there a better way to do this??

This is what I have so far - it will not work if the parts/assemblies are different names:

Dim swApp As Object Dim Part As Object Dim SelMgr As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim Feature As Object Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc Set SelMgr = Part.SelectionManager boolstatus = Part.Extension.SelectByID2("Front@Dual Base Plate Assy-1@QX10 Dual Base Assy", "PLANE", 0, 0, 0, False, 0, Nothing, 0) boolstatus = Part.Extension.SelectByID2("Front", "PLANE", 0, 0, 0, True, 0, Nothing, 0) Set Feature = Part.AddMate2(0, -1, False, 0, 0, 0, 1, 1,

1.570796326795, 0.5235987755983, 0.5235987755983, longstatus) Part.ClearSelection2 True boolstatus = Part.Extension.SelectByID2("Top", "PLANE", 0, 0, 0, True, 1, Nothing, 0) boolstatus = Part.Extension.SelectByID2("Top@Dual Base Plate Assy-1@QX10 Dual Base Assy", "PLANE", 0, 0, 0, True, 1, Nothing, 0) Set Feature = Part.AddMate2(0, -1, False, 0.0107, 0, 0, 1, 1, 0, 0.5235987755983, 0.5235987755983, longstatus) Part.ClearSelection2 True boolstatus = Part.Extension.SelectByID2("Right@Dual Base Plate Assy-1@QX10 Dual Base Assy", "PLANE", 0, 0, 0, True, 1, Nothing, 0) boolstatus = Part.Extension.SelectByID2("Right", "PLANE", 0, 0, 0, True, 1, Nothing, 0) Set Feature = Part.AddMate2(0, -1, False, 0, 0, 0, 1, 1, 1.570796326795, 0.5235987755983, 0.5235987755983, longstatus) Part.ClearSelection2 True End Sub

Any help appreciated. Chris

Reply to
yochris77
Loading thread data ...

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.