I'm trying to create two mirror-image splines by rotating and then mirroring a law curve, but I don't know how to specify which spline I want the geomcopyBuilder to use. For the rotation, I managed to identify the spline to use by copying a FindObject line from a recorded journal, but this relies on the default naming convention and didn't work for the mirror feature. Is there a way to denote a spline belonging to a given feature?
Here's a sample of the code I have so far, with comment lines at the two places where I tried to convert features to curves:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim nullUnit As Unit = Nothing
Dim nullFeatures_LawCurve As Features.LawCurve = Nothing
Dim lawCurveBuilderA As Features.LawCurveBuilder
lawCurveBuilderA = workPart.Features.CreateLawCurveBuilder(nullFeatures_LawCurve)
Dim parameter As Expression
parameter = workPart.Expressions.CreateWithUnits("t=0", nullUnit)
Dim xt As Expression
xt = workPart.Expressions.CreateWithUnits("xt=4*t^2", nullUnit)
Dim yt As Expression
yt = workPart.Expressions.CreateWithUnits("yt=t", nullUnit)
Dim zt As Expression
zt = workPart.Expressions.CreateWithUnits("zt=2", nullUnit)
Dim unit1 As Unit
unit1 = lawCurveBuilderA.ZLaw.Value.Units
lawCurveBuilderA.XLaw.AlongSpineData.Spine.DistanceTolerance = 0.001
lawCurveBuilderA.XLaw.AlongSpineData.Spine.ChainingTolerance = 0.00095
lawCurveBuilderA.XLaw.LawCurve.DistanceTolerance = 0.001
lawCurveBuilderA.XLaw.LawCurve.ChainingTolerance = 0.00095
lawCurveBuilderA.YLaw.AlongSpineData.Spine.DistanceTolerance = 0.001
lawCurveBuilderA.YLaw.AlongSpineData.Spine.ChainingTolerance = 0.00095
lawCurveBuilderA.YLaw.LawCurve.DistanceTolerance = 0.001
lawCurveBuilderA.YLaw.LawCurve.ChainingTolerance = 0.00095
lawCurveBuilderA.ZLaw.AlongSpineData.Spine.DistanceTolerance = 0.001
lawCurveBuilderA.ZLaw.AlongSpineData.Spine.ChainingTolerance = 0.00095
lawCurveBuilderA.ZLaw.LawCurve.DistanceTolerance = 0.001
lawCurveBuilderA.ZLaw.LawCurve.ChainingTolerance = 0.00095
Dim baseCurve As NXObject
baseCurve = lawCurveBuilderA.Commit
Dim geomcopyBuilderA As Features.GeomcopyBuilder
Dim nullFeatures_FeatureA As Features.Feature = Nothing
geomcopyBuilderA = workPart.Features.CreateGeomcopyBuilder(nullFeatures_FeatureA)
geomcopyBuilderA.Type = Features.GeomcopyBuilder.TransformTypes.Rotation
geomcopyBuilderA.Associative = False
Dim curvesA(0) As IBaseCurve
Dim splineA As Spline
'***************
splineA = CType(baseCurve.FindObject("CURVE 1"), Spline)
curvesA(0) = splineA
Dim curveDumbRuleA As CurveDumbRule
curveDumbRuleA = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curvesA)
Dim rulesA(0) As SelectionIntentRule
rulesA(0) = curveDumbRuleA
Dim scCollectorA As ScCollector
scCollectorA = workPart.ScCollectors.CreateCollector()
scCollectorA.ReplaceRules(rulesA, False)
Dim addedA As Boolean
addedA = geomcopyBuilderA.GeometryToInstance.Add(scCollectorA)
Dim datumAxisA As DatumAxis = CType(workPart.Datums.FindObject("DATUM_CSYS(0) Z axis"), DatumAxis)
Dim directionA As Direction
directionA = workPart.Directions.CreateDirection(datumAxisA, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
Dim nullPointA As Point = Nothing
Dim axisA As Axis
axisA = workPart.Axes.CreateAxis(nullPointA, directionA, SmartObject.UpdateOption.WithinModeling)
geomcopyBuilderA.RotationAxis = axisA
axisA.Point = nullPointA
axisA.Evaluate()
geomcopyBuilderA.RotateAngle.RightHandSide = "45"
Dim featureA As Features.Feature
featureA = geomcopyBuilderA.CommitFeature()
Dim markIdA As Session.UndoMarkId
markIdA = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
Dim deleteObj As NXObject
deleteObj = baseCurve
Dim nErrsA As Integer
nErrsA = theSession.UpdateManager.AddToDeleteList(deleteObj)
theSession.UpdateManager.DoUpdate(markIdA)
Dim planeAngle As Double
planeAngle = 2
Dim pt1 As New Point3d(0,0,0)
Dim pt2 As New Point3d(Math.cos(planeAngle), Math.sin(planeAngle), 0)
Dim planeLine As Line
planeLine = workPart.Curves.CreateLine(pt1,pt2)
Dim datumPlaneBuilder1 As Features.DatumPlaneBuilder
datumPlaneBuilder1 = workPart.Features.CreateDatumPlaneBuilder(nullFeatures_FeatureA)
Dim planeM As Plane
planeM = datumPlaneBuilder1.GetPlane()
planeM.SetUpdateOption(SmartObject.UpdateOption.WithinModeling)
planeM.SetMethod(PlaneTypes.MethodType.TwoLines)
Dim geom1(1) As NXObject
geom1(0) = planeLine
geom1(1) = datumAxisA
planeM.SetGeometry(geom1)
planeM.SetAlternate(PlaneTypes.AlternateType.One)
planeM.Evaluate()
Dim numSolutions1 As Integer
numSolutions1 = planeM.GetNumberOfAlternate()
planeM.SetAlternate(PlaneTypes.AlternateType.Three)
planeM.Evaluate()
Dim mirrorPlane As Features.Feature
mirrorPlane = datumPlaneBuilder1.CommitFeature
Dim geomcopyBuilder1 As Features.GeomcopyBuilder
geomcopyBuilder1 = workPart.Features.CreateGeomcopyBuilder(nullFeatures_FeatureA)
geomcopyBuilder1.Type = Features.GeomcopyBuilder.TransformTypes.Mirror
Dim scCollector1 As ScCollector
scCollector1 = workPart.ScCollectors.CreateCollector()
Dim curves1(0) As IBaseCurve
'******************
curves1(0) = featureA
Dim curveDumbRule1 As CurveDumbRule
curveDumbRule1 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves1)
Dim rules1(0) As SelectionIntentRule
rules1(0) = curveDumbRule1
scCollector1.ReplaceRules(rules1, False)
Dim added1 As Boolean
added1 = geomcopyBuilder1.GeometryToInstance.Add(scCollector1)
Dim added2 As Boolean
added2 = geomcopyBuilder1.GeometryToInstance.Add(mirrorPlane)
Dim feature2 As Features.Feature
feature2 = geomcopyBuilder1.CommitFeature()
geomcopyBuilder1.Destroy()
End Sub
End Module
an answer
This probably isn't the best way to do this, but since this model only contains one spline at the time of the rotation and mirror operations, the spline can be identified with:
Dim curveArray() As Curve
curveArray = workPart.Splines.ToArray
Dim useSpline As Spline
useSpline = curveArray(0)
re: rotate and mirror spline
I've reworked some of your code, please see if it does what you want.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
Module NXJournal
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "journal")
Dim nullUnit As Unit = Nothing
Dim nullFeatures_LawCurve As Features.LawCurve = Nothing
Dim lawCurveBuilderA As Features.LawCurveBuilder
lawCurveBuilderA = workPart.Features.CreateLawCurveBuilder(nullFeatures_LawCurve)
Dim parameter As Expression
parameter = workPart.Expressions.CreateWithUnits("t=0", nullUnit)
Dim xt As Expression
xt = workPart.Expressions.CreateWithUnits("xt=4*t^2", nullUnit)
Dim yt As Expression
yt = workPart.Expressions.CreateWithUnits("yt=t", nullUnit)
Dim zt As Expression
zt = workPart.Expressions.CreateWithUnits("zt=2", nullUnit)
Dim unit1 As Unit
unit1 = lawCurveBuilderA.ZLaw.Value.Units
lawCurveBuilderA.XLaw.AlongSpineData.Spine.DistanceTolerance = 0.001
lawCurveBuilderA.XLaw.AlongSpineData.Spine.ChainingTolerance = 0.00095
lawCurveBuilderA.XLaw.LawCurve.DistanceTolerance = 0.001
lawCurveBuilderA.XLaw.LawCurve.ChainingTolerance = 0.00095
lawCurveBuilderA.YLaw.AlongSpineData.Spine.DistanceTolerance = 0.001
lawCurveBuilderA.YLaw.AlongSpineData.Spine.ChainingTolerance = 0.00095
lawCurveBuilderA.YLaw.LawCurve.DistanceTolerance = 0.001
lawCurveBuilderA.YLaw.LawCurve.ChainingTolerance = 0.00095
lawCurveBuilderA.ZLaw.AlongSpineData.Spine.DistanceTolerance = 0.001
lawCurveBuilderA.ZLaw.AlongSpineData.Spine.ChainingTolerance = 0.00095
lawCurveBuilderA.ZLaw.LawCurve.DistanceTolerance = 0.001
lawCurveBuilderA.ZLaw.LawCurve.ChainingTolerance = 0.00095
'variable to hold the law curve
Dim baseCurve As LawCurve
baseCurve = lawCurveBuilderA.Commit
Dim geomcopyBuilderA As Features.GeomcopyBuilder
Dim nullFeatures_FeatureA As Features.Feature = Nothing
geomcopyBuilderA = workPart.Features.CreateGeomcopyBuilder(nullFeatures_FeatureA)
geomcopyBuilderA.Type = Features.GeomcopyBuilder.TransformTypes.Rotation
geomcopyBuilderA.Associative = False
Dim curvesA(0) As IBaseCurve
Dim splineA As Spline
'***************
'get spline entity from law curve feature
splineA = baseCurve.GetEntities(0)
curvesA(0) = splineA
Dim curveDumbRuleA As CurveDumbRule
curveDumbRuleA = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curvesA)
Dim rulesA(0) As SelectionIntentRule
rulesA(0) = curveDumbRuleA
Dim scCollectorA As ScCollector
scCollectorA = workPart.ScCollectors.CreateCollector()
scCollectorA.ReplaceRules(rulesA, False)
Dim addedA As Boolean
addedA = geomcopyBuilderA.GeometryToInstance.Add(scCollectorA)
Dim datumAxisA As DatumAxis = CType(workPart.Datums.FindObject("DATUM_CSYS(0) Z axis"), DatumAxis)
Dim directionA As Direction
directionA = workPart.Directions.CreateDirection(datumAxisA, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
Dim nullPointA As Point = Nothing
Dim axisA As Axis
axisA = workPart.Axes.CreateAxis(nullPointA, directionA, SmartObject.UpdateOption.WithinModeling)
'rotate law curve feature 45 degrees
Dim markIdRotate As Session.UndoMarkId
markIdRotate = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim nullFeatures_MoveObject As Features.MoveObject = Nothing
Dim moveObjectBuilder1 As Features.MoveObjectBuilder
moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(nullFeatures_MoveObject)
moveObjectBuilder1.TransformMotion.Option = GeometricUtilities.ModlMotion.Options.Angle
moveObjectBuilder1.TransformMotion.Angle.RightHandSide = "45"
theSession.SetUndoMarkName(markIdRotate, "Move Object")
moveObjectBuilder1.TransformMotion.AngularAxis = axisA
Dim added1 As Boolean
added1 = moveObjectBuilder1.ObjectToMoveObject.Add(splineA)
Dim nXObject1 As NXObject
nXObject1 = moveObjectBuilder1.Commit()
Dim objects1() As NXObject
objects1 = moveObjectBuilder1.GetCommittedObjects()
moveObjectBuilder1.Destroy()
'***********************************
'create mirror plane
Dim planeAngle As Double
planeAngle = 2
Dim pt1 As New Point3d(0, 0, 0)
Dim pt2 As New Point3d(Math.Cos(planeAngle), Math.Sin(planeAngle), 0)
Dim planeLine As Line
planeLine = workPart.Curves.CreateLine(pt1, pt2)
Dim datumPlaneBuilder1 As Features.DatumPlaneBuilder
datumPlaneBuilder1 = workPart.Features.CreateDatumPlaneBuilder(nullFeatures_FeatureA)
Dim planeM As Plane
planeM = datumPlaneBuilder1.GetPlane()
planeM.SetUpdateOption(SmartObject.UpdateOption.WithinModeling)
planeM.SetMethod(PlaneTypes.MethodType.TwoLines)
Dim geom1(1) As NXObject
geom1(0) = planeLine
geom1(1) = datumAxisA
planeM.SetGeometry(geom1)
planeM.SetAlternate(PlaneTypes.AlternateType.One)
planeM.Evaluate()
Dim numSolutions1 As Integer
numSolutions1 = planeM.GetNumberOfAlternate()
planeM.SetAlternate(PlaneTypes.AlternateType.Three)
planeM.Evaluate()
Dim mirrorPlane As DatumPlaneFeature
mirrorPlane = datumPlaneBuilder1.CommitFeature
'***********************************
'***********************************
'mirror curve about mirror plane
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim nullFeatures_Feature As Features.Feature = Nothing
Dim mirrorCurveBuilder1 As Features.MirrorCurveBuilder
mirrorCurveBuilder1 = workPart.Features.CreateMirrorCurveBuilder(nullFeatures_Feature)
theSession.SetUndoMarkName(markId2, "Mirror Curve")
mirrorCurveBuilder1.Curve.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)
Dim curves1(0) As IBaseCurve
curves1(0) = splineA
Dim curveDumbRule1 As CurveDumbRule
curveDumbRule1 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves1)
mirrorCurveBuilder1.Curve.AllowSelfIntersection(True)
Dim rules1(0) As SelectionIntentRule
rules1(0) = curveDumbRule1
Dim nullNXObject As NXObject = Nothing
Dim helpPoint1 As Point3d = New Point3d(0, 0, 0)
mirrorCurveBuilder1.Curve.AddToSection(rules1, splineA, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)
mirrorCurveBuilder1.ExistingPlane.Value = mirrorPlane.DatumPlane
Dim nXObject2 As NXObject
nXObject2 = mirrorCurveBuilder1.Commit()
mirrorCurveBuilder1.Curve.CleanMappingData()
mirrorCurveBuilder1.Destroy()
End Sub
End Module
re: rotate and mirror spline
Yes, thank you! GetEntities method does exactly what I need.