Issue:
I generated programatically a skechs with a series of arcs, straight lines and spline. How can I check through the API that the segments form a closed loop, such that when I use the revole command I will be able to generate a solis from the skech profile?
Solution:
ProfilePath.Closed tells if the profile is closed or not. The segment from the profile is "ProfileEntity". You can iterate the ProfilePath object to find all ProfileEntity object. The sample code below accesses the ProfileEntity and create revolve feature. Please note it will create the solid if the profile is closed or the surface if the profile is open.
Dim oApp As Inventor.Application
Public Sub CreateRevolveFeature()
Set oApp = ThisApplication
Dim oPartDoc As PartDocument
Dim oSketch As PlanarSketch
Set oPartDoc = oApp.ActiveDocument
' Get the sketch you are interested in
' We here select Sketch1...
Set oSketch = oPartDoc.ComponentDefinition.Sketches.Item(1)
Dim oProfile As Profile
On Error Resume Next
Set oProfile = oSketch.Profiles.AddForSolid(True)
If Err.Number <> 0 Then
' it appears that the profile is open, so use AddForSurface
Set oProfile = oSketch.Profiles.AddForSurface
Err.Clear
End If
Dim hs As HighlightSet
Set hs = oPartDoc.HighlightSets.Add
Dim oPath As ProfilePath
Set oPath = oProfile.Item(1)
Dim i As Integer
For i = 1 To oPath.Count
Dim oPfEntity As ProfileEntity
Set oPfEntity = oPath.Item(i)
'Add a breakpoint here,you can observe the highlighted segments from UI
hs.AddItem oPfEntity.SketchEntity
Next
Dim oTG As TransientGeometry
Set oTG = oApp.TransientGeometry
Dim oLine As SketchLine
Set oLine = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(0, 10))
Dim oRevFeature As RevolveFeature
'if the profile is open
If oPath.Closed = False Then
Set oRevFeature = oPartDoc.ComponentDefinition.Features.RevolveFeatures.AddFull(oProfile, oLine, kSurfaceOperation)
Else
'if the profile is closed
Set oRevFeature = oPartDoc.ComponentDefinition.Features.RevolveFeatures.AddFull(oProfile, oLine, kJoinOperation)
End If
oApp.ActiveView.Fit
End Sub