Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

ufs.Modl.AskBoundingBoxExact give min_corner that not the closest to the ABS Csys

Status
Not open for further replies.

Ehaviv

Computer
Jul 2, 2003
1,012
Hi

As the picture show the
min_corner that not the closest to the ABS Csys.

min_corner_h8axim.jpg


Or I don't understand the therm minimum corner ?

Thanks.

I used this journal for this minimum corner.

Code:
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 min_corner(2) As Double
        Dim directions(2, 2) As Double
        Dim distances(2) As Double
        Dim edge_len(2) 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)
 
            lw.Open()
 
            lw.WriteLine("Min_corner: " & _
                min_corner(0).ToString & ", " & _
                min_corner(1).ToString & ", " & _
                min_corner(2).ToString & ", ")
 
            lw.WriteLine("X direction: " & _
                directions(0, 0).ToString & ", " & _
                directions(0, 1).ToString & ", " & _
                directions(0, 2).ToString & ", ")
            lw.WriteLine("X distance: " & _
                distances(0).ToString)
 
            lw.WriteLine("Y direction: " & _
                directions(1, 0).ToString & ", " & _
                directions(1, 1).ToString & ", " & _
                directions(1, 2).ToString & ", ")
            lw.WriteLine("Y distance: " & _
                distances(1).ToString)
 
            lw.WriteLine("Z direction: " & _
                directions(2, 0).ToString & ", " & _
                directions(2, 1).ToString & ", " & _
                directions(2, 2).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()
 
            '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
 
Replies continue below

Recommended for you

Logically I expect the point that
is closest to the origin of the ABS
coordinate system.

the point that laying on the green plate.
 
I say logically because
I do not know the meaning of
min Corner.
 
If you take the mathematical minimum of the corner coordinates (min[x1, x2,...x8], min[y1, y2,...y8], min[z1, z1,...z8]), which corner would you end up with?

www.nxjournaling.com
 
You take the algebraic minimum.
I`m token the geometric minimum.

So does min Corner mean algebraic minimum.

According the result its clear.

Thank you Cowski.
 
I was continue to play with this
boundingbox issue and I found that
in some rotate csys the created
boundingbox is completely outside
of the body that should be bounded ?
 
Are you working in the context of an assembly? If so, make sure you get the occurrence object and the correct csys.

NX help said:
If you call this function with an occurrence, the bounding box
of the underlying geometry is transformed into assembly space.

Use occurrence object tags when working in an assembly context and prototype
object tags when working in non-assembly situations. Passing in a prototype
object tag when in an assembly may produce undesired results.

The csys_tag should always be in the context of the current work part.

www.nxjournaling.com
 
No. its in peace part context.
the wcs is in the abs and I do a -45deg
about the y axis.
 
Hi Cowski and thank you for your eforts to help me.

I'm wonderful how a small change can do big wrong.
Is change a value from abs to wcs can do that and why ?

Code:
Option Strict Off 
Imports System 
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.UF
 
Module make_bounding_points_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 dp As Part = s.Parts.Display
 
        Dim min_corner(2) As Double
        Dim directions(2, 2) As Double
        Dim distances(2) As Double
        Dim edge_len(2) As String
        Dim abs2wcs_pt As New Point3d

        ufs.Ui.ExitListingWindow()
        lw.Open()
 
        While select_a_body(a_body) = Selection.Response.Ok
 
            ufs.Csys.AskWcs(csys)
 
            ufs.Modl.AskBoundingBoxExact(a_body, csys, min_corner, directions, distances)

            abs2wcs_pt.X = min_corner(0) : abs2wcs_pt.Y = min_corner(1) : abs2wcs_pt.Z = min_corner(2)
            abs2wcs_pt = Abs2WCS(abs2wcs_pt)
            min_corner(0) = abs2wcs_pt.X : min_corner(1) = abs2wcs_pt.Y : min_corner(2) = abs2wcs_pt.Z
 
            lw.WriteLine("Min_corner: " & min_corner(0).ToString & ", " & min_corner(1).ToString & ", " & min_corner(2).ToString & ", ")
            lw.WriteLine("")
 
            lw.WriteLine("X direction: " & directions(0, 0).ToString & ", " & directions(0, 1).ToString & ", " & directions(0, 2).ToString & ", ")
            lw.WriteLine("X distance: " & distances(0).ToString)
 
            lw.WriteLine("Y direction: " & directions(1, 0).ToString & ", " & directions(1, 1).ToString & ", " & directions(1, 2).ToString & ", ")
            lw.WriteLine("Y distance: " & distances(1).ToString)
 
            lw.WriteLine("Z direction: " & directions(2, 0).ToString & ", " & directions(2, 1).ToString & ", " & directions(2, 2).ToString & ", ")
            lw.WriteLine("Z distance: " & distances(2).ToString)

            lw.WriteLine("")
            lw.WriteLine("-------------------------")
 
            edge_len(0) = distances(0).ToString()
            edge_len(1) = distances(1).ToString()
            edge_len(2) = distances(2).ToString()

            Dim sp As New Point3d(min_corner(0), min_corner(1), min_corner(2))   
            Dim thePoint As Point = s.Parts.Work.Points.CreatePoint(sp)
            thePoint.SetVisibility(SmartObject.VisibilityOption.Visible)
            'sp.Color = 51 
            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

    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  
 
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
 
        GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
 
    End Function

End Module
 
Now I see that NX build the bounding
by abs values. and that my big mistake.

All this comme because my model can be
completely outside the ABS csys and
I wanted to see the values in relative to wcs
to know the side of the bounded block
if on the top of the green plate or in its bottom side.
according the sign of z value
 
Do NX build all object in ABS values ?
 
There are a few exceptions (.AskMassProps3d being one), but in general, the NXOpen API will use ABS coordinates for input/output.

www.nxjournaling.com
 
After many confusions I`m now in stability.
and also get what I search for.

and you helped me to get it.

Thank you.
 
Hi Cowski
If you see this.
I need additional help
the journal now working smoothly when
applied to model part (peace part)
and now I become hungry to make it
working also in assembly context.

for this I played with the above journal
and I revealed that when I rotate the
csys about Z axis the min Corner change
its location on the wrapped block
but in the Z direction its ok.

and note also that I added an isoccurrence
on the selected body and its say true.

the documentation say that the min Corner
is in abs value. So no matter where wcs
is the min Corner must stay in the same
place so why when I rotate wcs the
min Corner change its location.

I note that the body is occurrence body.

Please explain to me what is the
correct csys that you mean in your post.

I`m very thank you.

Are you working in the context of an assembly? If so, make sure you get the occurrence object and the correct csys.

Quote (NX help)
If you call this function with an occurrence, the bounding box
of the underlying geometry is transformed into assembly space.

Use occurrence object tags when working in an assembly context and prototype
object tags when working in non-assembly situations. Passing in a prototype
object tag when in an assembly may produce undesired results.

The csys_tag should always be in the context of the current work part.
 
Hi

I played around with this journl that work perfectly with peace part and
I don't succeed to understand how
ufs.Modl.AskBoundingBoxExact(a_body, csys, min_corner, directions, distances)
work in an assembly part.

I'm posted here the parts files that I played with theme to try to understand this function.
the white point is the min corner and the magenta point shoud lay on middle of top face
of the block to be wraped

If you play in model part you'll see that it works perfect (the white point is on min corner and the magenta is on middle top face)
My target in all this is the magenta point to be allwase on the middle face of the wraped block.

I hop someone can help in this

Code:
Option Strict Off
 
Imports System
 
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.UF
 
Module make_bounding_points_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 dp As Part = s.Parts.Display
 
  Dim min_corner(2) As Double
  Dim directions(2, 2) As Double
  Dim distances(2) As Double
  Dim edge_len(2) As String
  Dim min_Point As Point 
  Dim min_pt As Point3d  
  Dim abs2wcs_pt As New Point3d
  Dim top_face_mid_pt As Point3d 
  Dim face_mid_Point As Point 

  ufs.Ui.ExitListingWindow()
  lw.Open()
 
  While select_a_body(a_body) = Selection.Response.Ok
   msgbox(ufs.Assem.IsOccurrence(a_body)) 
   'ufs.Csys.AskWcs(csys) 
   'ufs.Modl.AskBoundingBoxExact(a_body, csys, min_corner, directions, distances)
   ufs.Modl.AskBoundingBoxExact(a_body, Nothing, min_corner, directions, distances)

   abs2wcs_pt.X = min_corner(0) : abs2wcs_pt.Y = min_corner(1) : abs2wcs_pt.Z = min_corner(2)
   abs2wcs_pt = Abs2WCS(abs2wcs_pt)
   If Math.abs(abs2wcs_pt.Z) <0.0000001 Then abs2wcs_pt.Z = 0

   top_face_mid_pt.X = min_corner(0) + (directions(0,0)*distances(0)/2) + (directions(1,0)*distances(1)/2) + (directions(2,0)*distances(2)/2)
   top_face_mid_pt.Y = min_corner(1) + (directions(0,1)*distances(0)/2) + (directions(1,1)*distances(1)/2) + (directions(2,1)*distances(2)/2)
   top_face_mid_pt.Z = min_corner(2) + (directions(0,2)*distances(0)) + (directions(1,2)*distances(1)) + (directions(2,2)*distances(2))

   lw.WriteLine("abs2wcs_pt: X = " & abs2wcs_pt.X.ToString & ", Y = " & abs2wcs_pt.Y.ToString & ", Z = " & abs2wcs_pt.Z.ToString & ", ")
   lw.WriteLine("")

   lw.WriteLine("Min_corner: " & min_corner(0).ToString & ", " & min_corner(1).ToString & ", " & min_corner(2).ToString & ", ")
   lw.WriteLine("")
 
   lw.WriteLine("X direction: " & directions(0, 0).ToString & ", " & directions(0, 1).ToString & ", " & directions(0, 2).ToString & ", ")
   lw.WriteLine("X distance: " & distances(0).ToString)
 
   lw.WriteLine("Y direction: " & directions(1, 0).ToString & ", " & directions(1, 1).ToString & ", " & directions(1, 2).ToString & ", ")
   lw.WriteLine("Y distance: " & distances(1).ToString)
 
   lw.WriteLine("Z direction: " & directions(2, 0).ToString & ", " & directions(2, 1).ToString & ", " & directions(2, 2).ToString & ", ")
   lw.WriteLine("Z distance: " & distances(2).ToString)

   lw.WriteLine("")
   lw.WriteLine("-------------------------")
 
   edge_len(0) = distances(0).ToString()
   edge_len(1) = distances(1).ToString()
   edge_len(2) = distances(2).ToString()  
   ufs.Modl.CreateBlock(FeatureSigns.Nullsign, target, min_corner, edge_len, blockFeature)

   min_pt = New Point3d(min_corner(0), min_corner(1), min_corner(2))   
   min_Point = s.Parts.Work.Points.CreatePoint(min_pt)
   min_Point.SetVisibility(SmartObject.VisibilityOption.Visible)
   min_Point.Color = 7
   min_Point.RedisplayObject 

   face_mid_Point = s.Parts.Work.Points.CreatePoint(top_face_mid_pt)
   face_mid_Point.SetVisibility(SmartObject.VisibilityOption.Visible)
   face_mid_Point.Color = 5
   face_mid_Point.RedisplayObject 

  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

 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  
 
 Public Function GetUnloadOption(ByVal dummy As String) As Integer 
  GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY 
 End Function

End Module
 
 https://files.engineering.com/getfile.aspx?folder=65592ec2-fe8b-4636-baeb-e027a4191142&file=060818_zip.zip
Status
Not open for further replies.

Part and Inventory Search

Sponsor