AnsweredAssumed Answered

Assembly Mating Planes API

Question asked by Sam Pike on May 18, 2018
Latest reply on Jun 3, 2018 by Deepak Gupta

Hello, I am trying to expand on my recent code. I am hoping someone can help me out.

I have 2 assemblies in a document. I am trying to mate one assembly part to another part in the main assembly.

I am trying to write an API to coincident mate the Front Plane (Of the Main Assembly) to another Assembly Part plane Called "Array Vert."(Created in the Part File of the 2nd Assembly File)

Then I will do the same with the Right Plane (Of the Assembly) to the part called "Array Horz".

The part/assy. name always changes but always has these two planes, specially created for this part.

The part/assembly are part of a template, that is why the part name always changes.

I have code working that is similar to this for two parts in an assembly by selecting the part with the specially named planes, and it works just fine. I made some changes to this, but no matter what I do, it will now work.

 

Here is what I have so far. Any help would be appreciated.

 

Dim swApp As SldWorks.SldWorks
Dim swAssy As SldWorks.AssemblyDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComp As SldWorks.Component2
Dim boolstatus As Boolean
Dim swMate As Mate2
Dim longstatus As Long
Dim Part As Object

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swSelMgr = Part.SelectionManager
Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, 0)

boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Trial Vert@" + swComp.Name2 + "@" + Part.GetTitle, "PLANE", 0, 0, 0, True, 0, Nothing, 0)

' Mate
Set swMate = Part.AddMate5(0, 0, False, 0.470811238093686, 0.0254, 0.0254, 0.0254, 0.0254, 0, 0.5235987755983, 0.5235987755983, False, False, 0, longstatus)
Part.ClearSelection2 True
Part.EditRebuild3

boolstatus = Part.Extension.SelectByID2("Right Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Trial Horz@" + swComp.Name2 + "@" + Part.GetTitle, "PLANE", 0, 0, 0, True, 0, Nothing, 0)

' Mate
Set swMate = Part.AddMate5(0, 0, False, 0.470811238093686, 0.0254, 0.0254, 0.0254, 0.0254, 0, 0.5235987755983, 0.5235987755983, False, False, 0, longstatus)
Part.ClearSelection2 True
Part.EditRebuild3

boolstatus = Part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Trial Down@" + swComp.Name2 + "@" + Part.GetTitle, "PLANE", 0, 0, 0, True, 0, Nothing, 0)

' Mate
Set swMate = Part.AddMate5(0, 1, False, 0.470811238093686, 0.0254, 0.0254, 0.0254, 0.0254, 0, 0.5235987755983, 0.5235987755983, False, False, 0, longstatus)
Part.ClearSelection2 True
Part.EditRebuild3

End Sub

Outcomes