Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Edge Lenght of BoundedBlock 1

Status
Not open for further replies.

javaxp

Automotive
Jul 14, 2014
43
ES
Hi,

I want to write a journal that creates a NonAlignedMinimumBox and then gets the lenght of it's edges.

How to get the edgeLength when creating a NonAlignedMinimumBox BoundedBlock ?

On the NXOpen documentation says :

.CalculateBoxSize
Calculate box size and get directions, edge length, lower point position.

Signature CalculateBoxSize()

Returns: a tuple
Return type: A tuple consisting of (minPoint, edgeLength, cysMatrix). minPoint is a NXOpen.Point3d. edgeLength is a list of float. cysMatrix is a NXOpen.Matrix3x3.


Thanks in advance,

Javier
 
Replies continue below

Recommended for you

You do know that there is a button that creates a bounding box ?
search for "Bounding body".
It will present the edge lengths in real time when you rotate the coordinate system.

Regards, Tomas

 
Thanks Tomas
Yes, I know there is the function, but i want to create a journal that writes the edge lenghts into attributes(independent of a Csys).
Using the toolingBoxBuilder1.XValue.Value don't get the real values.

Regards, Javi
 
You need a csys definition. ( or use the Absolute Csys.) - The Csys controls the directions of the edges,- the orientation of the block.

Regards,
Tomas




 
My goal is not to have to define a Csys.
In interactive mode, the MW_TOOLS_BOX shows the dimensions of the created block on screen, even in non-aligned mode.
I want to avoid having to establish a Csys piece by piece.

Javier
 
without the csys definition you will most likely be using the Absolute Csys.
0527_yzlokw.png


Regards,
Tomas
 
But in this case the measurements might not be accurate if the block is not aligned with the
Absolute Csys.
I think there is no solution...Thanks anyway Tomas

Regards,
Javier
 
Hi,

Finally I've achieved a solution that works...

The strategy that I have used is to create the "non aligned" bounding box , then create a Csys on a face of that bounded box, and finally get the dimensions using the obtained Csys.

There is the code :


Code:
'####################################################################
' Journal para calcular la caja mínima de las piezas de un ensamble.
'Crea atributos con los valores de la caja mínima.
'Limitado a un solo cuerpo por pieza.
'Código para recorrer el assembly obtenida de NXJournaling.com February 24, 2012
'Código para crear Csys a partir de una cara obtenido de GTAC: CreateCsysfromPlanarFace
' Creado por Javier Axpe

'####################################################################




Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Features
Imports System.Collections.Generic



