Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal to Create Knurl on Cylindrical Face

Status
Not open for further replies.

Barnon

Mechanical
Jul 23, 2016
97
I'm trying to write a Journal that would create a Knurl on any cylindrical face, like shown below, with just a few inputs. Manually I create a plane tangent to the face, sketch a curve, wrap it to face, create another sketch, sweep that sketch with the wrapped curve, mirror sweep and then a circular pattern.

I'm new to Journaling and the code below just creates the first plane tangent to the face. It works when my geometry is relative to absolute but I want it to work relative to WCS. Is there any command to make that happen? I've seen Csys.MapPoint in this forum but seems like I should be able to always work off the WCS.

Knurl_wgc4sx.jpg


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim myFace As Face
If SelectEdge("select circular edge", myFace) = Selection.Response.Cancel Then
Return
End If

Dim ufs As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession
Dim axisPoint(2) As Double
Dim axisVector(2) As Double
Dim box(5) As Double 'minX, minY, minZ, maxX, maxY, maxZ.
Dim surfType As Integer
Dim r1, r2 As Double
Dim flip As Integer
ufs.Modl.AskFaceData(myFace.Tag, surfType, axisPoint, axisVector, box, r1, r2, flip)


Dim origin As New NXOpen.Point3d(box(3),0,box(5)/2)
Dim axisX As New NXOpen.Point3d(box(3),0,box(5)/2-1)
Dim wcsMatrix As NXOpen.Matrix3x3 = workPart.WCS.CoordinateSystem.Orientation.Element
Dim sketchPlane As NXOpen.DatumPlane = workPart.Datums.CreateFixedDatumPlane(origin, wcsMatrix)
Dim horizAxis As NXOpen.DatumAxis = workPart.Datums.CreateFixedDatumAxis(origin, axisX)


End Sub

Function SelectEdge(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select circular edge"
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_CYLINDRICAL_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

End Module
 
Replies continue below

Recommended for you

I'm trying to use the Mappoint function below but I'm getting a System.NullReferenceException error. Below is a small section of the code. What's my newbie problem?

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim s As Session = Nothing
Dim ufs As UFSession = Nothing

Sub Main()


Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim origin As New NXOpen.Point3d(1,2,3)
dim WCSorigin As NXOpen.Point3d
WCSorigin = Abs2WCS(origin)

End Sub


Function Abs2WCS(ByVal inPt As Point3d) As Point3d
Dim pt1(2), pt2(2) As Double

pt1(0) = inPt.X
pt1(1) = inPt.Y
pt1(2) = inPt.Z

ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1,UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)

Abs2WCS.X = pt2(0)
Abs2WCS.Y = pt2(1)
Abs2WCS.Z = pt2(2)

End Function

End Module
 
Change this:
Code:
Module Module1

Dim s As Session = Nothing
Dim ufs As UFSession = Nothing

Sub Main()


Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

to this:
Code:
Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Sub Main()

Then change any code that references the "s" variable to reference the "theSession" variable and likewise update references from "ufs" to "theUfSession" (or keep the "s" and "ufs" variable names if you prefer and change "theSession" and "theUfSession" as required).

As your code stands now, the Abs2Wcs function tries to use the "ufs" variable and fails because this variable has been declared as "nothing" (hence the "null reference" error); it needs to reference the current UF session object.

www.nxjournaling.com
 
I can't help you with that journal, but i can maybe propose a simpler method than the wrap curve.
Use a helix instead, then you do not need the sketch / datumplane/ wrap.


Regards,
Tomas

 
Thanks Cowski!

Toost

Helix does sound like a better approach... I was also trying to use the thread feature but was unsuccessful.

(Edit)

Helix approach cuts down the feature tree list quite a bit. Not sure if it represents real geometry of a knurling operation but I usually add a note stating geometry shown is for appearance only and call out a specific Knurl.

Clipboard02_dzyjug.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor