Hi, sorry for the late response, it was more complicated than I first thought.
De addworkplanes object is very limited in an assembly.
But you can try this.
Sub main
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition = asmDoc.ComponentDefinition
Dim oWorkPointList As New List(Of WorkPoint)
'-------------------------------------------------------------------------------------------------------
Dim oWorkplane As Boolean = false
Dim oWorkpoint1 As WorkPoint = Create3Points(oCompDef, "WP_1", -2.5, -1, 1)
oWorkPointList.Add(oWorkpoint1)
Dim oWorkpoint2 As WorkPoint = Create3Points(oCompDef, "WP_2", 2.5, -1, 1)
oWorkPointList.Add(oWorkpoint2)
Dim oWorkpoint3 As WorkPoint = Create3Points(oCompDef, "WP_3", 2.5, 1, 2)
oWorkPointList.Add(oWorkpoint3)
Dim oWorkpoint4 As WorkPoint = Create3Points(oCompDef, "WP_4", -2.5, -1, 3)
oWorkPointList.Add(oWorkpoint4)
Dim oWorkpoint5 As WorkPoint = Create3Points(oCompDef, "WP_5", 2.5, -1, 3)
oWorkPointList.Add(oWorkpoint5)
Dim oWorkpoint6 As WorkPoint = Create3Points(oCompDef, "WP_6", 2.5, 1, 4)
oWorkPointList.Add(oWorkpoint6)
'------------------------------------------------------------------------------------------------------
While oWorkPointList.Count > 2
If oWorkplane = True Then
Dim x1 As Double = oWorkPointList.Item(0).Point.X
Dim y1 As Double = oWorkPointList.Item(0).Point.Y
Dim z1 As Double = oWorkPointList.Item(0).Point.Z
Dim x2 As Double = oWorkPointList.Item(1).Point.X
Dim y2 As Double = oWorkPointList.Item(1).Point.Y
Dim z2 As Double = oWorkPointList.Item(1).Point.Z
Dim x3 As Double = oWorkPointList.Item(2).Point.X
Dim y3 As Double = oWorkPointList.Item(2).Point.Y
Dim z3 As Double = oWorkPointList.Item(2).Point.Z
CreateWorkplane(oCompDef, x1, x2, x3, y1, y2, y3, z1, z2, z3)
End If
oWorkPointList.RemoveAt(0)
oWorkPointList.RemoveAt(1)
oWorkPointList.RemoveAt(0)
End While
End Sub
Private Function Create3Points(ByVal oCompdef As ComponentDefinition, ByVal name As String, x As Double, y As Double, z As Double) As WorkPoint
Dim result As WorkPoint = Nothing
Dim oWorkpoint As WorkPoint = Nothing
Try
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
' Create 3 workpoints to define the origin, x-direction and y-direction points
oWorkpoint = oCompdef.WorkPoints.AddFixed(oTG.CreatePoint(x, y, z))
oWorkpoint.Name = name
result = oWorkpoint
Catch ex As Exception
End Try
Return result
End Function
Private Sub CreateWorkplane(oCompDef As AssemblyComponentDefinition, x1 As Double, x2 As Double, x3 As Double, y1 As Double, y2 As Double, y3 As Double, z1 As Double, z2 As Double, z3 As Double)
Try
Dim omidpoint As Point = ThisApplication.TransientGeometry.CreatePoint(x1, y1, z1)
Dim oUnitVec1 As UnitVector = CreateUnitVector(x1, x2, y1, y2, z1, z2)
Dim oUnitVec2 As UnitVector = CreateUnitVector(x1, x3, y1, y3, z1, z3)
Dim oWorkplane As WorkPlane = oCompDef.WorkPlanes.AddFixed(omidpoint, oUnitVec1, oUnitVec2)
oWorkplane.AutoResize = True
Catch ex As Exception
End Try
End Sub
Private Function CreateUnitVector(workpoint1x As Double, workpoint2x As Double, workpoint1y As Double, workpoint2y As Double, workpoint1z As Double, workpoint2z As Double) As UnitVector
Dim result As UnitVector = Nothing
Dim oUnitVector As UnitVector = Nothing
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Try
oUnitVector = oTG.CreateUnitVector(workpoint1x - workpoint2x, workpoint1y - workpoint2y, workpoint1z - workpoint2z)
result = oUnitVector
Catch ex As Exception
End Try
Return result
End Function