Twullf
Mechanical
- Jan 24, 2012
- 196
I have tried journaling this, but the result is so convoluted and long, I can't figure what is needed and what is not. Is there a nice clean way to place a point on a curve in a 3D environment when setting the distance of the point by an expression value?
The journal looks as follows, after the little cleaning I felt was safe to do:
Any help is greatly appreciated.
The journal looks as follows, after the little cleaning I felt was safe to do:
Code:
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Insert->Datum/Point->Point...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim unit1 As Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), Unit)
Dim expression1 As Expression
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("p0_x=0.00000000000", unit1)
Dim expression2 As Expression
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("p1_y=0.00000000000", unit1)
Dim expression3 As Expression
expression3 = workPart.Expressions.CreateSystemExpressionWithUnits("p2_z=0.00000000000", unit1)
Dim expression4 As Expression
expression4 = workPart.Expressions.CreateSystemExpressionWithUnits("p3_xdelta=0.00000000000", unit1)
Dim expression5 As Expression
expression5 = workPart.Expressions.CreateSystemExpressionWithUnits("p4_ydelta=0.00000000000", unit1)
Dim expression6 As Expression
expression6 = workPart.Expressions.CreateSystemExpressionWithUnits("p5_zdelta=0.00000000000", unit1)
Dim expression7 As Expression
expression7 = workPart.Expressions.CreateSystemExpressionWithUnits("p6_radius=0.00000000000", unit1)
Dim unit2 As Unit = CType(workPart.UnitCollection.FindObject("Degrees"), Unit)
Dim expression8 As Expression
expression8 = workPart.Expressions.CreateSystemExpressionWithUnits("p7_angle=0.00000000000", unit2)
Dim expression9 As Expression
expression9 = workPart.Expressions.CreateSystemExpressionWithUnits("p8_zdelta=0.00000000000", unit1)
Dim expression10 As Expression
expression10 = workPart.Expressions.CreateSystemExpressionWithUnits("p9_radius=0.00000000000", unit1)
Dim expression11 As Expression
expression11 = workPart.Expressions.CreateSystemExpressionWithUnits("p10_angle1=0.00000000000", unit2)
Dim expression12 As Expression
expression12 = workPart.Expressions.CreateSystemExpressionWithUnits("p11_angle2=0.00000000000", unit2)
Dim expression13 As Expression
expression13 = workPart.Expressions.CreateSystemExpressionWithUnits("p12_distance=0", unit1)
Dim expression14 As Expression
expression14 = workPart.Expressions.CreateSystemExpressionWithUnits("p13_arclen=0", unit1)
Dim nullUnit As Unit = Nothing
Dim expression15 As Expression
expression15 = workPart.Expressions.CreateSystemExpressionWithUnits("p14_percent=0", nullUnit)
expression4.RightHandSide = "0"
expression5.RightHandSide = "0"
expression6.RightHandSide = "0"
expression7.RightHandSide = "0"
expression8.RightHandSide = "0"
expression9.RightHandSide = "0"
expression10.RightHandSide = "0"
expression11.RightHandSide = "0"
expression12.RightHandSide = "0"
expression13.RightHandSide = "0"
expression15.RightHandSide = "100"
theSession.SetUndoMarkName(markId1, "Point Dialog")
Dim expression16 As Expression
expression16 = workPart.Expressions.CreateSystemExpressionWithUnits("p15_x=0.00000000000", unit1)
Dim scalar1 As Scalar
scalar1 = workPart.Scalars.CreateScalarExpression(expression16, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
Dim expression17 As Expression
expression17 = workPart.Expressions.CreateSystemExpressionWithUnits("p16_y=0.00000000000", unit1)
Dim scalar2 As Scalar
scalar2 = workPart.Scalars.CreateScalarExpression(expression17, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
Dim expression18 As Expression
expression18 = workPart.Expressions.CreateSystemExpressionWithUnits("p17_z=0.00000000000", unit1)
Dim scalar3 As Scalar
scalar3 = workPart.Scalars.CreateScalarExpression(expression18, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
Dim point1 As Point
point1 = workPart.Points.CreatePoint(scalar1, scalar2, scalar3, SmartObject.UpdateOption.WithinModeling)
workPart.Points.DeletePoint(point1)
Dim expression19 As Expression
expression19 = workPart.Expressions.CreateSystemExpressionWithUnits("p0=0.11", nullUnit)
Dim scalar4 As Scalar
scalar4 = workPart.Scalars.CreateScalarExpression(expression19, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
Dim spline1 As Spline = CType(workPart.Splines.FindObject("ENTITY 9 1 1"), Spline)
Dim point2 As Point
point2 = workPart.Points.CreatePoint(spline1, scalar4, SmartObject.UpdateOption.WithinModeling)
Dim expression20 As Expression
expression20 = workPart.Expressions.CreateSystemExpressionWithUnits("p1=0", nullUnit)
workPart.Points.DeletePoint(point2)
Dim scalar5 As Scalar
scalar5 = workPart.Scalars.CreateScalarExpression(expression20, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
Dim point3 As Point
point3 = workPart.Points.CreatePoint(spline1, scalar5, SmartObject.UpdateOption.WithinModeling)
Dim expression21 As Expression
expression21 = workPart.Expressions.CreateSystemExpressionWithUnits("p2_arclen=26535.86391015533", unit1)
Dim scalar6 As Scalar
scalar6 = workPart.Scalars.CreateScalarExpression(expression21, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
Dim point4 As Point
point4 = workPart.Points.CreatePoint(spline1, point3, scalar6, PointCollection.AlongCurveOption.Distance, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
expression1.RightHandSide = "0"
expression2.RightHandSide = "0"
expression3.RightHandSide = "0"
expression14.RightHandSide = "S3"
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(point4)
Dim expression22 As Expression
expression22 = workPart.Expressions.CreateSystemExpressionWithUnits("p3_arclen=S3", unit1)
Dim scalar7 As Scalar
scalar7 = workPart.Scalars.CreateScalarExpression(expression22, Scalar.DimensionalityType.None, SmartObject.UpdateOption.WithinModeling)
Dim point5 As Point
point5 = workPart.Points.CreatePoint(spline1, point3, scalar7, PointCollection.AlongCurveOption.Distance, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Point")
theSession.DeleteUndoMark(markId2, Nothing)
theSession.SetUndoMarkName(markId1, "Point")
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
Try
' Expression is still in use.
workPart.Expressions.Delete(expression3)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression4)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression5)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression6)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression7)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression8)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression9)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression10)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression11)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression12)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression13)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression14)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Try
' Expression is still in use.
workPart.Expressions.Delete(expression15)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
point5.SetVisibility(SmartObject.VisibilityOption.Visible)
Dim nullFeatures_Feature As Features.Feature = Nothing
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
Dim pointFeatureBuilder1 As Features.PointFeatureBuilder
pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)
pointFeatureBuilder1.Point = point5
Dim nXObject1 As NXObject
nXObject1 = pointFeatureBuilder1.Commit()
pointFeatureBuilder1.Destroy()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
Any help is greatly appreciated.