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.
Any help would be appreciated.
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.