Module NXJournal

    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow
    Dim workPart As Part = theSession.Parts.Work
    Dim theUfSession = UFSession.GetUFSession()
    Dim dispPart As Part = theSession.Parts.Display
    Dim origDisplayPart As Part = theSession.Parts.Display
    Dim origWorkComp As NXOpen.Assemblies.Component = theSession.Parts.WorkComponent


    Sub Main()


        Try
            Dim c As ComponentAssembly = dispPart.ComponentAssembly
            'to process the work part rather than the display part,
            '  comment the previous line and uncomment the following line
            'Dim c As ComponentAssembly = workPart.ComponentAssembly
            If Not IsNothing(c.RootComponent) Then
                '*** insert code to process 'root component' (assembly file)
                'lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
                'lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
                '*** end of code to process root component
                reportComponentChildren(c.RootComponent, 0)
            Else
                '*** insert code to process piece part
                lw.WriteLine("Part has no components")
            End If
        Catch e As Exception
            theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
        End Try
        'lw.Close()


        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
        theSession.Parts.SetWorkComponent(origWorkComp, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)

    End Sub

    '**********************************************************
    Sub reportComponentChildren(ByVal comp As Component,
        ByVal indent As Integer)

        For Each child As Component In comp.GetChildren()
            '*** insert code to process component or subassembly
            'lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
            '*** end of code to process component or subassembly
            If child.GetChildren.Length <> 0 Then
                '*** this is a subassembly, add code specific to subassemblies
                'lw.WriteLine(New String(" ", indent * 2) &
                '    "* subassembly with " &
                '    child.GetChildren.Length & " components")
                'lw.WriteLine(New String(" ", indent * 2) &
                '    " + Active Arrangement: " &
                '    child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
                '*** end of code to process subassembly
            Else
                'this component has no children (it is a leaf node)
                'add any code specific to bottom level components
                Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
                theSession.Parts.SetWorkComponent(child, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)


                Try

                    Dim marcaProcesado = theSession.Parts.Work.GetStringAttribute("CUERPOBRUTO")

                Catch
                    Try

                        Dim Cuerpos() As Body
                        Cuerpos = AskAllBodies(theSession.Parts.Work)

                        CreateBoundedBox(Cuerpos)


                        theSession.Parts.SetWorkComponent(child, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)
                        Dim actualWorkPart As NXOpen.Part = theSession.Parts.Work
                        theSession.Parts.SetDisplay(actualWorkPart, False, False, partLoadStatus1)

                        Dim objs() As NXObject = theSession.Parts.Work.Layers.GetAllObjectsOnLayer(2)



                        Dim count As Integer = theSession.UpdateManager.AddToDeleteList(objs)

                        Dim undoMark As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Undo Mark")


                        theSession.UpdateManager.DoUpdate(undoMark)
                        theSession.Parts.SetDisplay(dispPart, False, True, partLoadStatus1)



                    Catch

                    End Try

                End Try


            End If
            reportComponentChildren(child, indent + 1)
        Next
    End Sub
    '**********************************************************

    '**********************************************************

    Function AskAllBodies(ByVal thePart As Part) As Body()
        Dim theBodies As New System.Collections.ArrayList()

        Dim aBodyTag As Tag = Tag.Null
        Do
            ufs.Obj.CycleObjsInPart(thePart.Tag,
                UFConstants.UF_solid_type, aBodyTag)
            If aBodyTag = Tag.Null Then
                Exit Do
            End If

            Dim theType As Integer, theSubtype As Integer
            ufs.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
            If theSubtype = UFConstants.UF_solid_body_subtype Then
                theBodies.Add(theSession.GetObjectManager.GetTaggedObject(aBodyTag))

            End If
        Loop While True

        Return DirectCast(theBodies.ToArray(GetType(Body)), Body())
    End Function


    Function CreateBoundedBox(ByVal cuerpos() As Body)

        Dim tempWorkPart As Part = theSession.Parts.Work


        Dim nullNXOpen_Features_ToolingBox As NXOpen.Features.ToolingBox = Nothing

        Dim toolingBoxBuilder1 As NXOpen.Features.ToolingBoxBuilder = Nothing
        toolingBoxBuilder1 = tempWorkPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(nullNXOpen_Features_ToolingBox)

        toolingBoxBuilder1.Type = NXOpen.Features.ToolingBoxBuilder.Types.BoundedBlock
        toolingBoxBuilder1.NonAlignedMinimumBox = True

        Dim matrix1 As NXOpen.Matrix3x3 = Nothing
        matrix1.Xx = 1.0
        matrix1.Xy = 0.0
        matrix1.Xz = 0.0
        matrix1.Yx = 0.0
        matrix1.Yy = 1.0
        matrix1.Yz = 0.0
        matrix1.Zx = 0.0
        matrix1.Zy = 0.0
        matrix1.Zz = 1.0
        Dim position1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
        toolingBoxBuilder1.SetBoxMatrixAndPosition(matrix1, position1)

        Dim bodies1(0) As NXOpen.Body
        Dim body1 As NXOpen.Body = cuerpos(0)

        bodies1(0) = body1
        Dim bodyDumbRule1 As NXOpen.BodyDumbRule = Nothing
        bodyDumbRule1 = tempWorkPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, True)

        Dim scCollector1 As NXOpen.ScCollector = Nothing
        scCollector1 = toolingBoxBuilder1.BoundedObject

        Dim rules1(0) As NXOpen.SelectionIntentRule
        rules1(0) = bodyDumbRule1
        scCollector1.ReplaceRules(rules1, False)

        Dim selections1(0) As NXOpen.NXObject
        selections1(0) = body1
        Dim deselections1(-1) As NXOpen.NXObject
        toolingBoxBuilder1.SetSelectedOccurrences(selections1, deselections1)

        Dim selectNXObjectList1 As NXOpen.SelectNXObjectList = Nothing
        selectNXObjectList1 = toolingBoxBuilder1.FacetBodies

        Dim objects1(-1) As NXOpen.NXObject
        Dim added1 As Boolean = Nothing
        added1 = selectNXObjectList1.Add(objects1)

        toolingBoxBuilder1.CalculateBoxSize()

        Dim csysorigin1 As NXOpen.Point3d = New NXOpen.Point3d(50.0, 50.0, 50.0)
        toolingBoxBuilder1.BoxPosition = csysorigin1

        Dim nXObject1 As NXOpen.NXObject = Nothing
        nXObject1 = toolingBoxBuilder1.Commit()

        toolingBoxBuilder1.Destroy()


        Dim objects2(0) As NXOpen.NXObject
        objects2(0) = tempWorkPart
        Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder
        attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(tempWorkPart, objects2, NXOpen.AttributePropertiesBuilder.OperationType.None)

        attributePropertiesBuilder1.Title = "CUERPOBRUTO"
        attributePropertiesBuilder1.StringValue = "PROCESADO"

        Dim nXObject2 As NXOpen.NXObject
        nXObject2 = attributePropertiesBuilder1.Commit()


        Dim featArray() As Feature = theSession.Parts.Work.Features.GetFeatures()
        Dim featEntities() As NXObject

        'lw.WriteLine("*** All Features ***")
        For Each myFeature As Features.BodyFeature In featArray

            Dim tipo As String
            Dim myBodies() As Body
            Dim myFaces() As Face
            tipo = myFeature.FeatureType.ToString
            'lw.WriteLine("Tipo  " & tipo)
            If myFeature.FeatureType.ToString = "Tooling Box" Then


                myBodies = myFeature.GetBodies()
                myFaces = myBodies(0).GetFaces()
                Dim face As Face = myFaces(0)
                Dim matrixTag As Tag = Tag.Null
                Dim cSysTag As Tag = Tag.Null
                Dim faceType As Integer = 0
                Dim normalDirection As Integer = 0
                Dim origin As Double() = New Double(2) {}
                Dim dir As Double() = New Double(2) {}
                Dim boundedBox As Double() = New Double(5) {}
                Dim radius As Double = 0
                Dim radiusData As Double = 0
                theUfSession.Csys.AskMatrixOfObject(face.Tag, matrixTag)
                theUfSession.Modl.AskFaceData(face.Tag, faceType, origin, dir, boundedBox, radius, radiusData, normalDirection)
                theUfSession.Csys.CreateTempCsys(origin, matrixTag, cSysTag)
                theUfSession.Csys.SetWcs(cSysTag)
                Dim min_corner(2) As Double
                Dim directions(2, 2) As Double
                Dim distances(2) As Double
                Dim edge_len(2) As String
                ufs.Modl.AskBoundingBoxExact(myBodies(0).Tag, cSysTag, min_corner, directions,
                distances)


                Dim theObject(0) As Body


                theObject(0) = body1
                Dim myMeasure As MeasureManager = theSession.Parts.Display.MeasureManager()
                Dim massUnits(4) As Unit
                massUnits(0) = theSession.Parts.Display.UnitCollection.GetBase("Area")
                massUnits(1) = theSession.Parts.Display.UnitCollection.GetBase("Volume")
                massUnits(2) = theSession.Parts.Display.UnitCollection.GetBase("Mass")
                massUnits(3) = theSession.Parts.Display.UnitCollection.GetBase("Length")

                Dim mb As MeasureBodies = Nothing
                mb = myMeasure.NewMassProperties(massUnits, 0.99, theObject)

                Dim objectArray1(0) As NXOpen.DisplayableObject

                Dim body2 As NXOpen.Body = myBodies(0)

                objectArray1(0) = body2

                tempWorkPart.Layers.ApplyMoveToLayerToOwningParts(2, objectArray1)

                objectArray1(0).Highlight()
                objectArray1(0).Blank()



                attributePropertiesBuilder1.Category = "BRUTO"
                attributePropertiesBuilder1.Title = "BRUTO_X"
                attributePropertiesBuilder1.StringValue = CInt(distances(0)).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()

                attributePropertiesBuilder1.Category = "BRUTO"
                attributePropertiesBuilder1.Title = "BRUTO_Y"
                attributePropertiesBuilder1.StringValue = CInt(distances(1)).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()

                attributePropertiesBuilder1.Category = "BRUTO"
                attributePropertiesBuilder1.Title = "BRUTO_Z"
                attributePropertiesBuilder1.StringValue = CInt(distances(2)).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()

                attributePropertiesBuilder1.Category = "BRUTO"
                attributePropertiesBuilder1.Title = "MEDIDAS_BRUTO"
                attributePropertiesBuilder1.StringValue = CInt(distances(0)).ToString & " x " & CInt(distances(1)).ToString & " x " & CInt(distances(2)).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()



                attributePropertiesBuilder1.Title = "VOLUMEN"
                attributePropertiesBuilder1.StringValue = CInt(mb.Volume).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()

                attributePropertiesBuilder1.Title = "PESO"
                attributePropertiesBuilder1.StringValue = mb.Weight.ToString
                nXObject2 = attributePropertiesBuilder1.Commit()



                attributePropertiesBuilder1.Destroy()

            End If


        Next

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function


End Module


 
Hello, Javier.

The code you wanted to create is what i want :) i found this thread while searching.

I tried your journal but couldn't get it work. I wasn't able to get X,Y,Z values.

The code just creates "Gross Body" : "Processed" attribute.

**** If the body has already a CSYS in it , the code doesn't work ****
 
Hi tOlga,

sorry for the delay in answering, I just started today to work after the holidays.

The code above is for running in assembly context. If running on part alone it returns an error.
In addition to the "CUERPOBRUTO" attribute it creates the "BRUTO_X", "BRUTO_Y" and "BRUTO_Z" attributes that contains the X,Y,Z values, and the "MEDIDAS_BRUTO" attribute that contains these values in "A x B x C" format. These values are independent of any CSYS.
In addition it creates the "PESO" (weight) and the "VOLUMEN" (volume) attributes. The weight is calculated based on the density of material.
For me, it works in NX12 and 1892 version.

tOlga said:
**** If the body has already a CSYS in it , the code doesn't work ****

I can't reproduce this behavior...

Regards,

Javier
 
@javaxp

I am using NX 12.0.2.9 . Our template file contains a CSYS in default.

I added an assembly with 2 parts. Part 022 (contains CSYS) and Part 025 (No CSYS).

When i ran the code, the bounding body got created Part 022 (contains CSYS) and then not deleted. Also the attributes except "PROCESADO" not created

