Journal Project

hi to all,

i m new in journaling and i have no idea how to achive the following...

i need a journal to first auto create a bounding body around a part and second to
pick two points (front upper corner point, back lower corner point).
i need to capture the coordinates of these two points in respect of the current CSYS (selected by me). Also i need to export those coordinate values as Xmax,Ymax,Zmax for the upper corner point and Xmin,Ymin,Zmin for the lower corner point.
By those coordinates i can calculate the
X_dimension = Xmax + (-Xmin), the
Y_dimension = Ymax + (-Ymin), the
Z_dimension = Zmax + (-Zmin).

Finally i need to save these values (Xmax, Xmin, Ymax, Ymin, Zmax, Zmin, Xdimension, Ydimension, Zdimension) as Expressions or Attributes to the part.

i need another one journal to do the same but without the bounding body creation.
i pick the bounding body and the current CSYS and save the same values as Expressions or Attributes to the part.

Is it possible as project??
Will someone help me to make it??

Thanks in advance.

What version of NX are you using? Not sure when it was introduced, but look for 'Bounding Body' in the command finder. Record a journal using the Bounding Body function. This should get you started.

Ric Hotchkiss
Principal Design Automation Architect
Engineering USA
o: 860-749-3832x214 c: 860-463-8486
r.hotchkiss@engusa.com

https://www.eng-tips.com/viewthread.cfm?qid=323165

The thread above has some journals that calculate the bounding body but do not create any geometry; it should be a good starting point for your second journal.

Thanks for your support. After a lot of research i found these 3 journals.
First for bounding body creation.

Option Strict Off

Imports System

Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.UF

Module make_bounding_block_of_selected_body_relative_to_wcs

Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow()

Sub Main()

Dim a_body As NXOpen.Tag = NXOpen.Tag.Null
Dim csys As NXOpen.Tag = NXOpen.Tag.Null
Dim target As NXOpen.Tag = NXOpen.Tag.Null
Dim blockFeature As NXOpen.Tag = NXOpen.Tag.Null
Dim matrix_id As NXOpen.Tag = NXOpen.Tag.Null
Dim feature_obj_id As NXOpen.Tag = NXOpen.Tag.Null

Dim min_corner(2) As Double
Dim directions(2, 2) As Double
Dim distances(2) As Double
Dim edge_len(2) As String
Dim csys_origin (2) As Double
Dim origin2(2) As Double
Dim normal(2) As Double
Dim offset As String
Dim angle As String

While select_a_body(a_body) = Selection.Response.Ok

ufs.Csys.AskWcs(csys)

ufs.Modl.AskBoundingBoxExact(a_body, csys, min_corner, directions, _
distances)
ufs.Modl.AskDatumPlaneParms(feature_obj_id,origin2,normal,offset,angle)
ufs.Csys.AskCsysInfo(csys,matrix_id,csys_origin)
lw.Open()

lw.WriteLine("X distance: " & _
distances(0).ToString)

lw.WriteLine("Y distance: " & _
distances(1).ToString)

lw.WriteLine("Z distance: " & _
distances(2).ToString)

edge_len(0) = distances(0).ToString()
edge_len(1) = distances(1).ToString()
edge_len(2) = distances(2).ToString()

lw.WriteLine("csys_origin: " & _
int(csys_origin(0).ToString) & ", " & _
int(csys_origin(1).ToString) & ", " & _
int(csys_origin(2).ToString) & ", ")

lw.WriteLine("csys_origin2: " & _
int(origin2(0).ToString) & ", " & _
int(origin2(1).ToString) & ", " & _
int(origin2(2).ToString) & ", ")

ufs.Modl.CreateBlock(FeatureSigns.Nullsign, _
target, min_corner, edge_len, blockFeature)
End While

End Sub

Function select_a_body(ByRef a_body As NXOpen.Tag) As Selection.Response

Dim message As String = "Select a body"
Dim title As String = "Select a body"
Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
Dim response As Integer

