I could not find a elegant solution but maby it helps you.
i found that the property "_sketch1.Profiles" always gives the same profile and i could not find a elegant/correct way to loop over all profiles in a skecth. But i found that you can look up a profile that is consumed by a line in a sketch. if you loop over all lines then you will find all profiles. You will get to many profiles because 1 profile consumes multiple lines. There for you need to filter/check if you putted a profile already in the profile-list. i did not find a elegant/correct way to compare 2 profiles there for filetering is done by comparing the areas. (Yes that is way this code does not work if you have profiles with the same area.) Also im running inventor 2018 and i could not get all profiles in 1 patches there for i create a patch for each profile.
any way this is what i found.
Dim _partDoc As PartDocument = ThisApplication.ActiveDocument
Dim _partDef As PartComponentDefinition = _partDoc.ComponentDefinition
Dim _transGeometry As TransientGeometry = ThisApplication.TransientGeometry
Dim _sketch1 As PlanarSketch = _partDef.Sketches.Item(1)
Dim profiles As List(Of Profile) = New List(Of Profile)()
'creat a profile from all lines in the sketch
For Each line As SketchLine In _sketch1.SketchLines
Dim profileIsConsumed = False
Dim profile As Profile = _sketch1.Profiles.AddForSurface(line)
'check if there is already a profile in the list of profile with the same Area
For Each cProfile As Profile In profiles
If (Math.Abs(cProfile.RegionProperties.Area - profile.RegionProperties.Area) < 0.0000001) Then
profileIsConsumed = True
Exit For
End If
Next
'if there is already a profile with the the same area then dnt add it again to the list.
If (profileIsConsumed = False) Then
profiles.Add(profile)
End If
Next
For Each profile As Profile In profiles
Dim _boundaryPatchDef As BoundaryPatchDefinition = _partDef.Features.BoundaryPatchFeatures.CreateBoundaryPatchDefinition()
_boundaryPatchDef.BoundaryPatchLoops.Add(profile)
Dim BoundaryPatchFeatures As BoundaryPatchFeature = _partDef.Features.BoundaryPatchFeatures.Add(_boundaryPatchDef)
Next
It could (or should) be improved but i dont know how. maby some one else has a better solution.
P.S. if you post code in the here the please dont put it in a picture. i had to retype all your code to have a first look at it. If you post code in plane text its easyer for people that want to help you.
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com