cast object type NXOpen.Features.TroughtCurves to type NXOpen.body

How I can cast object type NXOpen.Features.TroughtCurves to type NXOpen.body

I make a function to join two solid, the solid are:

throughCurvesBuilder1.BodyPreference = Features.ThroughCurvesBuilder.BodyPreferenceTypes.Solid

Journalist save the following option

Dim body1 As Body = CType(workPart.Bodies.FindObject("THRU_CURVE(39)"), Body)

but I change for:

Dim body1 As Body
body1 = Sold1

I receive the following error

"cast object type NXOpen.Features.TroughtCurves to type NXOpen.body"

I send two Function(SupThroughCurve,UnionSolidos), one make TroughCurve Solid object and the other receive this Object to joing

Public Function SupThroughCurve(ByVal Sec01 As Object, ByVal Sec02 As Object) As Object

Dim nullFeatures_Feature As Features.Feature = Nothing

Dim throughCurvesBuilder1 As Features.ThroughCurvesBuilder
throughCurvesBuilder1 = workPart.Features.CreateThroughCurvesBuilder(nullFeatures_Feature)

throughCurvesBuilder1.PreserveShape = False
throughCurvesBuilder1.PatchType = Features.ThroughCurvesBuilder.PatchTypes.Multiple
throughCurvesBuilder1.Alignment.AlignCurve.DistanceTolerance = 0.0254
throughCurvesBuilder1.Alignment.AlignCurve.ChainingTolerance = 0.02413
throughCurvesBuilder1.SectionTemplateString.DistanceTolerance = 0.0254
throughCurvesBuilder1.SectionTemplateString.ChainingTolerance = 0.02413
throughCurvesBuilder1.Alignment.AlignCurve.AngleTolerance = 0.5
throughCurvesBuilder1.SectionTemplateString.AngleTolerance = 0.5

'throughCurvesBuilder1.BodyPreference = Features.ThroughCurvesBuilder.BodyPreferenceTypes.Sheet
throughCurvesBuilder1.BodyPreference = Features.ThroughCurvesBuilder.BodyPreferenceTypes.Solid

Dim section1 As Section
section1 = workPart.Sections.CreateSection(0.0, 0.0, 0.0)
throughCurvesBuilder1.SectionsList.Append(section1)
section1.SetAllowedEntityTypes(Section.AllowTypes.CurvesAndPoints)

'Procesa la seccion1
'*******************
Dim curves1(0) As IBaseCurve
'Dim arc1 As Arc = CType(workPart.Arcs.FindObject("ENTITY 5 37 1"), Arc)

Dim arc1 As NXopen.Arc
arc1 = Sec01

curves1(0) = Sec01
Dim curveDumbRule1 As CurveDumbRule
curveDumbRule1 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves1)

section1.AllowSelfIntersection(False)

Dim rules1(0) As SelectionIntentRule
rules1(0) = curveDumbRule1
Dim nullNXObject As NXObject = Nothing

Dim helpPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
section1.AddToSection(rules1, arc1, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)

Dim sections1(0) As Section
sections1(0) = section1
throughCurvesBuilder1.Alignment.SetSections(sections1)

'Procesa la seccion2
'*******************
Dim section2 As Section
section2 = workPart.Sections.CreateSection(0.0, 0.0, 0.0)

throughCurvesBuilder1.SectionsList.Append(section2)

section2.SetAllowedEntityTypes(Section.AllowTypes.CurvesAndPoints)

Dim curves2(0) As IBaseCurve
'Dim arc2 As Arc = CType(workPart.Arcs.FindObject("ENTITY 5 35 1"), Arc)

Dim arc2 As NXopen.Arc
arc2 = Sec02
curves2(0) = Sec02
Dim curveDumbRule2 As CurveDumbRule
curveDumbRule2 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves2)

section2.AllowSelfIntersection(False)

Dim rules2(0) As SelectionIntentRule
rules2(0) = curveDumbRule2
Dim helpPoint2 As Point3d = New Point3d(0.0, 0.0, 0.0)
section2.AddToSection(rules2, arc2, nullNXObject, nullNXObject, helpPoint2, Section.Mode.Create, False)

Dim sections2(1) As Section
sections2(0) = section1
sections2(1) = section2
throughCurvesBuilder1.Alignment.SetSections(sections2)

Dim feature1 As Features.Feature
feature1 = throughCurvesBuilder1.CommitFeature()

throughCurvesBuilder1.Destroy()

Return feature1

End Function

Public Function UnionSolidos(ByVal Sold1 As Object, ByVal Sold2 As Object) As NXObject

Dim nullFeatures_BooleanFeature As Features.BooleanFeature = Nothing

Dim booleanBuilder1 As Features.BooleanBuilder
booleanBuilder1 = workPart.Features.CreateBooleanBuilderUsingCollector(nullFeatures_BooleanFeature)

Dim scCollector1 As ScCollector
scCollector1 = booleanBuilder1.ToolBodyCollector

Dim booleanRegionSelect1 As GeometricUtilities.BooleanRegionSelect
booleanRegionSelect1 = booleanBuilder1.BooleanRegionSelect

booleanBuilder1.Tolerance = 0.0254

booleanBuilder1.Operation = Features.Feature.BooleanType.Unite

'Solido1 receptor
'***************
'Dim body1 As Body = CType(workPart.Bodies.FindObject("THRU_CURVE(39)"), Body)
Dim body1 As Body
body1 = Sold1

Dim added1 As Boolean
added1 = booleanBuilder1.Targets.Add(body1)

Dim targets1(0) As TaggedObject
targets1(0) = body1
booleanRegionSelect1.AssignTargets(targets1)

Dim scCollector2 As ScCollector
scCollector2 = workPart.ScCollectors.CreateCollector()

Dim bodies1(0) As Body

'Solido2
'****************
'Dim body2 As Body = CType(workPart.Bodies.FindObject("THRU_CURVE(40)"), Body)

Dim body2 As Body
body2 = Sold2

bodies1(0) = body2
Dim bodyDumbRule1 As BodyDumbRule
bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1)

Dim rules1(0) As SelectionIntentRule
rules1(0) = bodyDumbRule1
scCollector2.ReplaceRules(rules1, False)

booleanBuilder1.ToolBodyCollector = scCollector2

Dim targets2(0) As TaggedObject
targets2(0) = body1
booleanRegionSelect1.AssignTargets(targets2)

Dim nXObject1 As NXObject
nXObject1 = booleanBuilder1.Commit()

booleanBuilder1.Destroy()

Return nXObject1

End Function

Someone can help me

The through curves builder will return a reference to the through curves feature:

Dim feature1 As Features.Feature
feature1 = throughCurvesBuilder1.CommitFeature()

The through curves feature has a .GetBodies method that you can use to get references to the body(ies) created by the feature. A simplistic example would be:

dim body1 as body = feature1.GetBodies(0)