Project Curve : Update undo happened.

I am attempting to project a series of curves onto a sheet body. I grabbed a code sample on GTAC that matched close to something the journal recorder gave me, and the code kind of works.

For some reason, all of my projected curves appear as if they get projected correctly, and then offset from the part surface back towards the original geometry.

I also need to project along a line. I have tried using project along a vector in the code(see the commented out lines), but then I get an update undo happens and no curve.

Here is the link for the gtac code:
https://solutions.industrysoftware.automation.siemens.com/view.php?sort=...

: Function ProjectCurves(ByRef toProj() As Curve, ByRef projOnto() As Face, ByVal crvLine As Line) As Curve()

Dim markId1 As Session.UndoMarkId
markId1 = nxSes.SetUndoMark(Session.MarkVisibility.Visible, "Project Curve")

Dim nullFeatures_Feature As Features.Feature = Nothing

Dim projectCurveBuilder1 As Features.ProjectCurveBuilder
projectCurveBuilder1 = wrkPrt.Features.CreateProjectCurveBuilder(nullFeatures_Feature)

projectCurveBuilder1.BridgedGapSize = 0.0393700787401575

projectCurveBuilder1.Tolerance = 0.001

'projectCurveBuilder1.ProjectionDirectionMethod = Features.ProjectCurveBuilder.DirectionType.AlongVector

projectCurveBuilder1.AngleToProjectionVector.RightHandSide = "0"

'Dim direction1 As Direction
'direction1 = wrkPrt.Directions.CreateDirection(crvLine, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
'projectCurveBuilder1.ProjectionVector = direction1
'projectCurveBuilder1.ProjectionOption = Features.ProjectCurveBuilder.ProjectionOptionType.ProjectBothSides

projectCurveBuilder1.BridgedGapSize = 0.0393700787401575

projectCurveBuilder1.SectionToProject.DistanceTolerance = 0.001

projectCurveBuilder1.SectionToProject.ChainingTolerance = 0.00095

projectCurveBuilder1.SectionToProject.SetAllowedEntityTypes(Section.AllowTypes.CurvesAndPoints)

Dim curveDumbRule1 As CurveDumbRule
curveDumbRule1 = wrkPrt.ScRuleFactory.CreateRuleCurveDumb(toProj)

projectCurveBuilder1.SectionToProject.AllowSelfIntersection(True)

Dim rules1(0) As SelectionIntentRule
rules1(0) = curveDumbRule1
Dim nullNXObject As NXObject = Nothing

Dim helpPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
projectCurveBuilder1.SectionToProject.AddToSection(rules1, nullNXObject, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)

Dim scCollector1 As ScCollector
scCollector1 = wrkPrt.ScCollectors.CreateCollector()

Dim faceDumbRule1 As FaceDumbRule
faceDumbRule1 = wrkPrt.ScRuleFactory.CreateRuleFaceDumb(projOnto)

Dim rules2(0) As SelectionIntentRule
rules2(0) = faceDumbRule1
scCollector1.ReplaceRules(rules2, False)

Dim added1 As Boolean
added1 = projectCurveBuilder1.FaceToProjectTo.Add(scCollector1)

Dim nXObject1 As Features.ProjectCurve
nXObject1 = projectCurveBuilder1.Commit()

projectCurveBuilder1.Destroy()

Dim curveList As ArrayList = New ArrayList
For Each aCurve As NXObject In nXObject1.GetEntities()
curveList.Add(aCurve)
Next

Return curveList.ToArray(GetType(Curve))

End Function
<\vbnet>

I started with the GTAC code and added your code back in. In my (very limited) testing, the code below works with no errors.

You'll probably want a more robust method of picking/defining the projection vector, I was just reusing the selection code that was available.

I'm running NX 9, what version are you using?

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

Module NXJournal

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

Sub Main()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim whatCurves() As Curve = SelectCurves("Curves to Project")
If whatCurves.Length = 0 Then Exit sub

Dim whatFaces() As Face = SelectFaces("Faces to Project onto")
If whatFaces.Length = 0 Then Exit sub

dim dirCrv() as Curve = SelectCurves("Direction Line")
if dirCrv.Length <> 1 then Exit Sub
dim dirLine as line = dirCrv(0)

Dim curves() As Curve = ProjectCurves(whatCurves, whatFaces, dirLine)
lw.WriteLine(curves.Length)

End Sub

Function ProjectCurves(ByRef toProj() As Curve, ByRef projOnto() As Face, byval directionCurve as Line) As Curve()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Project Curve")

Dim nullFeatures_Feature As Features.Feature = Nothing

