Solved using UCS
Public Sub Main()
Dim partDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = partDoc.ComponentDefinition
Dim transBRep As TransientBRep = ThisApplication.TransientBRep
Dim transGeom As TransientGeometry = ThisApplication.TransientGeometry
Dim Selectededge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select an edge.")
Dim faces As Faces = Selectededge.Faces
Dim baseface As Face = Nothing
For i = 1 To faces.Count
If baseface Is Nothing Then
baseface = Faces(i)
ElseIf Faces(i).Evaluator.Area > baseface.Evaluator.Area Then
baseface = Faces(i)
End If
Next
Dim egdeLength As Double = Selectededge.StartVertex.Point.DistanceTo(Selectededge.StopVertex.Point)
Dim line As LineSegment = Selectededge.Geometry
Dim startPoint = line.StartPoint
Dim boxMinPoint As Point = transGeom.CreatePoint(0, 0, 0)
Dim boxMaxPoint As Point = transGeom.CreatePoint(egdeLength, 10, 0.3)
Dim box As Box = transGeom.CreateBox()
box.Extend(boxMinPoint)
box.Extend(boxMaxPoint)
Dim boxXpoint As Point = transGeom.CreatePoint(0, 0, egdeLength)
Dim boxYpoint As Point = transGeom.CreatePoint(0, 10, 0)
Dim oBody As SurfaceBody = transBRep.CreateSolidBlock(box)
Dim edgeStartWP As Inventor.WorkPoint = partDoc.ComponentDefinition.WorkPoints.AddByPoint(Selectededge.StartVertex)
Dim edgeXWP As Inventor.WorkPoint = partDoc.ComponentDefinition.WorkPoints.AddByPoint(Selectededge.StopVertex)
Dim edgeYWP As Inventor.WorkPoint
For Each oEdge As Inventor.Edge In Selectededge.StartVertex.Edges
If Not oEdge Is Selectededge Then
If Not Math.Round(oEdge.StartVertex.Point.DistanceTo(oEdge.StopVertex.Point), 2) = 0.3 Then
If Math.Round(oEdge.StartVertex.Point.DistanceTo(Selectededge.StartVertex.Point), 2) > 0 Then
edgeYWP = partDoc.ComponentDefinition.WorkPoints.AddByPoint(oEdge.StartVertex)
Else
edgeYWP = partDoc.ComponentDefinition.WorkPoints.AddByPoint(oEdge.StopVertex)
End If
End If
End If
Next
Dim oUCSDef As UserCoordinateSystemDefinition = oCompDef.UserCoordinateSystems.CreateDefinition
oUCSDef.SetByThreePoints(edgeStartWP, edgeXWP, edgeYWP)
Dim oEdgeUCS As UserCoordinateSystem = oCompDef.UserCoordinateSystems.Add(oUCSDef)
Dim Edgematrix As Matrix = oEdgeUCS.Transformation
transBRep.Transform(oBody, Edgematrix)
Dim vector = line.Direction.AsVector()
Edgematrix.SetToRotation(180 * Math.PI / 180, vector, Selectededge.StartVertex.Point)
transBRep.Transform(oBody, Edgematrix)
partDoc.ComponentDefinition.SetEndOfPartToTopOrBottom(True)
Dim oBaseFeature As NonParametricBaseFeature = oCompDef.Features.NonParametricBaseFeatures.Add(oBody)
partDoc.ComponentDefinition.SetEndOfPartToTopOrBottom(False)
End Sub