Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datums On Curve Through Point Sets 2

Status
Not open for further replies.

ChaseWichert

Mining
Jan 4, 2012
147
Is there a way to create a point set on a curve and in one step create datums normal to the curve on all of the points in the set?

Thanks
 
Replies continue below

Recommended for you

No, but you should be able to do what you need with a macro or journal.
 
Thanks, I'm not so hip on macroing or journaling, but I am sure if it is a necessity someone else at my work can do that.
 
Here is a journal which allows you to select a spline and then define the number of datum planes required to be placed on the spline. The points for the datum origin are associative so that you can move the points along the spline to change the datum plane location/orientation.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF

Module datumPlanesonSpline
Dim s As Session = Session.GetSession()
Dim ui As UI = ui.GetUI()
Dim ufs As UFSession = UFSession.GetUFSession()

Sub Main()
Dim mask(0) As Selection.MaskTriple
mask(0).Type = UFConstants.UF_spline_type
mask(0).Subtype = 0
mask(0).SolidBodySubtype = 0

Dim spline1 As Spline = Nothing
Dim cursor As Point3d = Nothing

Dim markId1 As Session.UndoMarkId
markId1 = s.SetUndoMark(Session.MarkVisibility.Visible, "Start")

' Select a spline

Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject("Datum Planes on Spline", "Select a Spline", _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, spline1, cursor)

' Get the number of datum planes
Dim no1 As Integer = NXInputBox.GetInputNumber("Enter Number of Datum Planes")

' Spline points and parameters
Dim parm As Double = 0.0
Dim delparm As Double = 1.0 / (no1 - 1)
Dim pnt1(2) As Double
Dim junk3(2) As Double
Dim junk1 As Double
' Create Datum Planes
For i As Integer = 0 To no1 - 1
ufs.Modl.AskCurveProps(spline1.Tag, parm, pnt1, junk3, junk3, junk3, junk1, junk1)
CreateDatumPlane(spline1, pnt1, parm)
parm += delparm
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function

Public Sub CreateDatumPlane(ByVal spline1 As Spline, ByVal pnt1() As Double, ByVal parm1 As Double)
Dim workPart As Part = s.Parts.Work
Dim nullFeatures_Feature As Features.Feature = Nothing
Dim pointFeatureBuilder1 As Features.PointFeatureBuilder
pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)
Dim datumPlaneBuilder1 As Features.DatumPlaneBuilder
datumPlaneBuilder1 = workPart.Features.CreateDatumPlaneBuilder(nullFeatures_Feature)
Dim plane1 As Plane
plane1 = datumPlaneBuilder1.GetPlane()
Dim scalar1 As Scalar
scalar1 = workPart.Scalars.CreateScalar(parm1, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
Dim point1 As Point
point1 = workPart.Points.CreatePoint(spline1, scalar1, SmartObject.UpdateOption.WithinModeling)
pointFeatureBuilder1.Point = point1
Dim nXObject1 As NXObject
nXObject1 = pointFeatureBuilder1.Commit()

Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(spline1, scalar1, Direction.OnCurveOption.Tangent, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
plane1.SetMethod(PlaneTypes.MethodType.PointDir)

Dim geom1(1) As NXObject
geom1(0) = point1
geom1(1) = direction1
plane1.SetGeometry(geom1)

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

Dim datumPlaneFeature1 As Features.DatumPlaneFeature = CType(feature1, Features.DatumPlaneFeature)

Dim datumPlane1 As DatumPlane
datumPlane1 = datumPlaneFeature1.DatumPlane

datumPlaneBuilder1.Destroy()
pointFeatureBuilder1.Destroy()

End Sub

End Module

Hope this helps you.

Frank Swinkels
 
FrankSwinks,

I am trying to adapt your code to my needs. I have a program, placing a spline, putting points on the spline, then datums on the points normal to the spline. I am up to the datum part, the program is selecting the existing point, preferably I'd like it to use the point "NAME" rather than the designation Point (1), but haven't figured that out yet, but right now I'm just trying to get the datum to place.

Code:
Sub PlaceDatum( ByRef counter as Integer )

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

        Dim displayPart As Part = theSession.Parts.Display

        Dim nullFeatures_Feature As Features.Feature = Nothing
        Dim pointFeatureBuilder1 As Features.PointFeatureBuilder
        pointFeatureBuilder1 = workPart.BaseFeatures.
         _CreatePointFeatureBuilder(nullFeatures_Feature)
        Dim datumPlaneBuilder1 As Features.DatumPlaneBuilder
        datumPlaneBuilder1 = workPart.Features.
         _CreateDatumPlaneBuilder(nullFeatures_Feature)
        Dim plane1 As Plane
        plane1 = datumPlaneBuilder1.GetPlane()

        Dim scalar1 As Scalar
        'dim counter as integer = 4


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


        Dim expression1 As Expression
        expression1 = workPart.Expressions.
         _CreateSystemExpressionWithUnits("0", unit1)
        scalar1 = workPart.Scalars.
         _CreateScalarExpression(expression1, Scalar.
         _DimensionalityType.None, SmartObject.UpdateOption.
         _WithinModeling)

        Dim curves1(0) As Curve
        Dim spline1 As Spline = CType(workPart.Splines.
         _FindObject("ENTITY 9 1 1"), Spline)

        curves1(0) = spline1


        Dim pointFeature1 As Features.PointFeature = 
         _CType(workPart.Features.FindObject("POINT (2)" ), 
         _Features.PointFeature)

        Dim point1 As Point = CType(pointFeature1.
         _FindObject("POINT 2" ), Point)

        Dim direction1 As Direction
        direction1 = workPart.Directions.
         _CreateDirection(spline1, scalar1, Direction.
         _OnCurveOption.Tangent, Sense.Forward, 
         _SmartObject.UpdateOption.WithinModeling)
        plane1.SetMethod(PlaneTypes.MethodType.PointDir)


        Dim geom1(1) As NXObject
        geom1(0) = point1
        geom1(1) = direction1
        plane1.SetGeometry(geom1)

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

        Dim datumPlaneFeature1 As Features.DatumPlaneFeature = 
         _CType(feature1, Features.DatumPlaneFeature)

        Dim datumPlane1 As DatumPlane
        datumPlane1 = datumPlaneFeature1.DatumPlane

        datumPlaneBuilder1.Destroy()
        pointFeatureBuilder1.Destroy()



End Sub

I get an error, for a No object found with this name on the following line:

datumPlane1 = datumPlaneFeature1.DatumPlane

Any idea what I've done wrong?
 
Okay, the prgram works so long as the point being searched for is Point 1, even though I have 14 points in the current model, it will not find the other points.

Any one have any idea why? To my mind the findObject command should find the object of the specified name and I am only changing the number. I haven't started looking into how to get the program to find the named property of a point or datum or what have you.
 
I have changed the code so that we get all points and then check for the points that lie on the spline. The datum creation sub needs to be a little different.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF

Module datumPlanesonSpline
Dim s As Session = Session.GetSession()
Dim ui As UI = ui.GetUI()
Dim ufs As UFSession = UFSession.GetUFSession()

Sub Main()
Dim mask(0) As Selection.MaskTriple
mask(0).Type = UFConstants.UF_spline_type
mask(0).Subtype = 0
mask(0).SolidBodySubtype = 0
Dim dispPart As Part = s.Parts.Display
Dim spline1 As Spline = Nothing
Dim cursor As Point3d = Nothing

Dim markId1 As Session.UndoMarkId
markId1 = s.SetUndoMark(Session.MarkVisibility.Visible, "Start")

' Select a spline

Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject("Datum Planes on Spline", "Select a Spline", _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, spline1, cursor)

Dim parm As Double = Nothing
Dim pntdouble(2) As Double
Dim pnt3d As Point3d
Dim pnts1 As PointCollection = dispPart.Points
Dim crvpnt(2) As Double
Dim distance1 As Double = Nothing
For Each pnt As Point In pnts1
pnt3d = pnt.Coordinates
pntdouble(0) = pnt3d.X
pntdouble(1) = pnt3d.Y
pntdouble(2) = pnt3d.Z
ufs.Modl.AskCurveParm(spline1.Tag, pntdouble, parm, crvpnt)
' must check that points lie on curve
ufs.Vec3.Distance(pntdouble, crvpnt, distance1)
If distance1 > 0.001 Then Continue For
CreateDatumPlane(spline1, pnt, parm)
Next

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function

Public Sub CreateDatumPlane(ByVal spline1 As Spline, ByVal pnt1 As Point, ByVal parm1 As Double)
Dim workPart As Part = s.Parts.Work
Dim nullFeatures_Feature As Features.Feature = Nothing
Dim pointFeatureBuilder1 As Features.PointFeatureBuilder
pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)
Dim datumPlaneBuilder1 As Features.DatumPlaneBuilder
datumPlaneBuilder1 = workPart.Features.CreateDatumPlaneBuilder(nullFeatures_Feature)
Dim plane1 As Plane
plane1 = datumPlaneBuilder1.GetPlane()
Dim scalar1 As Scalar
scalar1 = workPart.Scalars.CreateScalar(parm1, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)

Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(spline1, scalar1, Direction.OnCurveOption.Tangent, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
plane1.SetMethod(PlaneTypes.MethodType.PointDir)

Dim geom1(1) As NXObject
geom1(0) = pnt1
geom1(1) = direction1
plane1.SetGeometry(geom1)

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

datumPlaneBuilder1.Destroy()
pointFeatureBuilder1.Destroy()

End Sub

End Module

Regards

Frank Swinkels
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor