Hello, I am trying to following actions by journal.
User offsets a curve in face. And this action triggers a tube command. Nx automatically makes a 4mm radius tube with this offsetted curve.
I recorded the below journal for this but it looks so complicated for me. Can u help me on this?
' NX 8.0.2.2
'
'
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->Curve from Curves->Offset in Face...
' ----------------------------------------------
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 aOCSBuilder1 As Features.AOCSBuilder
aOCSBuilder1 = workPart.Features.CreateAocsBuilder(nullFeatures_Feature)
Dim section1 As Section
section1 = workPart.Sections.CreateSection(0.02413, 0.0254, 0.5)
Dim section2 As Section
section2 = workPart.Sections.CreateSection(0.02413, 0.0254, 0.5)
aOCSBuilder1.LawString = section2
Dim lawBuilder1 As GeometricUtilities.LawBuilder
lawBuilder1 = aOCSBuilder1.Law
Dim expression1 As Expression
expression1 = lawBuilder1.StartValue
Dim expression2 As Expression
expression2 = lawBuilder1.EndValue
Dim expression3 As Expression
expression3 = lawBuilder1.Value
Dim alongSpineBuilder1 As GeometricUtilities.AlongSpineBuilder
alongSpineBuilder1 = lawBuilder1.AlongSpineData
Dim unit1 As Unit
unit1 = aOCSBuilder1.FilletRadius.Units
Dim expression4 As Expression
expression4 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression5 As Expression
expression5 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression6 As Expression
expression6 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression7 As Expression
expression7 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression8 As Expression
expression8 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression9 As Expression
expression9 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression10 As Expression
expression10 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression11 As Expression
expression11 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression12 As Expression
expression12 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression13 As Expression
expression13 = aOCSBuilder1.FilletRadius
Dim curveFitJoin1 As GeometricUtilities.CurveFitJoin
curveFitJoin1 = aOCSBuilder1.CurveFitJoinData
Dim nullScCollector As ScCollector = Nothing
aOCSBuilder1.FaceCollector = nullScCollector
aOCSBuilder1.TrimMethod = Features.AOCSBuilder.Trim.WithinSection
aOCSBuilder1.ExtendMethod = Features.AOCSBuilder.Extend.WithinSection
aOCSBuilder1.TrimToFaceEdgesOption = True
aOCSBuilder1.ExtendToFaceOption = Features.AOCSBuilder.ExtendToFace.None
aOCSBuilder1.AssociativeOutputOption = True
aOCSBuilder1.OffsetMode = Features.AOCSBuilder.OffsetType.Chordal
aOCSBuilder1.DistanceTolerance = 0.0254
aOCSBuilder1.OffsetDistType = Features.AOCSBuilder.OffsetDistanceType.Constant
aOCSBuilder1.LawStringFlip = False
aOCSBuilder1.OffsetDirectionOption = Features.AOCSBuilder.OffsetDirection.NormalToCurve
aOCSBuilder1.FilletOption = Features.AOCSBuilder.FilletOptions.NoFillet
aOCSBuilder1.RemoveSelfIntersections = True
expression13.RightHandSide = "5.0"
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Update Law Data")
Dim objectList1 As ObjectList
objectList1 = alongSpineBuilder1.SpinePointList
objectList1.Clear(ObjectList.DeleteOption.Delete)
theSession.DeleteUndoMarksUpToMark(markId2, "Update Law Data", False)
theSession.SetUndoMarkName(markId1, "Offset Curve in Face Dialog")
section1.DistanceTolerance = 0.0254
section1.ChainingTolerance = 0.02413
section2.DistanceTolerance = 0.0254
section2.ChainingTolerance = 0.02413
aOCSBuilder1.Law.AlongSpineData.Spine.DistanceTolerance = 0.0254
aOCSBuilder1.Law.AlongSpineData.Spine.ChainingTolerance = 0.02413
aOCSBuilder1.Law.LawCurve.DistanceTolerance = 0.0254
aOCSBuilder1.Law.LawCurve.ChainingTolerance = 0.02413
section1.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)
Dim section3 As Section
section3 = workPart.Sections.CreateSection(0.02413, 0.0254, 0.5)
Dim nullSection As Section = Nothing
Dim expressionSectionSet1 As ExpressionSectionSet
expressionSectionSet1 = workPart.CreateExpressionSectionSet(nullSection, "10", "Length", 0)
expressionSectionSet1.ItemFlipFlag = True
aOCSBuilder1.Offsets.Append(expressionSectionSet1)
section3.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "section mark")
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, Nothing)
Dim edges1(0) As Edge
Dim brep1 As Features.Brep = CType(workPart.Features.FindObject("UNPARAMETERIZED_FEATURE(0)"), Features.Brep)
Dim edge1 As Edge = CType(brep1.FindObject("EDGE * 30 * 72 {(-131.0784369105108,90.8147661098534,130.2393322029726)(-129.1705132344285,101.1513916918431,128.7226642755924)(-127.2474145210153,111.4697594143704,127.1047959202027) UNPARAMETERIZED_FEATURE(0)}"), Edge)
edges1(0) = edge1
Dim edgeDumbRule1 As EdgeDumbRule
edgeDumbRule1 = workPart.ScRuleFactory.CreateRuleEdgeDumb(edges1)
section3.AllowSelfIntersection(False)
Dim rules1(0) As SelectionIntentRule
rules1(0) = edgeDumbRule1
Dim nullNXObject As NXObject = Nothing
Dim helpPoint1 As Point3d = New Point3d(-129.910097463325, 97.1566454838592, 129.321340288346)
section3.AddToSection(rules1, edge1, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)
theSession.DeleteUndoMark(markId4, Nothing)
expressionSectionSet1.Section = section3
Dim flipDirection1 As Boolean
flipDirection1 = aOCSBuilder1.UpdateSectionData(section3)
expressionSectionSet1.ItemValue.RightHandSide = "10"
theSession.DeleteUndoMark(markId3, Nothing)
Dim scCollector1 As ScCollector
scCollector1 = workPart.ScCollectors.CreateCollector()
Dim faces1(0) As Face
Dim face1 As Face = CType(brep1.FindObject("FACE 30 {(-120.6880204445295,100.4238543178286,130.5938141045439) UNPARAMETERIZED_FEATURE(0)}"), Face)
faces1(0) = face1
Dim faceDumbRule1 As FaceDumbRule
faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(faces1)
Dim rules2(0) As SelectionIntentRule
rules2(0) = faceDumbRule1
scCollector1.ReplaceRules(rules2, False)
aOCSBuilder1.FaceCollector = scCollector1
aOCSBuilder1.UpdateFaces()
Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Offset Curve in Face")
Dim feature1 As Features.Feature
feature1 = aOCSBuilder1.CommitFeature()
theSession.DeleteUndoMark(markId5, Nothing)
theSession.SetUndoMarkName(markId1, "Offset Curve in Face")
section3.CleanMappingData()
Dim expression14 As Expression = expressionSectionSet1.ItemValue
aOCSBuilder1.Destroy()
section1.Destroy()
workPart.Expressions.Delete(expression5)
workPart.Expressions.Delete(expression7)
workPart.Expressions.Delete(expression8)
workPart.Expressions.Delete(expression9)
workPart.Expressions.Delete(expression10)
workPart.Expressions.Delete(expression11)
workPart.Expressions.Delete(expression12)
workPart.Expressions.Delete(expression4)
workPart.Expressions.Delete(expression6)
' ----------------------------------------------
' Menu: Insert->Sweep->Tube...
' ----------------------------------------------
Dim markId6 As Session.UndoMarkId
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim tubeBuilder1 As Features.TubeBuilder
tubeBuilder1 = workPart.Features.CreateTubeBuilder(nullFeatures_Feature)
tubeBuilder1.Tolerance = 0.0254
tubeBuilder1.OuterDiameter.RightHandSide = "4"
tubeBuilder1.InnerDiameter.RightHandSide = "0"
tubeBuilder1.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
Dim targetBodies1(0) As Body
Dim nullBody As Body = Nothing
targetBodies1(0) = nullBody
tubeBuilder1.BooleanOption.SetTargetBodies(targetBodies1)
tubeBuilder1.OutputOption = Features.TubeBuilder.Output.SingleSegment
theSession.SetUndoMarkName(markId6, "Tube Dialog")
tubeBuilder1.PathSection.DistanceTolerance = 0.0254
tubeBuilder1.PathSection.ChainingTolerance = 0.02413
tubeBuilder1.PathSection.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)
Dim markId7 As Session.UndoMarkId
markId7 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "section mark")
Dim markId8 As Session.UndoMarkId
markId8 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, Nothing)
Dim features1(0) As Features.Feature
Dim aOCS1 As Features.AOCS = CType(feature1, Features.AOCS)
features1(0) = aOCS1
Dim arc1 As Arc = CType(aOCS1.FindObject("CURVE 1"), Arc)
Dim nullCurve As Curve = Nothing
Dim curveFeatureTangentRule1 As CurveFeatureTangentRule
curveFeatureTangentRule1 = workPart.ScRuleFactory.CreateRuleCurveFeatureTangent(features1, arc1, nullCurve, False, 0.02413, 0.5)
tubeBuilder1.PathSection.AllowSelfIntersection(True)
Dim rules3(0) As SelectionIntentRule
rules3(0) = curveFeatureTangentRule1
Dim helpPoint2 As Point3d = New Point3d(-118.970703579602, 102.731069056367, 130.498922740421)
tubeBuilder1.PathSection.AddToSection(rules3, arc1, nullNXObject, nullNXObject, helpPoint2, Section.Mode.Create, False)
theSession.DeleteUndoMark(markId8, Nothing)
theSession.DeleteUndoMark(markId7, Nothing)
tubeBuilder1.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
Dim targetBodies2(0) As Body
Dim body1 As Body = CType(workPart.Bodies.FindObject("UNPARAMETERIZED_FEATURE(0)"), Body)
targetBodies2(0) = body1
tubeBuilder1.BooleanOption.SetTargetBodies(targetBodies2)
Dim markId9 As Session.UndoMarkId
markId9 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Tube")
Dim nXObject1 As NXObject
nXObject1 = tubeBuilder1.Commit()
theSession.DeleteUndoMark(markId9, Nothing)
theSession.SetUndoMarkName(markId6, "Tube")
Dim expression15 As Expression = tubeBuilder1.OuterDiameter
Dim expression16 As Expression = tubeBuilder1.InnerDiameter
tubeBuilder1.Destroy()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
re: tube on surface
What is your intended workflow? It appears that this journal both creates the offset curve on surface and the tube features. From your description, it sounds like the journal would be run after creating an offset curve feature.
My intended workflow is my description
Hello, I record the journal from the begining of choosing the offset curve. But my inteded workflow is as in my description.
re: tube on surface
Creating a tube feature from the offset curves won't be too difficult; but getting the code to execute immediately following an offset curve on surface command might be. You could write a journal that would use the last offset curve feature to create the tube command, but it would have to be started manually. I know of no way to automatically execute code after a certain feature type is created.