3dr
Automotive
- Jul 10, 2004
- 456
I've made a template file with a hole feature. It's always Feature (26)
I want to be able to switch it from Cbore to Csink to Simple.
The Journals I've made do it well in the seed file. But after cloning it into an assembly it doesn't work.
I'm sure it's because it's not the same file anymore.
How can I make this universal to any file with this feature?
TIA for any help
' NX 9.0.2.5
' Journal created by Dave on Tue Oct 27 06:06:17 2015 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
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Feature Parameters")
Dim holePackage1 As Features.HolePackage = CType(workPart.Features.FindObject("COUNTERBORED SCREW HOLE(26)"), Features.HolePackage)
Try
' Invalid feature.
holePackage1.SetGroupActive(True)
Catch ex As NXException
ex.AssertErrorCode(670060)
End Try
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")
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 holePackageBuilder1 As Features.HolePackageBuilder
holePackageBuilder1 = workPart.Features.CreateHolePackageBuilder(holePackage1)
holePackageBuilder1.StartHoleData.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
Dim targetBodies1(0) As Body
Dim nullBody As Body = Nothing
targetBodies1(0) = nullBody
holePackageBuilder1.StartHoleData.BooleanOperation.SetTargetBodies(targetBodies1)
holePackageBuilder1.MiddleHoleData.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
Dim targetBodies2(-1) As Body
holePackageBuilder1.MiddleHoleData.BooleanOperation.SetTargetBodies(targetBodies2)
holePackageBuilder1.EndHoleData.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
Dim targetBodies3(0) As Body
targetBodies3(0) = nullBody
holePackageBuilder1.EndHoleData.BooleanOperation.SetTargetBodies(targetBodies3)
Dim targetBodies4(0) As Body
Dim body1 As Body = CType(workPart.Bodies.FindObject("EXTRUDE(3)"), Body)
targetBodies4(0) = body1
holePackageBuilder1.BooleanOperation.SetTargetBodies(targetBodies4)
holePackageBuilder1.HolePosition.PrepareMappingData()
holePackageBuilder1.ScrewClearanceHoleForm = Features.HolePackageBuilder.HoleForms.Counterbored
theSession.SetUndoMarkName(markId2, "Hole Dialog")
holePackageBuilder1.HolePosition.DistanceTolerance = 0.0004
holePackageBuilder1.HolePosition.ChainingTolerance = 0.00038
holePackageBuilder1.ScrewClearanceHoleForm = Features.HolePackageBuilder.HoleForms.Countersink
holePackageBuilder1.ScrewClearanceCountersinkDiameter.RightHandSide = "0.762"
holePackageBuilder1.ScrewClearanceReliefDepth.RightHandSide = "0.06"
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Hole")
theSession.DeleteUndoMark(markId3, Nothing)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Hole")
holePackageBuilder1.ScrewType = "Machine (82 degree)"
holePackageBuilder1.StartHoleData.ScrewType = "Socket Head, 4762"
holePackageBuilder1.StartHoleData.ScrewSize = "M1.6"
holePackageBuilder1.StartHoleData.FitOption = "Close (H12)"
holePackageBuilder1.MiddleHoleData.FitOption = "Close (H12)"
holePackageBuilder1.EndHoleData.FitOption = "Close (H12)"
Dim nXObject1 As NXObject
nXObject1 = holePackageBuilder1.Commit()
theSession.DeleteUndoMark(markId4, Nothing)
theSession.SetUndoMarkName(markId2, "Hole")
holePackageBuilder1.HolePosition.CleanMappingData()
Dim expression1 As Expression = holePackageBuilder1.DrillSizeTipAngle
Dim expression2 As Expression = holePackageBuilder1.DrillSizeStartChamferOffset
Dim expression3 As Expression = holePackageBuilder1.DrillSizeStartChamferAngle
Dim expression4 As Expression = holePackageBuilder1.DrillSizeEndChamferOffset
Dim expression5 As Expression = holePackageBuilder1.DrillSizeEndChamferAngle
Dim expression6 As Expression = holePackageBuilder1.DrillSizeHoleDiameter
Dim expression7 As Expression = holePackageBuilder1.ScrewClearanceReliefDepth
Dim expression8 As Expression = holePackageBuilder1.ScrewClearanceNeckChamferOffset
Dim expression9 As Expression = holePackageBuilder1.ScrewClearanceNeckChamferAngle
Dim expression10 As Expression = holePackageBuilder1.ScrewClearanceCountersinkDiameter
Dim expression11 As Expression = holePackageBuilder1.ScrewClearanceCountersinkAngle
Dim expression12 As Expression = holePackageBuilder1.GeneralCounterboreDiameter
Dim expression13 As Expression = holePackageBuilder1.GeneralCounterboreDepth
holePackageBuilder1.Destroy()
theSession.DeleteUndoMark(markId2, Nothing)
Dim holePackage2 As Features.HolePackage = CType(nXObject1, Features.HolePackage)
holePackage2.SetGroupActive(False)
theSession.Preferences.Modeling.UpdatePending = False
Dim projectCurve1 As Features.ProjectCurve = CType(workPart.Features.FindObject("CPROJ(31)"), Features.ProjectCurve)
theSession.UpdateManager.SetUpdateFailureAction(projectCurve1, Update.FailureOption.AcceptAll)
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
theSession.Preferences.Modeling.UpdatePending = False
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
Dave
Automotive Tooling / Aircraft Tooling / Ground Support Structures
NX9, Win 7 Pro SP1
I want to be able to switch it from Cbore to Csink to Simple.
The Journals I've made do it well in the seed file. But after cloning it into an assembly it doesn't work.
I'm sure it's because it's not the same file anymore.
How can I make this universal to any file with this feature?
TIA for any help
' NX 9.0.2.5
' Journal created by Dave on Tue Oct 27 06:06:17 2015 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
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Feature Parameters")
Dim holePackage1 As Features.HolePackage = CType(workPart.Features.FindObject("COUNTERBORED SCREW HOLE(26)"), Features.HolePackage)
Try
' Invalid feature.
holePackage1.SetGroupActive(True)
Catch ex As NXException
ex.AssertErrorCode(670060)
End Try
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")
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 holePackageBuilder1 As Features.HolePackageBuilder
holePackageBuilder1 = workPart.Features.CreateHolePackageBuilder(holePackage1)
holePackageBuilder1.StartHoleData.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
Dim targetBodies1(0) As Body
Dim nullBody As Body = Nothing
targetBodies1(0) = nullBody
holePackageBuilder1.StartHoleData.BooleanOperation.SetTargetBodies(targetBodies1)
holePackageBuilder1.MiddleHoleData.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
Dim targetBodies2(-1) As Body
holePackageBuilder1.MiddleHoleData.BooleanOperation.SetTargetBodies(targetBodies2)
holePackageBuilder1.EndHoleData.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
Dim targetBodies3(0) As Body
targetBodies3(0) = nullBody
holePackageBuilder1.EndHoleData.BooleanOperation.SetTargetBodies(targetBodies3)
Dim targetBodies4(0) As Body
Dim body1 As Body = CType(workPart.Bodies.FindObject("EXTRUDE(3)"), Body)
targetBodies4(0) = body1
holePackageBuilder1.BooleanOperation.SetTargetBodies(targetBodies4)
holePackageBuilder1.HolePosition.PrepareMappingData()
holePackageBuilder1.ScrewClearanceHoleForm = Features.HolePackageBuilder.HoleForms.Counterbored
theSession.SetUndoMarkName(markId2, "Hole Dialog")
holePackageBuilder1.HolePosition.DistanceTolerance = 0.0004
holePackageBuilder1.HolePosition.ChainingTolerance = 0.00038
holePackageBuilder1.ScrewClearanceHoleForm = Features.HolePackageBuilder.HoleForms.Countersink
holePackageBuilder1.ScrewClearanceCountersinkDiameter.RightHandSide = "0.762"
holePackageBuilder1.ScrewClearanceReliefDepth.RightHandSide = "0.06"
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Hole")
theSession.DeleteUndoMark(markId3, Nothing)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Hole")
holePackageBuilder1.ScrewType = "Machine (82 degree)"
holePackageBuilder1.StartHoleData.ScrewType = "Socket Head, 4762"
holePackageBuilder1.StartHoleData.ScrewSize = "M1.6"
holePackageBuilder1.StartHoleData.FitOption = "Close (H12)"
holePackageBuilder1.MiddleHoleData.FitOption = "Close (H12)"
holePackageBuilder1.EndHoleData.FitOption = "Close (H12)"
Dim nXObject1 As NXObject
nXObject1 = holePackageBuilder1.Commit()
theSession.DeleteUndoMark(markId4, Nothing)
theSession.SetUndoMarkName(markId2, "Hole")
holePackageBuilder1.HolePosition.CleanMappingData()
Dim expression1 As Expression = holePackageBuilder1.DrillSizeTipAngle
Dim expression2 As Expression = holePackageBuilder1.DrillSizeStartChamferOffset
Dim expression3 As Expression = holePackageBuilder1.DrillSizeStartChamferAngle
Dim expression4 As Expression = holePackageBuilder1.DrillSizeEndChamferOffset
Dim expression5 As Expression = holePackageBuilder1.DrillSizeEndChamferAngle
Dim expression6 As Expression = holePackageBuilder1.DrillSizeHoleDiameter
Dim expression7 As Expression = holePackageBuilder1.ScrewClearanceReliefDepth
Dim expression8 As Expression = holePackageBuilder1.ScrewClearanceNeckChamferOffset
Dim expression9 As Expression = holePackageBuilder1.ScrewClearanceNeckChamferAngle
Dim expression10 As Expression = holePackageBuilder1.ScrewClearanceCountersinkDiameter
Dim expression11 As Expression = holePackageBuilder1.ScrewClearanceCountersinkAngle
Dim expression12 As Expression = holePackageBuilder1.GeneralCounterboreDiameter
Dim expression13 As Expression = holePackageBuilder1.GeneralCounterboreDepth
holePackageBuilder1.Destroy()
theSession.DeleteUndoMark(markId2, Nothing)
Dim holePackage2 As Features.HolePackage = CType(nXObject1, Features.HolePackage)
holePackage2.SetGroupActive(False)
theSession.Preferences.Modeling.UpdatePending = False
Dim projectCurve1 As Features.ProjectCurve = CType(workPart.Features.FindObject("CPROJ(31)"), Features.ProjectCurve)
theSession.UpdateManager.SetUpdateFailureAction(projectCurve1, Update.FailureOption.AcceptAll)
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
theSession.Preferences.Modeling.UpdatePending = False
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
Dave
Automotive Tooling / Aircraft Tooling / Ground Support Structures
NX9, Win 7 Pro SP1