Now I have a case where interactively SWEEP works, but fails in API.
Dim oSweepOne As SweepFeature = Nothing
Dim oProfileOne As Profile
oProfileOne = newProfileSketch.Profiles.AddForSurface(newProfileSketch.SketchLines.Item(1))
oSweepOne = oCompDef.Features.SweepFeatures.AddUsingPath(oProfileOne, newPath, PartFeatureOperationEnum.kSurfaceOperation, SweepProfileOrientationEnum.kNormalToPath)
How do I get more information about the error? Just exception is of no use, actually.

Part attached.
Sketch9 is midcurve sketch which is the profile.
Sketch10 is the path
And the code above fails, whereas works fine intereactively.
Another question: sometimes path and profile do not intersect. How to check if they intersect? and if they don't how to offset Path to touch the profile?
Code I am trying:
Dim oProfiles As ObjectCollection = GenerateNewProfilesFromMidcurves(newProfileSketch, midcurves)
' Get path's sketch
Dim pathSketch As PlanarSketch = path.Item(1).SketchEntity.Parent
' Make a new sketch by copying evrything from path sketch
Dim newPathSketch As PlanarSketch = Nothing
If whenSketchCopyWillWOrk Then
newPathSketch = CreateNewSketch(pathSketch, True) ' THIS IS CAUSING TRANSFOMRATION BUG, SO FOR NOW, USING THE OLD PROFILE ONLY
Else
pathSketch.Shared = True
newPathSketch = pathSketch
End If
' Need any geom entity of the sketch, for shifting/offsetting later
Dim newPath As Inventor.Path = Nothing
Dim anySketchEntity As SketchEntity = Nothing
If newPathSketch.SketchLines.Count > 0 Then
anySketchEntity = newPathSketch.SketchLines.Item(1)
ElseIf newPathSketch.SketchArcs.Count > 0 Then
anySketchEntity = newPathSketch.SketchArcs.Item(1)
Else
anySketchEntity = newPathSketch.SketchPoints.Item(1)
End If
' Profile and Path should intersect, but generally they are away. [ BUT, HOW TO CHECK IF THEY ARE INTERSECTING???]
' So, project first point on to path's sketch plane, and then offset the path to that point so that SWEEP's profile and path will intersect
Dim oStartPointProfile As SketchPoint = oProfiles.Item(1).Item(1).Item(1).StartSketchPoint
Dim wpt As WorkPoint = oCompDef.WorkPoints.AddFixed(oStartPointProfile.Geometry3d, True)
Dim whenOffsetStartsWorking As Boolean = False
If whenOffsetStartsWorking Then
' Get a point to offset the path to
Dim newProjectedPoint As SketchPoint = newPathSketch.AddByProjectingEntity(wpt)
Dim oCollection As ObjectCollection = _invApp.TransientObjects.CreateObjectCollection
oCollection.Add(anySketchEntity)
Dim offsettedentities As SketchEntitiesEnumerator = newPathSketch.OffsetSketchEntitiesUsingPoint(oCollection, newProjectedPoint.Geometry, True, False)
newPath = oCompDef.Features.CreatePath(offsettedentities.Item(1))
Else
newPath = oCompDef.Features.CreatePath(anySketchEntity)
End If
Ideally I would like to have the SWEPT surface as a NEWBODY, but thats bit far, for now trying to get basic Sweep working.