Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

How to restrict to 4 decimal points

Status
Not open for further replies.

UGMasters

Automotive
Jan 22, 2008
51
0
0
CA

Hello Gentlemen,
this Journal gives me the min & Max x,y & z values of a selected solid.
I need help to make this suit my requirements
1.How to restrict to 4 decimal points
2.How to put these values in to the Expression

Regards
Girish


ption Strict Off
'Journal to calculate extreme values for X , Y & Z in relation to Absolute CSY_14-Sep-2020


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 min_corner(2) As Double
Dim max_corner(2) As Double
Dim directions(2, 2) As Double
Dim distances(2) As Double
Dim X_Max(2) As Double
Dim edge_len(2) As Double

While select_a_body(a_body) = Selection.Response.Ok

ufs.Csys.AskWcs(csys)

ufs.Modl.AskBoundingBoxExact(a_body, csys, min_corner, directions, _
distances)

lw.Open()


'_____________________________________________________________________________Min Value extraction


'Get the Values for X ,Y & Z Minimum

'lw.WriteLine(" X Min " & _
'min_corner(0).ToString & ", Y Min " & _
'min_corner(1).ToString & ",Z Min " & _
' min_corner(2).ToString & ", ")
lw.WriteLine("-----------------")
lw.WriteLine(" X Min " & _
min_corner(0).ToString)
lw.WriteLine("Y Min " & _
min_corner(1).ToString)
lw.WriteLine("Z Min " & _
min_corner(2).ToString)
lw.WriteLine("-----------------")

'_____________________________________________________________________________Max Value

'Get the Values for X ,Y & Z Maximum
edge_len(0) = distances(0).ToString()
edge_len(1) = distances(1).ToString()
edge_len(2) = distances(2).ToString()



lw.WriteLine("X Max + " & _
((edge_len(0)) + (min_corner(0).ToString)))

lw.WriteLine("Y Max + " & _
((edge_len(1)) + (min_corner(1).ToString)))

lw.WriteLine("Z Max + " & _
((edge_len(2)) + (min_corner(2).ToString)))
 
Replies continue below

Recommended for you

Thanks Cowski,
it worked.

This Journal reports the envelop of each solid as you select,
is there any way we can modify this Journal to report the envelop for the total all the selected parts combined?
I meant to say, the Journal should able to select a number of solids on screen and create 6 expressions in the top file

xmax
xmin
ymax
ymin
zmax
zmin
The top file has attribute UM_TOP.

________________________________________________________________________________________________
Option Strict Off
'Journal to calculate extreme values for X , Y & Z in relation to Absolute CSY_14-Sep-2020


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 min_corner(2) As Double
Dim max_corner(2) As Double
Dim directions(2, 2) As Double
Dim distances(2) As Double
Dim X_Max(2) As Double
Dim edge_len(2) As Double

While select_a_body(a_body) = Selection.Response.Ok

ufs.Csys.AskWcs(csys)

ufs.Modl.AskBoundingBoxExact(a_body, csys, min_corner, directions, _
distances)

lw.Open()


'_____________________________________________________________________________Min Value extraction


lw.WriteLine("-----------------")
lw.WriteLine(" X Min " & _
min_corner(0).ToString("0.0000"))
lw.WriteLine("Y Min " & _
min_corner(1).ToString("0.0000"))
lw.WriteLine("Z Min " & _
min_corner(2).ToString("0.0000"))
lw.WriteLine("-----------------")

'_____________________________________________________________________________Max Value

'Get the Values for X ,Y & Z Maximum
edge_len(0) = distances(0).ToString(("0.0000"))
edge_len(1) = distances(1).ToString(("0.0000"))
edge_len(2) = distances(2).ToString(("0.0000"))



lw.WriteLine("X Max + " & _
((edge_len(0)) + (min_corner(0).ToString("0.0000"))))

lw.WriteLine("Y Max + " & _
((edge_len(1)) + (min_corner(1).ToString("0.0000"))))

lw.WriteLine("Z Max + " & _
((edge_len(2)) + (min_corner(2).ToString("0.0000"))))


End While

End Sub

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

Dim message As String = "WM _Engg Select a body"
Dim title As String = "WM _Engg 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

__________________________________________

Regarfds
G.
 
To get the overall bounding box of multiple entities, you can iterate over the desired objects and save the overall extreme values. Some pseudocode below:

Code:
dim xMax as double = double.minvalue
dim xMin as double = double.maxvalue
for each tempBody as body
  askboundingbox(tempBody, tempMinX, tempMaxX)
  xMin = math.min(tempMinX, xMin)
  xMax = math.max(tempMaxX, xMax)
next

Now xMin and xMax will hold the overall min and max values of all the bodies. Of course you would do the same for the Y and Z values.

www.nxjournaling.com
 
Hi

Please create 2 folders "application", "startup" in the directory where "UGII_USER_DIR" environment variable is pointing.
Create a custom button-> Edit action-> type "Journal" , browse to the "MaxBox.cs" file in the "application" directory.
This tool will list the Max and Min values of X,Y and Z in listing window for the selected multiple solids in the assembly.
It also create/update expression values for XMIN,XMAX.YMIN,YMAX,ZMIN and ZMAX.
 
 https://files.engineering.com/getfile.aspx?folder=b8983e5c-c552-43a6-8cfb-5f30fd9367f4&file=MaxBox.zip
Status
Not open for further replies.
Back
Top