Hello,
how can I create a Pocket in journal?
I hav make me a Function for Holes...
Public Shared Function NXCreateHole(myPart As Part, _
myBody As Body, _
myPoint As Point3d, _
myDiameter As Double, _
myDepth As Double, _
mySinkDiameter As Double, _
mySinkDepth As Double, _
Optional myDirection As DatumAxis = Nothing) As Features.Feature
Dim HolePoint As NXOpen.Point = myPart.Points.CreatePoint(myPoint)
Dim holePackageBuilder1 As Features.HolePackageBuilder
holePackageBuilder1 = myPart.Features.CreateHolePackageBuilder(Nothing)
holePackageBuilder1.GeneralHoleForm = Features.HolePackageBuilder.HoleForms.Simple
holePackageBuilder1.HolePosition.AddSmartPoint(HolePoint, 1)
holePackageBuilder1.GeneralTipAngle.RightHandSide = "0"
holePackageBuilder1.GeneralHoleDiameter.RightHandSide = myDiameter
holePackageBuilder1.GeneralHoleDepth.RightHandSide = myDepth
If mySinkDepth > 0 Then
holePackageBuilder1.GeneralHoleForm = Features.HolePackageBuilder.HoleForms.Counterbored
holePackageBuilder1.GeneralCounterboreDiameter.RightHandSide = mySinkDiameter
holePackageBuilder1.GeneralCounterboreDepth.RightHandSide = mySinkDepth
End If
If Not myDirection Is Nothing Then
Dim direction1 As Direction = myPart.Directions.CreateDirection(myDirection, Sense.Forward, SmartObject.UpdateOption.WithinModeling)
holePackageBuilder1.ProjectionDirection.ProjectDirectionMethod = GeometricUtilities.ProjectionOptions.DirectionType.Vector
holePackageBuilder1.ProjectionDirection.ProjectVector = direction1
Dim Vx As Vector3d = myDirection.Direction
If myDirection.Origin.X <> myPoint.X And myDirection.Origin.Y <> myPoint.Y And myDirection.Origin.Z <> myPoint.Z Then
Dim AxisX As DatumAxis = myPart.Datums.CreateFixedDatumAxis(myPoint, New Point3d(myPoint.X + Vx.X, myPoint.Y + Vx.Y, myPoint.Z + Vx.Z))
End If
End If
Dim targetBodies5(0) As Body
targetBodies5(0) = myBody
holePackageBuilder1.BooleanOperation.SetTargetBodies(targetBodies5)
Dim Hole As Features.Feature = holePackageBuilder1.Commit()
Return Hole
End Function
re: pocket
What type of pocket are you trying to create? There is a "pocket" command in the modeling application, is this what you are referring to?
yes, I mean the "pocket"
yes, I mean the "pocket" command (Insert -> Design Features -> pocket...)
type?
What type of pocket would you like to create?
Cylindrical, rectangular, or general?
Hi, rectangular pocket with
Hi, rectangular pocket with corner Radius
re: create pocket
Below is some code that should get you started. The journal will prompt you to select a planar face and X direction, then it will create a rectangular pocket near the middle of the chosen face.
With some more work, you could prompt the user for a location. To make it work similarly to the interactive command, you might want to add positioning features (I've not looked into it that deeply).
For testing, I was working with a large block feature in an inch file; you will want to change the pocket parameters for your file in the line:
CreateRectPocket(thePlacementFace, myXDir, 4, 3, 0.25, 0.25, 0.12, 3.5)
The journal:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
lw.Open()
Const undoMarkName As String = "create rectangular pocket"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim thePlacementFace As Face
If SelectPlanarFace("choose placement face for pocket", thePlacementFace) = Selection.Response.Cancel Then
Return
End If
Dim myXDir As Vector3d = SpecifyVector("Choose pocket X direction")
If IsNothing(myXDir) Then
Return
End If
CreateRectPocket(thePlacementFace, myXDir, 4, 3, 0.25, 0.25, 0.12, 3.5)
lw.Close()
End Sub
Function SelectPlanarFace(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a planar face"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACE
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Sub CreateRectPocket(ByVal theFace As Face, ByVal Xvec As Vector3d, _
ByVal Xlength As Double, ByVal Ylength As Double, ByVal depth As Double, _
ByVal cornerRadius As Double, ByVal floorRadius As Double, ByVal taperAngle As Double)
Dim faceNormal As Vector3d = PlanarFaceNormal(theFace)
Dim unitNormal() As Double = {faceNormal.X, faceNormal.Y, faceNormal.Z}
Dim xDir() As Double = {Xvec.X, Xvec.Y, Xvec.Z}
Dim pocLoc As Point3d = PlanarFaceMidPoint(theFace)
Dim pocketLocation() As Double = {pocLoc.X, pocLoc.Y, pocLoc.Z}
Dim pocketDirection(2) As Double
theUfSession.Vec3.Negate(unitNormal, pocketDirection)
Dim pocketSize() As String = {Xlength.ToString, Ylength.ToString, depth.ToString}
Dim cornerRad As String = cornerRadius.ToString
Dim floorRad As String = floorRadius.ToString
Dim taper As String = taperAngle.ToString
Dim pocketTag As Tag = Tag.Null
theUfSession.Modl.CreateRectPocket(pocketLocation, pocketDirection, xDir, pocketSize, cornerRad, floorRad, taper, theFace.Tag, pocketTag)
End Sub
Function SpecifyVector(ByVal prompt As String) As Vector3d
Dim theUISession As UI = UI.GetUI()
Dim direction(2) As Double
Dim origin(2) As Double
Dim response As Integer
theUISession.LockAccess()
theUfSession.Ui.SpecifyVector(prompt, UFConstants.UF_UI_INFERRED, UFConstants.UF_UI_DISP_TEMP_VECTOR, direction, origin, response)
theUISession.UnlockAccess()
If response <> UFConstants.UF_UI_OK Then
Return Nothing
End If
Dim outputDir As Vector3d
outputDir.X = direction(0)
outputDir.Y = direction(1)
outputDir.Z = direction(2)
Return outputDir
End Function
Function PlanarFaceNormal(ByVal planarFace As Face) As Vector3d
'get normal direction of given face
Dim param() As Double = {0, 0}
Dim pt(2) As Double
Dim u1(2) As Double
Dim v1(2) As Double
Dim u2(2) As Double
Dim v2(2) As Double
Dim unitNormal(2) As Double
Dim radii(1) As Double
theUfSession.Modl.AskFaceProps(planarFace.Tag, param, pt, u1, v1, u2, v2, unitNormal, radii)
Dim faceNormal As New Vector3d(unitNormal(0), unitNormal(1), unitNormal(2))
Return faceNormal
End Function
Function PlanarFaceMidPoint(ByVal planarFace As Face) As Point3d
Dim uvMinMax(3) As Double
theUfSession.Modl.AskFaceUvMinmax(planarFace.Tag, uvMinMax)
Dim ptMin(2) As Double
Dim ptMax(2) As Double
'get mid point of given face
Dim param() As Double = {(uvMinMax(0) + uvMinMax(1)) / 2, (uvMinMax(2) + uvMinMax(3)) / 2}
Dim pt(2) As Double
Dim u1(2) As Double
Dim v1(2) As Double
Dim u2(2) As Double
Dim v2(2) As Double
Dim unitNormal(2) As Double
Dim radii(1) As Double
theUfSession.Modl.AskFaceProps(planarFace.Tag, param, pt, u1, v1, u2, v2, unitNormal, radii)
Dim midPt As New Point3d(pt(0), pt(1), pt(2))
Return midPt
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module