Making a Non Associative Spline Associative to defining points.
Making a Non Associative Spline Associative to defining points.
(OP)
I am working in NX7.5.3 and I am creating studio splines by selecting the points, one at a time. I noticed that it is possible to use the old spline operator and select all the points at once and create the spline. And then go back double click on it and assign associativity to the spline. The only problem is that the constraint of G0 is not assigned to the spline defining points. Does anyone know of a way to assign the G0 constraint?





RE: Making a Non Associative Spline Associative to defining points.
If they are point objects, what creates them? Are they the result of a laser scan, CMM, or something else?
If I understand correctly, you want to use a rectangle selection like in the old spline command, but create an associative spline from the points?
www.nxjournaling.com
RE: Making a Non Associative Spline Associative to defining points.
You are correct in your understanding. I want to a rectangle selection like the old spline operator would allow, and then create a spline that is associative to the defining points.
Background Information:
The points are being created from Sections through curves.
RE: Making a Non Associative Spline Associative to defining points.
Regards,
Tomas
RE: Making a Non Associative Spline Associative to defining points.
CODE
'April 24, 2012
'www.nxjournaling.com
'eng-tips thread561-320527: Making a Non Associative Spline Associative to defining points.
'Journal to create studio spline through existing point objects
'allows rectangle select of points, similar to old spline dialog
'resulting studio spline will be associative to the selected point objects
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim splineThruPoints() As NXObject
Dim axisToSort As String
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Studio Spline")
lw.Open()
splineThruPoints = SelectObjects("Select objects")
Dim startPoint As Point
startPoint = SelectPoint("Select Start Point")
Dim endPoint As Point
endPoint = SelectPoint("Select End Point")
axisToSort = increasingAxis(startPoint, endPoint)
Dim xCoords(splineThruPoints.GetUpperBound(0)) As Double
Dim yCoords(splineThruPoints.GetUpperBound(0)) As Double
Dim zCoords(splineThruPoints.GetUpperBound(0)) As Double
Dim pointTags(splineThruPoints.GetUpperBound(0)) As Tag
Dim i As Integer = 0
For Each obj As Point In splineThruPoints
xCoords(i) = obj.Coordinates.X
yCoords(i) = obj.Coordinates.Y
zCoords(i) = obj.Coordinates.Z
pointTags(i) = obj.Tag
i += 1
Next
If axisToSort = "X" Then
System.Array.Sort(xCoords, pointTags)
If startPoint.Coordinates.X <> xCoords(0) Then
System.Array.Reverse(xCoords)
System.Array.Reverse(pointTags)
End If
ElseIf axisToSort = "Y" Then
System.Array.Sort(yCoords, pointTags)
If startPoint.Coordinates.Y <> yCoords(0) Then
System.Array.Reverse(yCoords)
System.Array.Reverse(pointTags)
End If
Else
System.Array.Sort(zCoords, pointTags)
If startPoint.Coordinates.Z <> zCoords(0) Then
System.Array.Reverse(zCoords)
System.Array.Reverse(pointTags)
End If
End If
Dim nullFeatures_StudioSpline As Features.StudioSpline = Nothing
Dim studioSplineBuilder1 As Features.StudioSplineBuilder
studioSplineBuilder1 = workPart.Features.CreateStudioSplineBuilder(nullFeatures_StudioSpline)
studioSplineBuilder1.Associative = True
studioSplineBuilder1.InputCurveOption = Features.StudioSplineBuilder.CurveOption.Retain
studioSplineBuilder1.SplineMethod = Features.StudioSplineBuilder.Method.ThroughPoints
studioSplineBuilder1.Degree = 3
studioSplineBuilder1.IsPeriodic = False
studioSplineBuilder1.MatchKnots = Features.StudioSplineBuilder.MatchKnotsType.None
Dim knots1(-1) As Double
studioSplineBuilder1.SetKnots(knots1)
Dim parameters1(-1) As Double
studioSplineBuilder1.SetParameters(parameters1)
Dim nullDirection As Direction = Nothing
Dim nullScalar As Scalar = Nothing
Dim nullOffset As Offset = Nothing
Dim geometricConstraintData1(splineThruPoints.GetUpperBound(0)) As Features.GeometricConstraintData
For i = 0 To splineThruPoints.GetUpperBound(0)
geometricConstraintData1(i) = studioSplineBuilder1.ConstraintManager.CreateGeometricConstraintData()
geometricConstraintData1(i).Point = Utilities.NXObjectManager.Get(pointTags(i))
geometricConstraintData1(i).AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
geometricConstraintData1(i).AutomaticConstraintType = Features.GeometricConstraintData.AutoConstraintType.None
geometricConstraintData1(i).TangentDirection = nullDirection
geometricConstraintData1(i).TangentMagnitude = nullScalar
geometricConstraintData1(i).Curvature = nullOffset
geometricConstraintData1(i).CurvatureDerivative = nullOffset
geometricConstraintData1(i).HasSymmetricModelingConstraint = False
Next
studioSplineBuilder1.ConstraintManager.SetContents(geometricConstraintData1)
Dim feature1 As Features.Feature
feature1 = studioSplineBuilder1.CommitFeature()
studioSplineBuilder1.Destroy()
lw.Close()
End Sub
Function SelectObjects(ByVal prompt As String) As NXObject()
Dim selobj() As NXObject = Nothing
Dim theUI As UI = UI.GetUI
Dim title As String = "Selection"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(1) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_point_type
.Subtype = UFConstants.UF_point_subtype
.SolidBodySubtype = 0
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, selobj)
Return selobj
End Function
Function SelectPoint(ByVal prompt As String) As Point
Dim selobj As Point = Nothing
Dim theUI As UI = UI.GetUI
Dim title As String = "Selection"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(1) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_point_type
.Subtype = UFConstants.UF_point_subtype
.SolidBodySubtype = 0
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
prompt, title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, selobj, cursor)
Return selobj
End Function
Function increasingAxis(ByVal point1 As Point, ByVal point2 As Point) As String
'which axis has the greatest distance between start and end points? - sort by that axis
'possibly a bad assumption, but it's a start
Dim maxLength As Double
Dim maxAxis As String
Dim length As Double
maxLength = Math.Abs(point2.Coordinates.X - point1.Coordinates.X)
maxAxis = "X"
length = Math.Abs(point2.Coordinates.Y - point1.Coordinates.Y)
If length > maxLength Then
maxLength = length
maxAxis = "Y"
End If
length = Math.Abs(point2.Coordinates.Z - point1.Coordinates.Z)
If length > maxLength Then
maxLength = length
maxAxis = "Z"
End If
Return maxAxis
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module
www.nxjournaling.com