Here's an executable of the issue you can copy and paste to run...
Sub Main
Dim oDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oWorkPlane As WorkPlane
Dim oSketch As PlanarSketch
Dim oLine(3) As SketchLine
'for sample
Dim FlatAngle As Double = 30
Dim Dia As Double = 30
Dim Value As Double
Dim IsSlipJoint As Boolean = False
Dim MatThick As Double = 0.25
'close any active sketches
If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
oSketch = ThisApplication.ActiveEditObject
oSketch.ExitEdit
End If
'remove any previously created stuff
While oCompDef.Features.Count > 0
oCompDef.Features.Item(oCompDef.Features.Count).Delete
End While
While oCompDef.Sketches.Count > 0
oCompDef.Sketches.Item(oCompDef.Sketches.Count).Delete
End While
'make new stuff
oWorkPlane = oCompDef.WorkPlanes.Item("XZ Plane")
oSketch = oCompDef.Sketches.Add(oWorkPlane)
oSketch.Name = "Sealer sketch"
oGC = oSketch.GeometricConstraints
oDC = oSketch.DimensionConstraints
Value = (Dia / 2 * 2.54) * Tan(FlatAngle / 2 * PI / 180)
oLine(1) = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(-Value, -(Dia / 2 * 2.54)), oTG.CreatePoint2d(0, 0))
oLine(2) = oSketch.SketchLines.AddByTwoPoints(oLine(1).EndSketchPoint, oTG.CreatePoint2d(Value, -(Dia / 2 * 2.54)))
oGC.AddGround(oLine(1).EndSketchPoint)
oGC.AddHorizontalAlign(oLine(1).StartSketchPoint, oLine(2).EndSketchPoint)
If IsSlipJoint Then 'slipjoint = polygon shape
oLine(3) = oSketch.SketchLines.AddByTwoPoints(oLine(2).EndSketchPoint, oLine(1).StartSketchPoint)
oSKP = oSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 0), False)
oGC.AddMidpoint(oSKP, oLine(3))
oGC.AddVerticalAlign(oSKP, oLine(1).EndSketchPoint)
oTmp = oDC.AddTwoLineAngle(oLine(1), oLine(2), oTG.CreatePoint2d(0, oLine(1).Geometry.MidPoint.Y), False)
oTmp.Parameter.Expression = CStr(FlatAngle) & " deg"
oTmp = oDC.AddOffset(oLine(3), oLine(1).EndSketchPoint, oTG.CreatePoint2d(0, oLine(1).Geometry.MidPoint.Y), False, False)
oTmp.Parameter.Expression = CStr(Dia / 2) & " in"
Else
oArc = oSketch.SketchArcs.AddByCenterStartEndPoint(oLine(1).EndSketchPoint, oLine(2).EndSketchPoint, oLine(1).StartSketchPoint, False)
'This line fails
oGC.AddCoincident(oLine(1).EndSketchPoint, oArc.CenterSketchPoint)
'These REM'd lines don't fail
' oSKP1 = oLine(1).EndSketchPoint
' oSKP2 = oArc.CenterSketchPoint
' oGC.AddCoincident(oSKP1, oSKP2)
oTmp = oDC.AddTwoLineAngle(oLine(1), oLine(2), oTG.CreatePoint2d(0, oLine(1).Geometry.MidPoint.Y), False)
oTmp.Parameter.Expression = CStr(FlatAngle) & " deg"
oTmp = oDC.AddRadius(oArc, oTG.CreatePoint2d(0, -Dia / 4 * 2.54), False)
oTmp.Parameter.Expression = CStr(Dia / 2) & " in"
End If
oProfile = oSketch.Profiles.AddForSolid
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kNewBodyOperation)
oExtrudeDef.SetDistanceExtent(MatThick * 2.54, kNegativeExtentDirection)
oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
oExtrude.Name = "Sealer Plate slice"
End Sub
Autodesk Inventor Certified Professional