Cancel
Showing results for
Did you mean:

# Divide the tube solid body into multiple equal length bodies, SNAP/NX Open VB

Valued Contributor

I have a main tube solid body, let's assume its length is 100mm.  I would like to create 10 solid bodies from the main solid body to have 10mm each.  Anyway way to do this?

4 REPLIES

# Re: Divide the tube solid body into multiple equal length bodies, SNAP/NX Open VB

Genius

Maybe try the following approach:

Create the tube feature

Create an "Isoparametic Curve" Feature in "V-direction"

Create a plane for everey circle

Create a split body for every plane

This can be either done "manually" or scripted. The scripted way could create the planes without the "Isoparametric Curve" Feature.

# Re: Divide the tube solid body into multiple equal length bodies, SNAP/NX Open VB

Genius
Exchange the "plane" step with "bounded plane" because other wise "split Body" might split sour Body where yo do not want to split...

# Re: Divide the tube solid body into multiple equal length bodies, SNAP/NX Open VB

Experimenter

Hello,

here is a simple code with selection and inputbox. Usage: create a line, and a tube feature. Play the journal, select the body of the tube, and the guide curve of the tube (the journal will prompt), set the number of bodies. The code does not work on helix, arcs, circles in many cases, becuse of the splitting geometry is a plane. If you try it on a helices you will see what I mean.
Hope this helps!

```Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
Sub Main(ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim markId1 As NXOpen.Session.UndoMarkId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Split Body")

Dim splitBodyBuilder1 As NXOpen.Features.SplitBodyBuilder = Nothing
splitBodyBuilder1 = workPart.Features.CreateSplitBodyBuilderUsingCollector(Nothing)
splitBodyBuilder1.BooleanTool.ToolOption = NXOpen.GeometricUtilities.BooleanToolBuilder.BooleanToolType.NewPlane
Dim scCollector1 As NXOpen.ScCollector = Nothing
scCollector1 = workPart.ScCollectors.CreateCollector()
Dim TubeBody As NXOpen.Body

If SelectTube("Select Tube to Split...", TubeBody) = Selection.Response.Cancel Then
Exit Sub
End If

Dim bodies1(0) As NXOpen.Body
bodies1(0) = TubeBody
Dim bodyDumbRule1 As NXOpen.BodyDumbRule = Nothing
bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, True)

Dim rules1(0) As NXOpen.SelectionIntentRule
rules1(0) = bodyDumbRule1
scCollector1.ReplaceRules(rules1, False)
splitBodyBuilder1.TargetBodyCollector = scCollector1

Dim GuideCurve As NXOpen.Curve
If SelectGuide("Select Tube Guide Curve...", GuideCurve) = Selection.Response.Cancel Then
Exit Sub
End If
Dim splitNR = NXOpenUI.NXInputBox.GetInputString("Input parameter...", "Enter the number of bodies:", "10")
Dim Percent As NXOpen.Scalar = Nothing
For i As Integer = 1 To splitNR - 1
Percent = workPart.Scalars.CreateScalar(i * 100 / CDbl(splitNR), NXOpen.Scalar.DimensionalityType.None, NXOpen.SmartObject.UpdateOption.WithinModeling)
Dim CurvePT As NXOpen.Point = Nothing
CurvePT = workPart.Points.CreatePoint(GuideCurve, Percent, NXOpen.PointCollection.PointOnCurveLocationOption.PercentArcLength, NXOpen.SmartObject.UpdateOption.WithinModeling)
Dim Dir As NXOpen.Direction = Nothing
Dir = workPart.Directions.CreateDirection(GuideCurve, CurvePT, NXOpen.Direction.OnCurveOption.Tangent, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)
Dim Origin As NXOpen.Point3d = CurvePT.Coordinates
Dim Normal As NXOpen.Vector3d = Dir.Vector
Dim SplitPlane As NXOpen.Plane =  workPart.Planes.CreatePlane(Origin, Normal, NXOpen.SmartObject.UpdateOption.WithinModeling)
splitBodyBuilder1.BooleanTool.FacePlaneTool.ToolPlane = SplitPlane
SplitPlane.Evaluate()
splitBodyBuilder1.CommitFeature()
Next
splitBodyBuilder1.Destroy()
End Sub

Function SelectTube(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
.Type = UFConstants.UF_UI_SEL_FEATURE_BODY
.SubType = 0
.SolidBodySubtype = 0
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, "Select Tube Feature Body:", Selection.SelectionScope.AnyInAssembly, selAction, _
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Function SelectGuide(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim typeArray() As Selection.SelectionType = {Selection.SelectionType.Curves}

Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, "Select Tube Guide Curve:", _
Selection.SelectionScope.AnyInAssembly, False, typeArray, selobj, cursor)

If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module```

# Re: Divide the tube solid body into multiple equal length bodies, SNAP/NX Open VB

Experimenter

Hello,

here is a simple code with selection and inputbox. Usage: create a line (guide) and a tube feature. Play the journal. Select the tube body and its guide curve, set the number of splitted bodies. The code does not work on arcs, circles, helices because of the splitting geometry is a plane. If you try the journal on a helix, you will see what I mean.
Hope this helps!

`Imports SystemImports NXOpenImports NXOpen.UFModule NXJournal Sub Main(ByVal args() As String) Dim theSession As NXOpen.Session = NXOpen.Session.GetSession() Dim workPart As NXOpen.Part = theSession.Parts.Work Dim displayPart As NXOpen.Part = theSession.Parts.Display Dim markId1 As NXOpen.Session.UndoMarkId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Split Body") Dim splitBodyBuilder1 As NXOpen.Features.SplitBodyBuilder = Nothing splitBodyBuilder1 = workPart.Features.CreateSplitBodyBuilderUsingCollector(Nothing) splitBodyBuilder1.BooleanTool.ToolOption = NXOpen.GeometricUtilities.BooleanToolBuilder.BooleanToolType.NewPlane Dim scCollector1 As NXOpen.ScCollector = Nothing scCollector1 = workPart.ScCollectors.CreateCollector() Dim TubeBody As NXOpen.Body If SelectTube("Select the Tube to split...", TubeBody) = Selection.Response.Cancel Then Exit Sub End If Dim bodies1(0) As NXOpen.Body bodies1(0) = TubeBody Dim bodyDumbRule1 As NXOpen.BodyDumbRule = Nothing bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, True) Dim rules1(0) As NXOpen.SelectionIntentRule rules1(0) = bodyDumbRule1 scCollector1.ReplaceRules(rules1, False) splitBodyBuilder1.TargetBodyCollector = scCollector1 Dim GuideCurve As NXOpen.Curve If SelectGuide("Select Tube Guide Curve...", GuideCurve) = Selection.Response.Cancel Then Exit Sub End If Dim splitNR = NXOpenUI.NXInputBox.GetInputString("Input parameter...", "Enter the Number of Bodies:", "10") Dim Percent As NXOpen.Scalar = Nothing For i As Integer = 1 To splitNR - 1 Percent = workPart.Scalars.CreateScalar(i * 100 / CDbl(splitNR), NXOpen.Scalar.DimensionalityType.None, NXOpen.SmartObject.UpdateOption.WithinModeling) Dim CurvePT As NXOpen.Point = Nothing CurvePT = workPart.Points.CreatePoint(GuideCurve, Percent, NXOpen.PointCollection.PointOnCurveLocationOption.PercentArcLength, NXOpen.SmartObject.UpdateOption.WithinModeling) Dim Dir As NXOpen.Direction = Nothing Dir = workPart.Directions.CreateDirection(GuideCurve, CurvePT, NXOpen.Direction.OnCurveOption.Tangent, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling) Dim Origin As NXOpen.Point3d = CurvePT.Coordinates Dim Normal As NXOpen.Vector3d = Dir.Vector Dim SplitPlane As NXOpen.Plane = workPart.Planes.CreatePlane(Origin, Normal, NXOpen.SmartObject.UpdateOption.WithinModeling) splitBodyBuilder1.BooleanTool.FacePlaneTool.ToolPlane = SplitPlane SplitPlane.Evaluate() splitBodyBuilder1.CommitFeature() Next splitBodyBuilder1.Destroy() End Sub Function SelectTube(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response Dim theUI As UI = UI.GetUI Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific Dim cursor As Point3d Dim selectionMask_array(0) As Selection.MaskTriple With selectionMask_array(0) .Type = UFConstants.UF_UI_SEL_FEATURE_BODY .SubType = 0 .SolidBodySubtype = 0 End With Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, "Select Tube Feature Body:", Selection.SelectionScope.AnyInAssembly, selAction, _ False, False, selectionMask_array, selObj, cursor) If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Function SelectGuide(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response Dim theUI As UI = UI.GetUI Dim cursor As Point3d Dim typeArray() As Selection.SelectionType = {Selection.SelectionType.Curves} Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, "Select Tube Guide Curve:", _ Selection.SelectionScope.AnyInAssembly, False, typeArray, selobj, cursor) If resp = Selection.Response.ObjectSelected Or _ resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End FunctionEnd Module`