Dim view As NXOpen.Tag
Dim cursor(2) As Double
Dim ip As UFUi.SelInitFnT = AddressOf body_init_proc

ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)

Try
ufs.Ui.SelectWithSingleDialog(message, title, scope, ip, _
Nothing, response, a_body, cursor, view)
Finally
ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
End Try

If response <> UFConstants.UF_UI_OBJECT_SELECTED And _
response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
Return Selection.Response.Cancel
Else
ufs.Disp.SetHighlight(a_body, 0)
Return Selection.Response.Ok
End If

End Function

Function body_init_proc(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer

Dim num_triples As Integer = 1
Dim mask_triples(0) As UFUi.Mask
mask_triples(0).object_type = UFConstants.UF_solid_type
mask_triples(0).object_subtype = UFConstants.UF_solid_body_subtype
mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_BODY

ufs.Ui.SetSelMask(select_, _
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY

End Function

End Module

Second For CSYS creation

Option Strict Off
Imports System
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF

Module Module2

Public Enum csysOption As Integer
Inferred = 0
Origin_Xpt_Ypt = 1
Xaxis_Yaxis = 2
Zaxis_Xpoint = 3
Csys_object = 4
Dynamic = 5
OffsetCsys = 6
Absolute = 7
CurrentView = 8
ThreePlanes = 9
Xaxis_Yaxis_Origin = 10
Point_PerpendicularCurve = 11
Plane_Vector = 12
Plane_Xaxis_Pt = 13
Zaxis_Xaxis_Origin = 14
Zaxis_Yaxis_Origin = 15
End Enum

Sub Main()

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

Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

If IsNothing(displayPart) Then
'active part required
Return
End If

'9 element orientation matrix of specified csys
'arrays are zero based
Dim myCsys(8) As Double

'3 element array: origin point of specified csys
Dim myOrigin(2) As Double

'tag variable used as input/output for the .SpecifyCsys method
'passing a null tag into the function uses the current WCS as the starting csys
Dim newCsysTag As Tag = Tag.Null

'variable to hold the user specified coordinate system
Dim newCsys As CartesianCoordinateSystem

Dim response As Integer

'If you want to know the option the user used to specify the csys, pass in a variable.
'The initial value of the variable will control the default option shown to the user.
'After the function returns, this variable will hold the actual option used.
Dim specifyOption As csysOption = csysOption.Dynamic

'optional message to user
MessageBox.Show("Orient manipulator to the desired location/orientation", "Specify Coordinate System", MessageBoxButtons.OK, MessageBoxIcon.Information)
theUISession.LockAccess()

response = theUfSession.Ui.SpecifyCsys("Specify Desired Orientation", specifyOption, myCsys, myOrigin, newCsysTag)

'if you don't care what option was used to specify the csys, simply pass in an integer that specified the default method to show to the user
'response = theUfSession.Ui.SpecifyCsys("Specify Desired Orientation", csysOption.Dynamic, myCsys, myOrigin, newCsysTag)

theUISession.UnlockAccess()

If response = Selection.Response.Ok Then
'get CartesianCoordinateSystem object from tag
newCsys = Utilities.NXObjectManager.Get(newCsysTag)
'orient WCS to specified coordinate system
displayPart.WCS.SetCoordinateSystemCartesianAtCsys(newCsys)

'try to parse enumeration value to integer (should always work in our case)
Dim num As Integer
If Not Integer.TryParse(specifyOption, num) Then
num = -1
End If

If num > -1 Then
MessageBox.Show("The user used option: " & specifyOption.ToString & " (option: " & num.ToString & ")", "Option used", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("The user used option: " & specifyOption.ToString, "Option used", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

Else
'user pressed back or cancel or the system was in a state that could not allow the dialog to be shown
'1 = back
'2 = cancel
'3 = OK
'7 = no active part
'8 = disallowed state, unable to bring up dialog
End If

End Sub

End Module

Third for point creation and save them as expressions

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Point3d

Module Module1

Const ptNamePrefix As String = "WZ"

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim ptsPoints As New List(Of Point)

If SelectPoints("Select points", ptsPoints) = Selection.Response.Cancel Then
Exit Sub
End If

Dim ptsQtyExp As Expression
Try
ptsQtyExp = workPart.Expressions.FindObject("ptsQty")
Catch ex As NXException
If ex.ErrorCode = 3520016 Then
'not found, create it
Dim nullUnit As Unit = Nothing
ptsQtyExp = workPart.Expressions.CreateWithUnits("ptsQty=0", nullUnit)
Else
MsgBox(ex.ErrorCode & ": " & ex.Message)
Exit Sub
End If
End Try

Dim nextPtNum As Integer = ptsQtyExp.Value

For i As Integer = 0 To ptsPoints.Count - 1
nextPtNum += 1

ptsPoints.Item(i).SetName(ptNamePrefix & nextPtNum.ToString)

'create expression for each point coordinate
CreateExpression(workPart, ptNamePrefix & nextPtNum.ToString & "_x", ptsPoints.Item(i).Coordinates.X)
CreateExpression(workPart, ptNamePrefix & nextPtNum.ToString & "_y", ptsPoints.Item(i).Coordinates.Y)
CreateExpression(workPart, ptNamePrefix & nextPtNum.ToString & "_z", ptsPoints.Item(i).Coordinates.Z)

Dim mypoint As Double
mypoint(0) = ptsPoints.Item(i).Coordinates.X
mypoint(1) = ptsPoints.Item(i).Coordinates.Y
mypoint(2) = ptsPoints.Item(i).Coordinates.Z

NXOpen.Point3d.Point3d ( double X,
double Y,
double Z
)

Abs2WCS(mypoint)
'create expression for each point coordinate

CreateExpression(workPart, ptNamePrefix & nextPtNum.ToString & "_y", Abs2WCS.X)
CreateExpression(workPart, ptNamePrefix & nextPtNum.ToString & "_y", Abs2WCS.Y)
CreateExpression(workPart, ptNamePrefix & nextPtNum.ToString & "_z", Abs2WCS.Z)

Next

'update points quantity expression
ptsQtyExp.Value = nextPtNum

End Sub

Function SelectPoints(ByVal prompt As String, ByRef pointList As List(Of Point)) As Selection.Response

Dim selObj() As TaggedObject
Dim theUI As UI = UI.GetUI
Dim title As String = "Select points"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_point_type
.Subtype = UFConstants.UF_all_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj)
If resp = Selection.Response.Ok Then
For Each pt As Point In selObj
If Not pt.Name.Contains(ptNamePrefix) Then
pointList.Add(pt)
End If
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Sub CreateExpression(ByVal thePart As Part, ByVal expName As String, ByVal expValue As Double)

Dim nullUnit As Unit = Nothing
thePart.Expressions.CreateWithUnits(expName & "=" & expValue.ToString, nullUnit)

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function
Function Abs2WCS(ByVal mypt As Double) As Point3d
Dim ufs As UFSession = UFSession.GetUFSession()
Dim pt1(2), pt2(2) As Double

pt1(0) = mypt.X
pt1(1) = mypt.Y
pt1(2) = mypt.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

Can i combine these 3 journals into one??
Also how can i export the point coordinates according the CSYS i have created at second journal?

i have seen the journal:

https://community.sw.siemens.com/s/question/0D54O000061xOWO/obtaining-po...

but i can't make it work....

sfot

To make it clear...

1) i want to create a bounding box around the part
2) after this i want to open a dialog box to specify a CSYS
3) after this i want to open a dialog box to pick a point
4) finally i want to save the bounding box dimentions(x,y,z) and the point coordinates(x,y,z) relative to the CSYS i have created before as expression to part.

sfot

Do you want the sides of the bounding box to be parallel to the chosen csys planes? If so, I think you will need to select the csys first, before calculating the bounding box.

Thanks a lot for your reply.
No, the CSYS plane should be ralated to the bounding box, so i need to make first the bounding box and then open a dialog to create the CSYS.

sfot