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!

Intersection curve 1

Status
Not open for further replies.

Twullf

Mechanical
Jan 24, 2012
196
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.
 
Replies continue below

Recommended for you

I really need help with this. with one set of data the point counting area starts at the origin and with the other it starts at the opposite end of the spline/intersection curve.

It is the same code. I am not sure why this is happening.
 
 http://files.engineering.com/getfile.aspx?folder=7a1f9f20-dbc0-4c17-937d-97eb6de27f2a&file=Expressions_Good.exp
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
 
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?
 
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.
 
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:
[COLOR=green]'Date:  08/09/2010[/color]
[COLOR=green]'Subject:  Sample NX Open .NET Visual Basic program : get curve start and end point coordinates[/color]
[COLOR=green]'[/color]
[COLOR=green]'Note:  GTAC provides programming examples for illustration only, and[/color]
[COLOR=green]'assumes that you are familiar with the programming language being[/color]
[COLOR=green]'demonstrated and the tools used to create and debug procedures.  GTAC[/color]
[COLOR=green]'support professionals can help explain the functionality of a particular[/color]
[COLOR=green]'procedure, but we will not modify these examples to provide added[/color]
[COLOR=green]'functionality or construct procedures to meet your specific needs.[/color]

[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpen.UF  

[COLOR=blue]Module[/color] NXJournal  

  [COLOR=blue]Sub[/color] Main  

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

    [COLOR=blue]Do[/color] [COLOR=blue]While[/color] curve [COLOR=blue]isnot[/color] [COLOR=blue]nothing[/color]  
      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: " [COLOR=blue]&[/color] spt(0) [COLOR=blue]&[/color] ", " [COLOR=blue]&[/color] spt(1) [COLOR=blue]&[/color] ", " [COLOR=blue]&[/color] spt(2))  
      lw.WriteLine("end  : " [COLOR=blue]&[/color] ept(0) [COLOR=blue]&[/color] ", " [COLOR=blue]&[/color] ept(1) [COLOR=blue]&[/color] ", " [COLOR=blue]&[/color] ept(2))  

      curve [COLOR=blue]=[/color] select_a_curve("Get Start/End Points")  
    [COLOR=blue]Loop[/color]  

  End [COLOR=blue]Sub[/color]  

  [COLOR=blue]Function[/color] select_a_curve(prompt [COLOR=blue]As[/color] [COLOR=blue]String[/color]) [COLOR=blue]As[/color] NXObject  

    [COLOR=blue]Dim[/color] ui [COLOR=blue]As[/color] UI [COLOR=blue]=[/color] ui.GetUI()  
    [COLOR=blue]Dim[/color] curveType() [COLOR=blue]As[/color] Selection.SelectionType [COLOR=blue]=[/color] _  
        { Selection.SelectionType.Curves }  
    [COLOR=blue]Dim[/color] cursor [COLOR=blue]As[/color] Point3d [COLOR=blue]=[/color] [COLOR=blue]Nothing[/color]  

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

  End [COLOR=blue]Function[/color]  

End [COLOR=blue]Module[/color]


 
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?
 
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.

 
That was it!!

So simple, thanks very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor