Option Strict Off
Imports System
Imports System.Math
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.UF
Module report_bounding_box_plus_block
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Sub Main()
Dim a_body As NXOpen.Tag
Dim csys As NXOpen.Tag
Dim min_corner(2) As Double
Dim directions(2,2) As Double
Dim distances(2) As Double
Dim n As String = vbCrLf
While select_a_body(a_body) = Selection.Response.Ok 'And _
' select_a_csys(wcs) = Selection.Response.Ok
ufs.Modl.AskBoundingBoxExact(a_body, csys, min_corner, directions, _
distances)
ufs.Ui.OpenListingWindow()
'ufs.Ui.WriteListingWindow("Min_corner: " & _
' min_corner(0).ToString & ", " & _
' min_corner(1).ToString & ", " & _
' min_corner(2).ToString & ", " & n)
' ufs.Ui.WriteListingWindow("Stock Size X: " & _
' directions(0,0).ToString & ", " & _
' directions(0,1).ToString & ", " & _
' directions(0,2).ToString & ", " & n)
ufs.Ui.WriteListingWindow("Stock Size X: " & _
Math.Round(distances(0),3).ToString & n)
' ufs.Ui.WriteListingWindow("Stock Size Y: " & _
' directions(1,0).ToString & ", " & _
' directions(1,1).ToString & ", " & _
' directions(1,2).ToString & ", " & n)
ufs.Ui.WriteListingWindow("Stock Size Y " & _
Math.Round(distances(1),3).ToString & n)
' ufs.Ui.WriteListingWindow("Z direction: " & _
' directions(2,0).ToString & ", " & _
' directions(2,1).ToString & ", " & _
' directions(2,2).ToString & ", " & n)
ufs.Ui.WriteListingWindow("Stock Size Z: " & _
Math.Round(distances(2),3).ToString & n & n)
' End While
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Want to create a block?" ' Define message.
style = MsgBoxStyle.YesNo
title = "Stock Size Bloco" ' Define title.
' Display the dialog for the user
response = MsgBox(msg, style, title)
If response = MsgBoxResult.No Then
'
Exit Sub
End If
--------------------------------------------------------------
Dim coordinates1 As Point3d = New Point3d (min_corner(0), min_corner(1), min_corner(2))
Dim point1 As Point
Dim T_Dim_X As String = Math.Round(distances(0),3)
Dim T_Dim_Y As String = Math.Round(distances(1),3)
Dim T_Dim_Z As String = Math.Round(distances(2),3)
T_Dim_X = T_Dim_X.replace(",", ".")
T_Dim_Y = T_Dim_Y.replace(",", ".")
T_Dim_Z = T_Dim_Z.replace(",", ".")
point1 = workPart.Points.CreatePoint(coordinates1)
Dim nullFeatures_Feature As Features.Feature = Nothing
Dim blockFeatureBuilder1 As Features.BlockFeatureBuilder
blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature)
Dim originPoint1 As Point3d = New Point3d (min_corner(0), min_corner(1), min_corner(2))
blockFeatureBuilder1.SetOriginAndLengths(originPoint1, T_Dim_X, _
T_Dim_Y, _
T_Dim_Z)
' Decimal.Round(distances(1),3), _
' Decimal.Round(distances(2),3))
Dim feature1 As Features.Feature
feature1 = blockFeatureBuilder1.CommitFeature()
blockFeatureBuilder1.Destroy()
Dim body2 As Body
Dim LastBlock As Features.Block = CType (feature1,Features.Block)
body2 = LastBlock.GetBodies (0)
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.NewColor = 6
displayModification1.NewTranslucency = 50
displayModification1.NewFont = DisplayableObject.ObjectFont.Dashed
Dim objects1(0) As DisplayableObject
objects1(0) = body2
displayModification1.Apply(objects1)
displayModification1.Dispose()
'---------------------------------------------------------------------------------
End While
End Sub
Function select_a_body(ByRef a_body As NXOpen.Tag) As Selection.Response
Dim message As String
Dim title As String = "Select a body"
Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
Dim response As Integer
Dim obj As NXOpen.Tag
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
Function select_a_csys(ByRef csys As NXOpen.Tag) As Selection.Response
Dim message As String
Dim title As String = "Select a CSYS"
Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
Dim response As Integer
Dim obj As NXOpen.Tag
Dim view As NXOpen.Tag
Dim cursor(2) As Double
Dim ip As UFUi.SelInitFnT = AddressOf csys_init_proc
ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Try
ufs.Ui.SelectWithSingleDialog(message, title, scope, ip, _
Nothing, response, csys, 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(csys, 0)
Return Selection.Response.Ok
End If
End Function
Function csys_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_coordinate_system_type
mask_triples(0).object_subtype = UFConstants.UF_csys_normal_subtype
mask_triples(0).solid_type = 0
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