Showing results for 
Search instead for 
Did you mean: 

Divide Curve by Equal Arc Length Function

Valued Contributor
Valued Contributor

 I would like to have a function so it can take a curve and the number of segments as input parameters and return the name of the divided segments. I try to record the steps and adjust the record code to fit my need. I think I will be able to get the working code, however, how can I get (or set) the name of the divided segments so I can access them later?


Input = (Line A, 5), Output = Line A_01, Line A_02, Line A_03, Line A_04, Line_05?





Imports System
Imports NXOpen

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

' ----------------------------------------------
' Menu: Edit->Curve->Divide...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing

Dim divideCurveBuilder1 As NXOpen.Features.DivideCurveBuilder = Nothing
divideCurveBuilder1 = workPart.BaseFeatures.CreateDivideCurveBuilder(nullNXOpen_Features_Feature)

Dim origin1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal1 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane1 As NXOpen.Plane = Nothing
plane1 = workPart.Planes.CreatePlane(origin1, normal1, NXOpen.SmartObject.UpdateOption.WithinModeling)

Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

Dim expression1 As NXOpen.Expression = Nothing
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression2 As NXOpen.Expression = Nothing
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

divideCurveBuilder1.EqualParameterSegments = 10

Dim boundingObjectBuilder1 As NXOpen.GeometricUtilities.BoundingObjectBuilder = Nothing
boundingObjectBuilder1 = workPart.CreateBoundingObjectBuilder()

Dim origin2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal2 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane2 As NXOpen.Plane = Nothing
plane2 = workPart.Planes.CreatePlane(origin2, normal2, NXOpen.SmartObject.UpdateOption.WithinModeling)

boundingObjectBuilder1.BoundingPlane = plane2

Dim expression3 As NXOpen.Expression = Nothing
expression3 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression4 As NXOpen.Expression = Nothing
expression4 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim nullNXOpen_Plane As NXOpen.Plane = Nothing

boundingObjectBuilder1.BoundingPlane = nullNXOpen_Plane


theSession.SetUndoMarkName(markId1, "Divide Curve Dialog")

Dim theUI As UI = UI.GetUI()

Dim point1 As NXOpen.Point3d = New NXOpen.Point3d(3693.378374003441, 532.86486737767007, 1.1368683772161603e-013)
divideCurveBuilder1.DividingCurve.SetValue(CType(theUI.SelectionManager.GetSelectedObject(0), NXOpen.Line), workPart.ModelingViews.WorkView, point1)

divideCurveBuilder1.EqualSegmentMethod = NXOpen.Features.DivideCurveBuilder.EqualSegmentOption.EqualArcLength

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Divide Curve")

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Divide Curve")

Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = divideCurveBuilder1.Commit()

Dim objects1() As NXOpen.NXObject
objects1 = divideCurveBuilder1.GetCommittedObjects()

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(markId1, "Divide Curve")


' Expression is still in use.
Catch ex As NXException
End Try

' Expression is still in use.
Catch ex As NXException
End Try

' Expression is still in use.
Catch ex As NXException
End Try


' Expression is still in use.
Catch ex As NXException
End Try


Dim scaleAboutPoint1 As NXOpen.Point3d = New NXOpen.Point3d(98.361921939289502, -48.206437304459811, 0.0)
Dim viewCenter1 As NXOpen.Point3d = New NXOpen.Point3d(-98.361921939289502, 48.206437304460707, 0.0)
workPart.ModelingViews.WorkView.ZoomAboutPoint(0.80000000000000004, scaleAboutPoint1, viewCenter1)

Dim scaleAboutPoint2 As NXOpen.Point3d = New NXOpen.Point3d(122.95240242411182, -60.258046630574817, 0.0)
Dim viewCenter2 As NXOpen.Point3d = New NXOpen.Point3d(-122.95240242411182, 60.258046630575734, 0.0)
workPart.ModelingViews.WorkView.ZoomAboutPoint(0.80000000000000004, scaleAboutPoint2, viewCenter2)

Dim scaleAboutPoint3 As NXOpen.Point3d = New NXOpen.Point3d(158.15706982890217, -78.164918978340154, 0.0)
Dim viewCenter3 As NXOpen.Point3d = New NXOpen.Point3d(-158.15706982890217, 78.164918978341049, 0.0)
workPart.ModelingViews.WorkView.ZoomAboutPoint(0.80000000000000004, scaleAboutPoint3, viewCenter3)

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Re: Divide Curve by Equal Arc Length Function

Siemens Phenom Siemens Phenom
Siemens Phenom

Adapted from the documentation of the Snap.NX.Curve.Divide function:


Option Infer On
Imports Snap, Snap.Create

Public Class MyProgram

   Public Shared Sub Main()

      ' Create a 90-degree elliptical arc to be divided
      Dim curve = Ellipse(Position.Origin, 5, 3, 0, 0, 90)

      ' Calculate parameters at 25%, 50%, 75% arclengths
      Dim t25 = curve.Parameter(0.25)
      Dim t50 = curve.Parameter(0.50)
      Dim t75 = curve.Parameter(0.75)

      ' Use these parameter values to divide the ellipse into four pieces
      Dim pieces As NX.Ellipse() = curve.Divide(t25, t50, t75)

      ' Hide the original curve and name the pieces
      curve.IsHidden = True
      pieces(0).Name = "curve0"
      pieces(1).Name = "curve1"
      pieces(2).Name = "curve2"
      pieces(3).Name = "curve3"

      ' Report the arclengths of the four pieces, to confirm they are equal
      For Each segment In pieces
         InfoWindow.WriteLine("Arclength: " & segment.ArcLength.ToString("F8"))

   End Sub

End Class

Re: Divide Curve by Equal Arc Length Function

Valued Contributor
Valued Contributor

Thanks, I will try it.  The snap code is much cleaner than the jx record Smiley Happy 

Re: Divide Curve by Equal Arc Length Function

Valued Contributor
Valued Contributor

This may be a simple question but I am confused, so the arc object is not curve object? When I try to divide the curve (which its ID is Arc 1234)  by, the pieces().count only returns 1, although there is no error.


There is anyway to convert an Arc to curve so it can be divided properly? 

Re: Divide Curve by Equal Arc Length Function

Siemens Phenom Siemens Phenom
Siemens Phenom

A Snap.NX.Arc object is indeed a Snap.NX.Curve object.


I don't know why the Divide function is not doing what you expect.


You can convert an arc to a spline using the ToSpline function, and see if that helps. But I don't see any reason why it should.


Dividing an arc into equal pieces is easy, anyway -- you just divide the angular span into equal pieces.