×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Intersection curve

Intersection curve

Intersection curve

(OP)
I have an automation program, It creates a spline using a file listing a series of points.  Then rotates the spline 20 degrees.  Places a datum at the origin at a specified angle, places an intersection line on the surface and finally puts a point on the line.

The problem I am having is that the point sometimes has a zero value and other times the other end is the zero end.  I am not sure why it is doing this.

The program is HUGE, I can send it to a person if it is needed.  However here is the Intersection and Place Point Subs of the program.

CODE

   Public Sub IntersectionLine( ByRef splineRevolve As Features.Revolve, ByRef rotatedDatum As DatumPlane, _
      ByRef SplineSCurve As Spline, ByRef counter As Integer, ByRef boolIntersection As Boolean )

      Dim intersectionCurveBuilder1 As Features.IntersectionCurveBuilder
      Dim plane1                    As Plane
      Dim plane2                    As Plane
      Dim section1                  As Section
      Dim section2                  As Section
      Dim section3                  As Section
      Dim section4                  As Section
      Dim expression1               As Expression
      Dim expression2               As Expression
      Dim expression3               As Expression
      Dim expression4               As Expression
      Dim expression5               As Expression
      Dim expression6               As Expression
      Dim objects2(0)               As TaggedObject
      Dim added2                    As Boolean
      Dim rotMatrix1                As Matrix3x3
      Dim faceTangentRule1          As FaceTangentRule
      Dim boundaryFaces1(-1)        As Face
      Dim rules1(0)                 As SelectionIntentRule
      Dim geom1(0)                  As NXObject
      Dim geom2(0)                  As NXObject
      Dim nXObject1                 As NXObject
      Dim datumPlane1               As DatumPlane
      Dim origin2                   As Point3d
      Dim translation1              As Point3d
      Dim normal2                   As Vector3d
      Dim face1                     As Face
      Dim intersectionCurve1        As Features.IntersectionCurve
      Dim feature1                  As Features.Feature
      Dim interName                 As String

      interName = "S" & counter

      boolIntersection = true

      Dim unit1 As Unit = CType(workPart.UnitCollection.FindObject( "MilliMeter" ), Unit )
      Dim nullFeatures_Feature As Features.Feature = Nothing

      intersectionCurveBuilder1 = workPart.Features.CreateIntersectionCurveBuilder( nullFeatures_Feature )
      section1 = workPart.Sections.CreateSection( 0.0024, 0.0025, 0.5 )

      expression1 = workPart.Expressions.CreateSystemExpressionWithUnits( "0", unit1 )
      section2 = workPart.Sections.CreateSection( 0.0024, 0.0025, 0.5 )
      expression2 = workPart.Expressions.CreateSystemExpressionWithUnits( "0", unit1 )

      origin2 = New Point3d( 0.0, 0.0, 0.0 )
      normal2 = New Vector3d( 0.0, 0.0, 1.0 )
      plane2 = workPart.Planes.CreatePlane( origin2, normal2, SmartObject.UpdateOption.WithinModeling )
      section3 = workPart.Sections.CreateSection( 0.0024, 0.0025, 0.05 )
      expression3 = workPart.Expressions.CreateSystemExpressionWithUnits( "0", unit1 )
      section4 = workPart.Sections.CreateSection( 0.0024, 0.0025, 0.05 )
      expression4 = workPart.Expressions.CreateSystemExpressionWithUnits( "0", unit1 )

      intersectionCurveBuilder1.Tolerance = 0.0025

      section1.DistanceTolerance = 0.0025
      section1.ChainingTolerance = 0.0024
      section2.DistanceTolerance = 0.0025
      section2.ChainingTolerance = 0.0024
      section3.DistanceTolerance = 0.0025
      section3.ChainingTolerance = 0.0024
      section4.DistanceTolerance = 0.0025
      section4.ChainingTolerance = 0.0024

      intersectionCurveBuilder1.Associative = True

      rotMatrix1.Xx = -0.012
      rotMatrix1.Xy = 0.078
      rotMatrix1.Xz = -0.060
      rotMatrix1.Yx = 0.093
      rotMatrix1.Yy = 0.028
      rotMatrix1.Yz = 0.019
      rotMatrix1.Zx = 0.032
      rotMatrix1.Zy = -0.054
      rotMatrix1.Zz = -0.077

      translation1 = New Point3d( 1, -.75, 10 )
      workPart.ModelingViews.WorkView.SetRotationTranslationScale( rotMatrix1, translation1, 0.0191 )

      face1 = CType( splineRevolve.FindObject( "FACE [CURVE 0 0]" ), Face )

      faceTangentRule1 = workPart.ScRuleFactory.CreateRuleFaceTangent( face1, boundaryFaces1 )
      rules1(0) = faceTangentRule1
      intersectionCurveBuilder1.FirstFace.ReplaceRules( rules1, False )
      objects2(0) = face1
      added2 = intersectionCurveBuilder1.FirstSet.Add( objects2 )
      datumPlane1 = rotatedDatum
      plane2.SetMethod( PlaneTypes.MethodType.Distance )

      geom2(0) = datumPlane1
      plane2.SetGeometry( geom2 )
      plane2.SetFlip( False )
      plane2.SetReverseSide( False )

      expression6 = plane2.Expression
      expression6.RightHandSide = "0"

      plane2.SetAlternate( PlaneTypes.AlternateType.One )
      plane2.Evaluate()

      intersectionCurveBuilder1.SecondPlane = plane2
      nXObject1 = intersectionCurveBuilder1.Commit()

      Try
         feature1 = intersectionCurveBuilder1.commitFeature()
      Catch
         MessageBox.Show( "Intersection Line cannot be completed, check value of expression S" & counter & _
            "_sweep cannot exceed 20 degrees. Station will be skipped.", _
            "Error", MessageBoxButtons.OK, MessageBoxIcon.Error )
         boolIntersection = false
      End Try

      intersectionCurve1 = CType( feature1, Features.IntersectionCurve )
      splineSCurve = CType( intersectionCurve1.FindObject( "CURVE 1" ), Spline )

      '------------------------------------------------------------------------------------------
      '   Rename IntersectionCurve S*counter*
      '------------------------------------------------------------------------------------------

      intersectionCurve1.SetName( interName )

      '------------------------------------------------------------------------------------------
      '   Move intersection line to layer 23
      '------------------------------------------------------------------------------------------

      Dim objectArray1(0) As DisplayableObject
      objectArray1(0) = SplineSCurve
      workPart.Layers.MoveDisplayableObjects(23, objectArray1)

      intersectionCurveBuilder1.Destroy()

      section2.Destroy()
      section4.Destroy()

      Dim objects3(0) As NXObject
      objects3(0) = plane1

      section1.Destroy()
      section3.Destroy()

   End Sub

   Public Sub PlacePoint( ByRef counter as Integer, ByRef pointCur as Point, ByRef SplineSCurve As Spline )

      '------------------------------------------------------------------------------------------
      '   Do the work to place the point on the line using counter
      '   Modified a recorded journal to use passed variables
      '------------------------------------------------------------------------------------------

      Dim spline1               As Spline
      Dim point1                As Point
      Dim scalar1               As Scalar
      Dim scalar2               As Scalar
      Dim expression1           As Expression
      Dim expression2           As Expression
      Dim strExp1               As String
      Dim strExp2               As String
      Dim PName                 As String
      Dim nullFeatures_Feature  As Features.Feature
      Dim nullUnit              As Unit
      Dim unit1                 As Unit
      Dim nXObject1             As NXObject
      Dim feature2              As Features.Feature
      Dim pointFeature1         As features.pointfeature
      Dim pointFeatureBuilder1  As Features.PointFeatureBuilder

      strExp1 = "d" & counter & "=0"
      spline1 = SplineSCurve
      nullFeatures_Feature = Nothing
      nullUnit = Nothing
      unit1 = CType(workPart.UnitCollection.FindObject( "MilliMeter" ), Unit)

      expression1 = workPart.Expressions.CreateSystemExpressionWithUnits( strExp1, unit1 )
      scalar2 = workPart.Scalars.CreateScalarExpression( expression1, Scalar.DimensionalityType.None, _
         SmartObject.UpdateOption.WithinModeling )
      point1 = workPart.Points.CreatePoint( spline1, scalar2, SmartObject.UpdateOption.WithinModeling )
      strExp2 = "E" & counter & "_arclen=S" & counter
      expression2 = workPart.Expressions.CreateSystemExpressionWithUnits( strExp2, unit1 )
      scalar1 = workPart.Scalars.CreateScalarExpression( expression2, Scalar.DimensionalityType.None, _
         SmartObject.UpdateOption.WithinModeling )
      pointCur = workPart.Points.CreatePoint( spline1, point1, scalar1, _
         PointCollection.AlongCurveOption.Distance, Sense.Forward, SmartObject.UpdateOption.WithinModeling )

      Try
         ' Expression is still in use.
         workPart.Expressions.Delete( expression1 )
      Catch ex As NXException
         ex.AssertErrorCode( 1050029 )
      End Try

      Try
         ' Expression is still in use.
         workPart.Expressions.Delete( expression2 )
      Catch ex As NXException
         ex.AssertErrorCode( 1050029 )
      End Try

      pointCur.SetVisibility( SmartObject.VisibilityOption.Visible )

      If Not workPart.Preferences.Modeling.GetHistoryMode Then
         Throw( New Exception( "Create or edit of a Feature was recorded in History Mode but playback is in" & _
            " History-Free Mode." ) )
      End If

      pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder( nullFeatures_Feature )
      pointFeatureBuilder1.Point = pointCur
      nXObject1 = pointFeatureBuilder1.Commit( )

      '------------------------------------------------------------------------------------------
      '   Move point to Layer 21
      '------------------------------------------------------------------------------------------

      Dim objectArray1(0) As DisplayableObject
      
      objectArray1(0) = PointCur
      workPart.Layers.MoveDisplayableObjects(21, objectArray1)

      '------------------------------------------------------------------------------------------
      '   Name the point Point_counter
      '   Hand written
      '------------------------------------------------------------------------------------------

      feature2 = pointFeatureBuilder1.commitfeature( )
      pointFeature1 = CType( feature2, Features.pointFeature )
       
      pName = "S" & counter
      pointFeature1.SetName( pName )

      pointFeatureBuilder1.Destroy()
   End Sub

Any help would be appreciated.

RE: Intersection curve

I am not sure that I understand the program fully, however, I can make one point that, if it is relevant, may allow you to add some appropriate code.  The situation is that when you create the surface of revolution the only edge for which you can be certain of its direction is the original spline edge.  The other three edges, if any of these are used in further work need to be checked for their direction.

Hope this helps.

Frank Swinkels

RE: Intersection curve

(OP)
The Splines in the two sets of data are of two different lengths.  The one that works properly is 14m the set that is working backwards is 26 m.

Is there a rule or such that causes the direction to change based on the length of the intersection curve?

RE: Intersection curve

(OP)
Alright, I know where the problem is, I don't know how to fix it.  When the surface is created there is a direction under the "Select Curve" I need the direction to be the same EVERY time, but I don't know what is setting the direction.

I need an if then statement to say when that direction should be changed, but I'm not sure how to determine when the direction should be reversed.  

The Specify Origin Curve is greyed out so cannot be used.

Here is my code for creating the surface.

CODE

   Public Sub RevolveSpline( ByRef SplineSCurve As Spline, ByRef splineRevolve As Features.Revolve )

      Dim curves1(0) As Curve
      Dim nullFeatures_Feature As Features.Feature
      Dim section1 As Section
      Dim revolveBuilder1 As Features.RevolveBuilder
      Dim starthelperpoint1(2) As Double
      Dim endhelperpoint1(2) As Double
      Dim curveDumbRule1 As CurveDumbRule
      Dim rules1(0) As SelectionIntentRule
      Dim nullNXObject As NXObject
      Dim helpPoint1 As Point3d
      Dim direction1 As Direction
      Dim origin1 As Point3d
      Dim vector1 As Vector3d
      Dim nullPoint As Point
      Dim axis1 As Axis
      Dim datumCsys1 As Features.DatumCsys
      Dim point1 As Point
      Dim nullXform As Xform
      Dim point2 As Point
      Dim success1 As Boolean
      Dim feature1 As Features.Feature
      Dim expression1 As Expression
      Dim expression2 As Expression

      '------------------------------------------------------------------------------------------
      '
      '   Rotate the previously created Spline 20 degrees around the Origin
      '
      '------------------------------------------------------------------------------------------

      nullNXObject = Nothing
      section1 = workPart.Sections.CreateSection(0.02413, 0.0254, 0.5)
      nullFeatures_Feature = Nothing

      revolveBuilder1 = workPart.Features.CreateRevolveBuilder(nullFeatures_Feature)
      revolveBuilder1.Limits.StartExtend.Value.RightHandSide = "0"
      revolveBuilder1.Limits.EndExtend.Value.RightHandSide = "20"
      revolveBuilder1.Offset.StartOffset.RightHandSide = "0"
      revolveBuilder1.Offset.EndOffset.RightHandSide = "5"
      revolveBuilder1.Tolerance = 0.0254
      revolveBuilder1.Section = section1

      section1.DistanceTolerance = 0.0254
      section1.ChainingTolerance = 0.0241

      starthelperpoint1(0) = 0.0
      starthelperpoint1(1) = 0.0
      starthelperpoint1(2) = 0.0
      revolveBuilder1.SetStartLimitHelperPoint( starthelperpoint1 )

      endhelperpoint1(0) = 0.0
      endhelperpoint1(1) = 0.0
      endhelperpoint1(2) = 0.0
      revolveBuilder1.SetEndLimitHelperPoint( endhelperpoint1 )

      curves1(0) = splineSCurve
      curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb( curves1 )
      section1.AllowSelfIntersection(False)

      rules1(0) = curveDumbRule1
      helpPoint1 = New Point3d( -129.89677, 0.0, 10369.69960 )
      section1.AddToSection( rules1, splineSCurve, nullNXObject, nullNXObject, helpPoint1, _
         Section.Mode.Create, False )

      origin1 = New Point3d( 0.0, 0.0, 0.0 )
      vector1 = New Vector3d( 1.0, 0.0, 0.0 )

      direction1 = workPart.Directions.CreateDirection( origin1, vector1, _
         SmartObject.UpdateOption.WithinModeling )
      nullPoint = Nothing

      axis1 = workPart.Axes.CreateAxis( nullPoint, direction1, SmartObject.UpdateOption.WithinModeling )
      datumCsys1 = CType(workPart.Features.FindObject( "DATUM_CSYS(0)"), Features.DatumCsys )

      nullXform = Nothing
      point2 = CType( datumCsys1.FindObject("HANDLE R-850"), Point )

      axis1.Point = point2
      success1 = direction1.ReverseDirection()
      axis1.Direction = direction1

      revolveBuilder1.Axis = axis1
      revolveBuilder1.ParentFeatureInternal = False

      feature1 = revolveBuilder1.CommitFeature()
      expression1 = revolveBuilder1.Limits.StartExtend.Value
      expression2 = revolveBuilder1.Limits.EndExtend.Value
      splineRevolve = cType( feature1, Features.Revolve )

      Dim objectArray1(0) As DisplayableObject
      Dim body1 As Body = CType(workPart.Bodies.FindObject("REVOLVED(2)"), Body)

      '------------------------------------------------------------------------------------------
      '   Move the rotated surface to layer 7
      '------------------------------------------------------------------------------------------

      objectArray1(0) = body1
      workPart.Layers.MoveDisplayableObjects(7, objectArray1)

   End Sub

