No, it is not an perfect cylinder. So I figured it out by traversing through all the Edges. Only Edges Normal to the direction, can be Circles or Arcs. (I assume...).
Here is the final code:
Sub SimplifyCylinder()
' This utility will create a new Cylinder, removing all internal voids.
Dim oT As TransientGeometry
Set oT = ThisApplication.TransientGeometry
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveEditDocument
Dim oPartDef As PartComponentDefinition
Set oPartDef = oDoc.ComponentDefinition
Dim oFace As Face
Set oFace = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "Select circular face")
If Not oFace Is Nothing Then
Dim oCylinder As Cylinder: Set oCylinder = oFace.geometry
Dim oWorkPlane As WorkPlane
Dim xdir As UnitVector
Dim ydir As UnitVector
Set xdir = oCylinder.AxisVector
' Create an arbitrary Vector, just so we can create the Normal plane.
Dim oPnt As Point
' Just add a random point to ensure we will always find a Plane.
Set oPnt = ThisApplication.TransientGeometry.CreatePoint(10.974769876, 45.574764, 10.743238787)
Dim v1 As Vector
Set v1 = oCylinder.BasePoint.VectorTo(oPnt)
Set ydir = xdir.CrossProduct(v1.AsUnitVector)
Set oWorkPlane = oPartDef.WorkPlanes.AddFixed(oCylinder.BasePoint, xdir, ydir, True)
Dim oEdge As Inventor.edge
Dim oCircle As Inventor.Circle
Dim oArc As Arc3d
Dim tmpLength As Double, Length As Double
For Each oEdge In oFace.Edges
If oEdge.GeometryType = kCircularArcCurve Then
Set oArc = oEdge.geometry
tmpLength = oCylinder.BasePoint.DistanceTo(oArc.Center)
ElseIf oEdge.GeometryType = kCircleCurve Then
Set oCircle = oEdge.geometry
tmpLength = oCylinder.BasePoint.DistanceTo(oCircle.Center)
End If
If tmpLength > Length Then
Length = tmpLength
End If
Next
Dim oSketch As PlanarSketch
Set oSketch = oPartDef.Sketches.Add(oWorkPlane)
Dim oSketchLines As SketchEntitiesEnumerator
Set oSketchLines = oSketch.SketchLines.AddAsTwoPointRectangle(oT.CreatePoint2d(0, 0), oT.CreatePoint2d(Length, oCylinder.Radius))
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid()
Dim oRevolve As RevolveFeature
Dim oSketchAxis As SketchLine
Set oSketchAxis = oSketch.SketchLines.AddByTwoPoints(oT.CreatePoint2d(0, 0), oT.CreatePoint2d(10, 0))
Set oRevolve = oPartDef.Features.RevolveFeatures.AddFull(oProfile, oSketchAxis, kJoinOperation)
oDoc.Update2 True
End If
End Sub