Dim projectCurveBuilder1 As Features.ProjectCurveBuilder
projectCurveBuilder1 = wp.Features.CreateProjectCurveBuilder(nullFeatures_Feature)

projectCurveBuilder1.ProjectionDirectionMethod = Features.ProjectCurveBuilder.DirectionType.AlongVector

Dim direction1 As Direction
direction1 = wp.Directions.CreateDirection(directionCurve, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
projectCurveBuilder1.ProjectionVector = direction1
projectCurveBuilder1.ProjectionOption = Features.ProjectCurveBuilder.ProjectionOptionType.ProjectBothSides

projectCurveBuilder1.BridgedGapSize = 0.0393700787401575

projectCurveBuilder1.Tolerance = 0.001

projectCurveBuilder1.AngleToProjectionVector.RightHandSide = "0"

projectCurveBuilder1.BridgedGapSize = 0.0393700787401575

projectCurveBuilder1.SectionToProject.DistanceTolerance = 0.001

projectCurveBuilder1.SectionToProject.ChainingTolerance = 0.00095

projectCurveBuilder1.SectionToProject.SetAllowedEntityTypes(Section.AllowTypes.CurvesAndPoints)

Dim curveDumbRule1 As CurveDumbRule
curveDumbRule1 = wp.ScRuleFactory.CreateRuleCurveDumb(toProj)

projectCurveBuilder1.SectionToProject.AllowSelfIntersection(True)

Dim rules1(0) As SelectionIntentRule
rules1(0) = curveDumbRule1
Dim nullNXObject As NXObject = Nothing

Dim helpPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
projectCurveBuilder1.SectionToProject.AddToSection(rules1, nullNXObject, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)

Dim scCollector1 As ScCollector
scCollector1 = wp.ScCollectors.CreateCollector()

Dim faceDumbRule1 As FaceDumbRule
faceDumbRule1 = wp.ScRuleFactory.CreateRuleFaceDumb(projOnto)

Dim rules2(0) As SelectionIntentRule
rules2(0) = faceDumbRule1
scCollector1.ReplaceRules(rules2, False)

Dim added1 As Boolean
added1 = projectCurveBuilder1.FaceToProjectTo.Add(scCollector1)

Dim nXObject1 As Features.ProjectCurve
nXObject1 = projectCurveBuilder1.Commit()

projectCurveBuilder1.Destroy()

Dim curveList As ArrayList = New ArrayList
For Each aCurve As NXObject In nXObject1.GetEntities()
curveList.Add(aCurve)
Next

Return curveList.ToArray(GetType(Curve))

End Function

Function SelectCurves(ByRef prompt As String) As Curve()
Dim selectionMask(3) As Selection.MaskTriple
With selectionMask(0)
.Type = UFConstants.UF_line_type
.Subtype = 0
.SolidBodySubtype = 0
End With
With selectionMask(1)
.Type = UFConstants.UF_circle_type
.Subtype = 0
.SolidBodySubtype = 0
End With
With selectionMask(2)
.Type = UFConstants.UF_conic_type
.Subtype = 0
.SolidBodySubtype = 0
End With
With selectionMask(3)
.Type = UFConstants.UF_spline_type
.Subtype = 0
.SolidBodySubtype = 0
End With

Dim selected() As NXObject = Nothing

NXOpen.UI.GetUI.SelectionManager.SelectObjects("Select Curves", prompt, Selection.SelectionScope.WorkPart, _
Selection.SelectionAction.ClearAndEnableSpecific, False, False, selectionMask, selected)

Dim curveList As ArrayList = New ArrayList
For Each aCurve As NXObject In selected
curveList.Add(aCurve)
Next

Return curveList.ToArray(GetType(Curve))

End Function

Function SelectFaces(ByRef prompt As String) As Face()
Dim selectionMask(0) As Selection.MaskTriple
With selectionMask(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
End With
Dim selected() As NXObject = Nothing

NXOpen.UI.GetUI.SelectionManager.SelectObjects("Select Faces", prompt, Selection.SelectionScope.WorkPart, _
Selection.SelectionAction.ClearAndEnableSpecific, False, False, selectionMask, selected)

Dim faceList As ArrayList = New ArrayList
For Each aFace As NXObject In selected
faceList.Add(aFace)
Next

Return faceList.ToArray(GetType(Face))

End Function

End Module

I'm running nx9.0. Here is the issue I am getting. The final curve is offset into towards the original geometry.

I'm using the circle on top for the curves to project, the faces below it for the projection surface, and the line for the vector.

https://drive.google.com/open?id=0B7BueUXr0wMrV2lJd2NVOXEwZVU

DHuskic
Nx 9 VB

Do you get the correct result when using the interactive NX command?

Yes. I recorded a journal doing such, it gives me the desired output. I don't see any differences in property settings inside of the project function.

' NX 9.0.3.4
' Journal created by dhuskic on Thu Aug 18 17:22:02 2016 Eastern Daylight Time
'
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main(ByVal args() As String)

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

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Insert->Derived Curve->Project...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

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 projectCurveBuilder1 As Features.ProjectCurveBuilder
projectCurveBuilder1 = workPart.Features.CreateProjectCurveBuilder(nullFeatures_Feature)

Dim origin1 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim normal1 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
Dim plane1 As Plane
plane1 = workPart.Planes.CreatePlane(origin1, normal1, SmartObject.UpdateOption.WithinModeling)

Dim unit1 As Unit = CType(workPart.UnitCollection.FindObject("Inch"), Unit)

Dim expression1 As Expression
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression2 As Expression
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

projectCurveBuilder1.CurveFitData.Tolerance = 0.0001

projectCurveBuilder1.CurveFitData.AngleTolerance = 0.125

projectCurveBuilder1.BridgedGapSize = 0.0393700787401575

projectCurveBuilder1.ProjectionDirectionMethod = Features.ProjectCurveBuilder.DirectionType.AlongVector

projectCurveBuilder1.AngleToProjectionVector.RightHandSide = "0"

projectCurveBuilder1.BridgedGapSize = 0.0393700787401575

projectCurveBuilder1.InputCurvesOption.Associative = False

projectCurveBuilder1.InputCurvesOption.InputCurveOption = GeometricUtilities.CurveOptions.InputCurve.Replace

theSession.SetUndoMarkName(markId1, "Project Curve Dialog")

plane1.SetMethod(PlaneTypes.MethodType.FixedZ)

Dim geom1(-1) As NXObject
plane1.SetGeometry(geom1)

Dim origin2 As Point3d = New Point3d(0.0, 0.0, 0.0)
plane1.Origin = origin2

Dim matrix1 As Matrix3x3
matrix1.Xx = 1.0
matrix1.Xy = -0.0
matrix1.Xz = 0.0
matrix1.Yx = 0.0
matrix1.Yy = 0.707106781186548
matrix1.Yz = -0.707106781186547
matrix1.Zx = 0.0
matrix1.Zy = 0.707106781186547
matrix1.Zz = 0.707106781186548
plane1.Matrix = matrix1

plane1.SetAlternate(PlaneTypes.AlternateType.One)

plane1.Evaluate()

plane1.SetMethod(PlaneTypes.MethodType.FixedZ)

projectCurveBuilder1.SectionToProject.DistanceTolerance = 0.0001

projectCurveBuilder1.SectionToProject.ChainingTolerance = 0.000095

projectCurveBuilder1.SectionToProject.AngleTolerance = 0.125

projectCurveBuilder1.PlaneToProjectTo = plane1

projectCurveBuilder1.SectionToProject.SetAllowedEntityTypes(Section.AllowTypes.CurvesAndPoints)

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "section mark")

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, Nothing)

Dim curves1(0) As IBaseCurve
Dim arc1 As Arc = CType(workPart.Arcs.FindObject("ENTITY 5 8 1"), Arc)

curves1(0) = arc1
Dim curveDumbRule1 As CurveDumbRule
curveDumbRule1 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves1)

projectCurveBuilder1.SectionToProject.AllowSelfIntersection(True)

Dim rules1(0) As SelectionIntentRule
rules1(0) = curveDumbRule1
Dim nullNXObject As NXObject = Nothing

Dim helpPoint1 As Point3d = New Point3d(7.19814884385955, -19.6529877084094, 5.5)
projectCurveBuilder1.SectionToProject.AddToSection(rules1, arc1, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)

theSession.DeleteUndoMark(markId3, Nothing)

theSession.DeleteUndoMark(markId2, Nothing)

Dim extractFaceBuilder1 As Features.ExtractFaceBuilder
extractFaceBuilder1 = workPart.Features.CreateExtractFaceBuilder(nullFeatures_Feature)

extractFaceBuilder1.Type = Features.ExtractFaceBuilder.ExtractType.Face

extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain

extractFaceBuilder1.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart

extractFaceBuilder1.Associative = True

Dim scCollector1 As ScCollector
scCollector1 = extractFaceBuilder1.FaceChain

Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT 10003__MOLDBASE 1"), Assemblies.Component)

Dim component2 As Assemblies.Component = CType(component1.FindObject("COMPONENT 10003__COVER_ASSEMBLY 1"), Assemblies.Component)

Dim component3 As Assemblies.Component = CType(component2.FindObject("COMPONENT 10003__Cover_Steel 1"), Assemblies.Component)

Dim face1 As Face = CType(component3.FindObject("PROTO#.Features|LINKED_BODY(118)|FACE 486 {(0.0042189831323,-18.1262349882287,1.7499721332504) LINKED_BODY(118)}"), Face)

Dim boundaryFaces1(-1) As Face
Dim faceTangentRule1 As FaceTangentRule
faceTangentRule1 = workPart.ScRuleFactory.CreateRuleFaceTangent(face1, boundaryFaces1, 0.125)

Dim rules2(0) As SelectionIntentRule
rules2(0) = faceTangentRule1
scCollector1.ReplaceRules(rules2, False)

extractFaceBuilder1.FixAtCurrentTimestamp = True

Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, Nothing)

Dim feature1 As Features.Feature
feature1 = extractFaceBuilder1.CommitCreateOnTheFly()

theSession.DeleteUndoMark(markId4, Nothing)

Dim waveLinkRepository1 As GeometricUtilities.WaveLinkRepository
waveLinkRepository1 = workPart.CreateWavelinkRepository()

waveLinkRepository1.SetNonFeatureApplication(False)

waveLinkRepository1.SetBuilder(projectCurveBuilder1)

Dim extractFace1 As Features.ExtractFace = CType(feature1, Features.ExtractFace)

waveLinkRepository1.SetLink(extractFace1)

Dim extractFaceBuilder2 As Features.ExtractFaceBuilder
extractFaceBuilder2 = workPart.Features.CreateExtractFaceBuilder(extractFace1)

extractFaceBuilder2.Associative = False

Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, Nothing)

Dim feature2 As Features.Feature
feature2 = extractFaceBuilder2.CommitCreateOnTheFly()

extractFaceBuilder2.Destroy()

theSession.DeleteUndoMark(markId5, Nothing)

extractFaceBuilder1.Destroy()

Dim scCollector2 As ScCollector
scCollector2 = workPart.ScCollectors.CreateCollector()

Dim features1(0) As Features.Feature
Dim extractFace2 As Features.ExtractFace = CType(feature2, Features.ExtractFace)

features1(0) = extractFace2
Dim faceFeatureRule1 As FaceFeatureRule
faceFeatureRule1 = workPart.ScRuleFactory.CreateRuleFaceFeature(features1)

Dim rules3(0) As SelectionIntentRule
rules3(0) = faceFeatureRule1
scCollector2.ReplaceRules(rules3, False)

Dim added1 As Boolean
added1 = projectCurveBuilder1.FaceToProjectTo.Add(scCollector2)

Dim line1 As Line = CType(workPart.Lines.FindObject("ENTITY 3 8 1"), Line)

Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(line1, Sense.Forward, SmartObject.UpdateOption.WithinModeling)

projectCurveBuilder1.ProjectionVector = direction1

Dim markId6 As Session.UndoMarkId
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Project Curve")

theSession.DeleteUndoMark(markId6, Nothing)

Dim markId7 As Session.UndoMarkId
markId7 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Project Curve")

Dim nXObject1 As NXObject
nXObject1 = projectCurveBuilder1.Commit()

Dim objects1() As NXObject
objects1 = projectCurveBuilder1.GetCommittedObjects()

theSession.DeleteUndoMark(markId7, Nothing)

theSession.SetUndoMarkName(markId1, "Project Curve")

projectCurveBuilder1.Destroy()

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(expression1)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

plane1.DestroyPlane()

waveLinkRepository1.Destroy()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module<\vbnet>

DHuskic
Nx 9 VB

If you re-run the journal that you recorded (on the same part), do you get the correct results?

If you do not get the correct results when you re-run the journal on the same part used to record the journal, then it needs to be reported to GTAC (it has happened to me once or twice before).

The journal rerun seems to work correctly and consistently. I used your copy of the projectcurves function and it was working well this morning, I changed some code after I called that function, and it stopped working at some point.

I keep getting an error now, and I've verified that all of these faces are added to the builder correctly, the add boolean returns true as well. So everything was working fine at one point, and now it all just keeps breaking and I am getting no projections.

NXOpen.NXException: No faces or planes to project to.
at NXOpen.Builder.Commit()

DHuskic
Nx 9 VB

If possible, please email me the part file (or just the relevant portion of it) and your code. I'd be glad to take a look. If you can email the code, change the extension of the file to ".txt". My email provider won't let ".vb" or ".cs" files through.

info@nxjournaling.com

There are a few GTAC problem reports regarding the project curve builder. None of them exactly match my current problem, but I might try going through them.

DHuskic
Nx 9 VB

My apologies, I was typing that before I got the notification of your response. I'll get some parts and code over to you.

DHuskic
Nx 9 VB