Again I appreciate all help that can be offered.

RE: Intersection curve

The direction of the intersection curve is based on the normal directions of the bodies that intersect.

Do you want the start point to be at (or near) the origin? If so, you can check the start/end points and if the start point is not what you want, you can change your code to reverse the direction

some psuedocode:

CODE

if startPoint near origin then
  newPoint = createNewPointAlongCurve(..., Sense.Forward, ...)
else
  newPoint = createNewPointAlongCurve(..., Sense.Reverse, ...)
end if

Here is some example code from GTAC that demonstrates how to determine the start/end points of a curve.

CODE

'Date:  08/09/2010
'Subject:  Sample NX Open .NET Visual Basic program : get curve start and end point coordinates
'
'Note:  GTAC provides programming examples for illustration only, and
'assumes that you are familiar with the programming language being
'demonstrated and the tools used to create and debug procedures.  GTAC
'support professionals can help explain the functionality of a particular
'procedure, but we will not modify these examples to provide added
'functionality or construct procedures to meet your specific needs.

Option Strict Off  
Imports System  
Imports NXOpen  
Imports NXOpen.UF  

Module NXJournal  

  Sub Main  

    Dim theSession As Session = Session.GetSession()  
    Dim ufs As UFSession = UFSession.GetUFSession()  
    Dim lw As ListingWindow = theSession.ListingWindow  
    Dim evaluator As IntPtr = nothing  
    Dim limits(1) As Double  
    Dim spt(2) As Double  
    Dim ept(2) As Double  
    Dim junk(2) As Double  
    Dim curve As NXObject = select_a_curve("Get Start/End Points")  

    Do While curve isnot nothing  
      ufs.Eval.Initialize(curve.Tag, evaluator)  
      ufs.Eval.AskLimits(evaluator, limits)  
      ufs.Eval.Evaluate(evaluator, 0, limits(0), spt, junk)  
      ufs.Eval.Evaluate(evaluator, 0, limits(1), ept, junk)  
      ufs.Eval.Free(evaluator)  

      lw.Open()  
      lw.WriteLine("start: " & spt(0) & ", " & spt(1) & ", " & spt(2))  
      lw.WriteLine("end  : " & ept(0) & ", " & ept(1) & ", " & ept(2))  

      curve = select_a_curve("Get Start/End Points")  
    Loop  

  End Sub  

  Function select_a_curve(prompt As String) As NXObject  

    Dim ui As UI = ui.GetUI()  
    Dim curveType() As Selection.SelectionType = _  
        { Selection.SelectionType.Curves }  
    Dim cursor As Point3d = Nothing  

    Dim resp As Selection.Response = _  
        ui.SelectionManager.SelectObject("Select a curve", prompt, _  
            Selection.SelectionScope.AnyInAssembly, False, _  
            curveType, select_a_curve, cursor)  

  End Function  