It is fine with Part 025 (No CSYS), everything works as it is coded.
 
 https://files.engineering.com/getfile.aspx?folder=913667d8-4d93-4693-bd19-bd88fee6390a&file=assembly.zip
Hi tOlga,


Try with this new version. For me it works correctly, even if there is more than one body object.




Code:
'####################################################################
' Journal para calcular la caja mínima de las piezas de un ensamble.
'Crea atributos con los valores de la caja mínima.
'Limitado a un solo cuerpo por pieza.
'Código para recorrer el assembly obtenida de NXJournaling.com February 24, 2012
'Código para crear Csys a partir de una cara obtenido de GTAC: CreateCsysfromPlanarFace
'21.10.2020  Ampliado a varios cuerpos
'21.10.2020  Eliminado atributo CUERPOBRUTO
'21.10.2020  Corregido problema cuando hay más elementos además del cuerpo.
'21.10.2020   Las medidas se ordenan de mayor a menor (X,Y,Z)
' Creado por Javier Axpe

'####################################################################




Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Features
Imports System.Collections.Generic
Imports NXOpen.Utilities
Imports NXOpenUI

Module NXJournal

    Public theSession As Session = Session.GetSession()
    Public theUISession As UI = UI.GetUI
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow
    Dim workPart As Part = theSession.Parts.Work
    Dim theUfSession = UFSession.GetUFSession()
    Dim dispPart As Part = theSession.Parts.Display
    Dim origDisplayPart As Part = theSession.Parts.Display
    Dim origWorkComp As NXOpen.Assemblies.Component = theSession.Parts.WorkComponent
    Dim theUI As UI = UI.GetUI()
    Dim listName As New List(Of String)

    Sub Main()
        'lw.Open()




        Try
            Dim c As ComponentAssembly = dispPart.ComponentAssembly
            'to process the work part rather than the display part,
            '  comment the previous line and uncomment the following line
            'Dim c As ComponentAssembly = workPart.ComponentAssembly
            If Not IsNothing(c.RootComponent) Then
                '*** insert code to process 'root component' (assembly file)
                'lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
                'lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
                '*** end of code to process root component
                reportComponentChildren(c.RootComponent, 0)
            Else
                '*** insert code to process piece part
                lw.WriteLine("Part has no components")
            End If
        Catch e As Exception
            theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
        End Try
        'lw.Close()


        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
        theSession.Parts.SetWorkComponent(origWorkComp, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)



        theUISession.NXMessageBox.Show("Material mínimo", NXMessageBox.DialogType.Information, "Cálculo de caja mínima (medidas Bruto) y volumen de pieza realizado con éxito.")

    End Sub

    '**********************************************************
    Sub reportComponentChildren(ByVal comp As Component,
        ByVal indent As Integer)

        For Each child As Component In comp.GetChildren()
            '*** insert code to process component or subassembly
            'lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
            '*** end of code to process component or subassembly
            If child.GetChildren.Length <> 0 Then
                '*** this is a subassembly, add code specific to subassemblies
                'lw.WriteLine(New String(" ", indent * 2) &
                '    "* subassembly with " &
                '    child.GetChildren.Length & " components")
                'lw.WriteLine(New String(" ", indent * 2) &
                '    " + Active Arrangement: " &
                '    child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
                '*** end of code to process subassembly
            Else
                'this component has no children (it is a leaf node)
                'add any code specific to bottom level components
                Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
                theSession.Parts.SetWorkComponent(child, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)


                'Try

                '    Dim marcaProcesado = theSession.Parts.Work.GetStringAttribute("CUERPOBRUTO")

                'Catch

                Dim strFindString = child.Name

                If listName.Contains(strFindString) Then

                Else

                    listName.Add(child.Name)



                    Try

                        Dim Cuerpos() As Body
                        Cuerpos = AskAllBodies(theSession.Parts.Work)

                        CreateBoundedBox(Cuerpos)


                        theSession.Parts.SetWorkComponent(child, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)
                        Dim actualWorkPart As NXOpen.Part = theSession.Parts.Work
                        theSession.Parts.SetDisplay(actualWorkPart, False, False, partLoadStatus1)

                        Dim objs() As NXObject = theSession.Parts.Work.Layers.GetAllObjectsOnLayer(2)



                        Dim count As Integer = theSession.UpdateManager.AddToDeleteList(objs)

                        Dim undoMark As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Undo Mark")


                        theSession.UpdateManager.DoUpdate(undoMark)
                        theSession.Parts.SetDisplay(dispPart, False, True, partLoadStatus1)



                    Catch

                    End Try

                    'End Try
                End If


            End If
            reportComponentChildren(child, indent + 1)
        Next
    End Sub
    '**********************************************************

    '**********************************************************

    Function AskAllBodies(ByVal thePart As Part) As Body()
        Dim theBodies As New System.Collections.ArrayList()

        Dim aBodyTag As Tag = Tag.Null
        Do
            ufs.Obj.CycleObjsInPart(thePart.Tag,
                UFConstants.UF_solid_type, aBodyTag)
            If aBodyTag = Tag.Null Then
                Exit Do
            End If

            Dim theType As Integer, theSubtype As Integer
            ufs.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
            If theSubtype = UFConstants.UF_solid_body_subtype Then
                theBodies.Add(theSession.GetObjectManager.GetTaggedObject(aBodyTag))

            End If
        Loop While True

        Return DirectCast(theBodies.ToArray(GetType(Body)), Body())
    End Function


    Function CreateBoundedBox(ByVal cuerpos() As Body)

        Dim tempWorkPart As Part = theSession.Parts.Work


        Dim nullNXOpen_Features_ToolingBox As NXOpen.Features.ToolingBox = Nothing

        Dim toolingBoxBuilder1 As NXOpen.Features.ToolingBoxBuilder = Nothing
        toolingBoxBuilder1 = tempWorkPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(nullNXOpen_Features_ToolingBox)

        toolingBoxBuilder1.Type = NXOpen.Features.ToolingBoxBuilder.Types.BoundedBlock
        toolingBoxBuilder1.NonAlignedMinimumBox = True

        Dim matrix1 As NXOpen.Matrix3x3 = Nothing
        matrix1.Xx = 1.0
        matrix1.Xy = 0.0
        matrix1.Xz = 0.0
        matrix1.Yx = 0.0
        matrix1.Yy = 1.0
        matrix1.Yz = 0.0
        matrix1.Zx = 0.0
        matrix1.Zy = 0.0
        matrix1.Zz = 1.0
        Dim position1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
        toolingBoxBuilder1.SetBoxMatrixAndPosition(matrix1, position1)


        Dim n As Integer
        n = cuerpos.Length

        Dim bodies1(n) As NXOpen.Body
        Dim body1() As NXOpen.Body = cuerpos

        bodies1 = cuerpos
        Dim bodyDumbRule1 As NXOpen.BodyDumbRule = Nothing
        bodyDumbRule1 = tempWorkPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, True)

        Dim scCollector1 As NXOpen.ScCollector = Nothing
        scCollector1 = toolingBoxBuilder1.BoundedObject

        Dim rules1(0) As NXOpen.SelectionIntentRule
        rules1(0) = bodyDumbRule1
        scCollector1.ReplaceRules(rules1, False)

        Dim selections1(n) As NXOpen.NXObject
        selections1 = bodies1
        Dim deselections1(-1) As NXOpen.NXObject
        toolingBoxBuilder1.SetSelectedOccurrences(selections1, deselections1)

        Dim selectNXObjectList1 As NXOpen.SelectNXObjectList = Nothing
        selectNXObjectList1 = toolingBoxBuilder1.FacetBodies

        Dim objects1(-1) As NXOpen.NXObject
        Dim added1 As Boolean = Nothing
        added1 = selectNXObjectList1.Add(objects1)

        toolingBoxBuilder1.CalculateBoxSize()

        Dim csysorigin1 As NXOpen.Point3d = New NXOpen.Point3d(50.0, 50.0, 50.0)
        toolingBoxBuilder1.BoxPosition = csysorigin1

        Dim nXObject1 As NXOpen.NXObject = Nothing
        nXObject1 = toolingBoxBuilder1.Commit()
        nXObject1.SetName("CAJA_MINIMA")
        toolingBoxBuilder1.Destroy()

        Dim objects2(0) As NXOpen.NXObject
        objects2(0) = tempWorkPart
        Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder
        attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(tempWorkPart, objects2, NXOpen.AttributePropertiesBuilder.OperationType.None)




        Dim featArray() As Features.Feature = theSession.Parts.Work.Features.GetFeatures()

        Dim featEntities() As NXObject




        For Each myFeature As Features.Feature In featArray

            Dim tipo As String
            Dim myBodies() As Body
            Dim myFaces() As Face
            tipo = myFeature.FeatureType.ToString
            If myFeature.FeatureType.ToString = "Tooling Box" Then

                Dim myBodyFeat As Features.BodyFeature = myFeature

                myBodies = myBodyFeat.GetBodies()
                myFaces = myBodies(0).GetFaces()
                Dim face As Face = myFaces(0)
                Dim matrixTag As Tag = Tag.Null
                Dim cSysTag As Tag = Tag.Null
                Dim faceType As Integer = 0
                Dim normalDirection As Integer = 0
                Dim origin As Double() = New Double(2) {}
                Dim dir As Double() = New Double(2) {}
                Dim boundedBox As Double() = New Double(5) {}
                Dim radius As Double = 0
                Dim radiusData As Double = 0
                theUfSession.Csys.AskMatrixOfObject(face.Tag, matrixTag)
                theUfSession.Modl.AskFaceData(face.Tag, faceType, origin, dir, boundedBox, radius, radiusData, normalDirection)
                theUfSession.Csys.CreateTempCsys(origin, matrixTag, cSysTag)
                Dim min_corner(2) As Double
                Dim directions(2, 2) As Double
                Dim distances(2) As Double
                Dim edge_len(2) As String
                ufs.Modl.AskBoundingBoxExact(myBodies(0).Tag, cSysTag, min_corner, directions,
                distances)


                Dim theObject(0) As Body


                theObject(0) = myBodies(0)
                Dim myMeasure As MeasureManager = theSession.Parts.Display.MeasureManager()
                Dim massUnits(4) As Unit
                massUnits(0) = theSession.Parts.Display.UnitCollection.GetBase("Area")
                massUnits(1) = theSession.Parts.Display.UnitCollection.GetBase("Volume")
                massUnits(2) = theSession.Parts.Display.UnitCollection.GetBase("Mass")
                massUnits(3) = theSession.Parts.Display.UnitCollection.GetBase("Length")

                Dim mb As MeasureBodies = Nothing
                mb = myMeasure.NewMassProperties(massUnits, 0.99, theObject)

                Dim objectArray1(0) As NXOpen.DisplayableObject

                Dim body2 As NXOpen.Body = myBodies(0)

                objectArray1(0) = body2

                tempWorkPart.Layers.ApplyMoveToLayerToOwningParts(2, objectArray1)

                objectArray1(0).Highlight()
                objectArray1(0).Blank()

                Dim nXObject2 As NXOpen.NXObject



                Dim listMedidas As New List(Of Integer)



                listMedidas.Add(CInt(distances(0)))
                listMedidas.Add(CInt(distances(1)))
                listMedidas.Add(CInt(distances(2)))

                listMedidas.Sort(Function(valueA, valueB) valueB.CompareTo(valueA))

                attributePropertiesBuilder1.Category = "BRUTO"
                attributePropertiesBuilder1.Title = "BRUTO_X"
                attributePropertiesBuilder1.StringValue = listMedidas(0).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()

                attributePropertiesBuilder1.Category = "BRUTO"
                attributePropertiesBuilder1.Title = "BRUTO_Y"
                attributePropertiesBuilder1.StringValue = listMedidas(1).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()

                attributePropertiesBuilder1.Category = "BRUTO"
                attributePropertiesBuilder1.Title = "BRUTO_Z"
                attributePropertiesBuilder1.StringValue = listMedidas(2).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()

                attributePropertiesBuilder1.Category = "BRUTO"
                attributePropertiesBuilder1.Title = "MEDIDAS_BRUTO"
                attributePropertiesBuilder1.StringValue = listMedidas(0).ToString & " x " & listMedidas(1).ToString & " x " & listMedidas(2).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()



                attributePropertiesBuilder1.Title = "VOLUMEN"
                attributePropertiesBuilder1.StringValue = CInt(mb.Volume).ToString
                nXObject2 = attributePropertiesBuilder1.Commit()

                attributePropertiesBuilder1.Title = "PESO"
                attributePropertiesBuilder1.StringValue = mb.Weight.ToString
                nXObject2 = attributePropertiesBuilder1.Commit()



                attributePropertiesBuilder1.Destroy()

            End If


        Next





    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function


End Module

Regards,
Javier
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top