End Module  
 

www.nxjournaling.com

RE: Intersection curve

(OP)
I have been trying to apply your advice Cowski, but I can't find the element to test for the start point.  The initial spline ALWAYS has a start point at the origin, and yet when creating the solid revolve the start point is occasionally away from the origin and thus needs to be reversed.

I know how to get the start point of any spline, but neither the direction1 callout nor the section1 nor the revolvebuilder, none of these elements seem to have a way or a callout I can test to see if the direction is beginning at the origin.

Am I missing something?

RE: Intersection curve

My previous response was in regard to checking the direction of the intersection curve. Given your latest post, I think I have a better idea of what is happening. In many interactive functions the direction of the curve is implied by where you select the curve. If you select nearer one end, that end is used as the "start". Your variable helpPoint1 is acting as the cursor pick location of an interactive session. What you have seems to work for most of your input curves, but when they hit a certain length, the inferred pick point now lies on the other side of the mid point causing the other end of the curve to be assigned the "start". I assume the following line of code is the result of a recorded journal:

CODE

helpPoint1 = New Point3d( -129.89677, 0.0, 10369.69960 )
Try setting the helpPoint1 coordinates to the start point of your curve and see if you get consistent results no matter the spline length.

www.nxjournaling.com

RE: Intersection curve

(OP)
That was it!!  

So simple, thanks very much!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources