cancel
Showing results for 
Search instead for 
Did you mean: 

Toolingboxbuilder created boundingblock not selectable by name

Creator
Creator

Hi,

I'm using NXopen in NX11.

I'm having trouble selecting a boundingblock that I've created with the toolinboxbuilder function.

Creating a boundingblock works fine, I give it a "newName"with the setname method.

And here seems to be a bug... The given name is added to the automatic created name for example: ...setname("NEWNAME") will show in NX as": Bounding Body (1)"NEWNAME" However, if you check the properties of the object, it will show NEWNAME as object name...

If I later try to select the object by using FindObject("NEWNAME") (full code:  Dim body1 As NXOpen.Body = CType(workPart.Bodies.FindObject("NEWNAME"), NXOpen.Body) )

It doesn't select the desired object...

 

Is it a bug or am I missing something?

 

Thanks

 

 

6 REPLIES

Re: Toolingboxbuilder created boundingblock not selectable by name

Phenom
Phenom

The name is being applied to the feature that gets created, not the body it produces.

You'll have to find the feature by name and then call it's getEntities() method which should return the solid body.

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Toolingboxbuilder created boundingblock not selectable by name

Creator
Creator

Hi Inch,

 

I tried to get the feature name by using ".GetFeatureName()" on the created boundingblock, but I get the error "GetFeatureName' is not a member of 'NXOpen.NXObject"

Do you have some vb code as example how to fix this?

 

Thanks!

 

Re: Toolingboxbuilder created boundingblock not selectable by name

Phenom
Phenom

I have no idea how you are creating the 'boundingblock' or even what that is(Man Wink). However the fact that you said it appears as 'Bounding Body (1)"NEWNAME"' shows it is a feature.

The error saying "GetFeatureName' is not a member of 'NXOpen.NXObject" indicates that however you create the 'boundingblock' is returning a simple NXObject. You probably need to cast that to some other feature based object.

If you posted some of your code it would help to understand what you are doing. Use the insert code function for best results:

InsertCode.png

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Toolingboxbuilder created boundingblock not selectable by name

Creator
Creator

Hi Inch,

 

Here is some code...

Dim nullNXOpen_Features_ToolingBox As NXOpen.Features.ToolingBox = Nothing

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

        toolingBoxBuilder1.Type = NXOpen.Features.ToolingBoxBuilder.Types.BoundedBlock`


        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 faces1() As Face
        faces1 = thisBody.GetFaces()
        Dim nrFaces As Integer
        nrFaces = faces1.Length

        Dim faceDumbRule1 As NXOpen.FaceDumbRule = Nothing
        faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(faces1)

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


        bodies1(0) = body1
        Dim nrBodies As Integer = 1
        Dim bodyDumbRule1 As NXOpen.BodyDumbRule = Nothing
        bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, True)

  Dim edges1 As Edge()
        edges1 = thisBody.GetEdges
        Dim nrEdges As Integer
        nrEdges = edges1.Length


        Dim edgeDumbRule1 As NXOpen.EdgeDumbRule = Nothing
        edgeDumbRule1 = workPart.ScRuleFactory.CreateRuleEdgeDumb(edges1)

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

        Dim rules1(3) As NXOpen.SelectionIntentRule
        rules1(0) = faceDumbRule1
        rules1(1) = bodyDumbRule1
        rules1(2) = edgeDumbRule1
   scCollector1.ReplaceRules(rules1, False)

Dim selection As Integer
        selection = nrFaces + nrEdges + nrBodies
 selection = selection - 1

        Dim selections1(selection) As NXOpen.NXObject

 Dim aantalFaces As Integer
        Dim aantalEdges As Integer
        Dim aantalBodies As Integer
        ' Dim aantalPoints As Integer
        Dim aantalSelection As Integer = 0


        For aantalFaces = 0 To nrFaces - 1
            selections1(aantalSelection) = faces1(aantalFaces)
            aantalSelection = aantalSelection + 1

        Next aantalFaces

 For aantalBodies = 0 To nrBodies - 1
            selections1(aantalSelection) = bodies1(aantalBodies)
            aantalSelection = aantalSelection + 1
        Next aantalBodies


        For aantalEdges = 0 To nrEdges - 1
            selections1(aantalSelection) = edges1(aantalEdges)
            aantalSelection = aantalSelection + 1
        Next aantalEdges

      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 boundingBlockObject As NXOpen.NXObject = Nothing
        boundingBlockObject = toolingBoxBuilder1.Commit()

        Dim nameBoundingBlock As String = boundingBlockObject.GetFeatureName()

The last part is where I'm having trouble...

Re: Toolingboxbuilder created boundingblock not selectable by name

Phenom
Phenom

OK, change the end of the code from:

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

To something like:

Dim boundingBlockObject As NXOpen.Feature = Nothing
        boundingBlockObject = toolingBoxBuilder1.CommitFeature()
Dim tb As NXOpen.Features.ToolingBox = CType(boundingBlockObject, NXOpen.Features.ToolingBox)
Dim bodies() As Body = tb.GetBodies()
For Each bd As Body in bodies
' Do whatever you like with each body
Next

You'll almost definitely only get 1 body returned, so the loop is probably not necessary.

Note that I don't use VB, so I haven't tested this, but it should be basically correct.

 

EDIT: Added the CType to cast from generic Feature to ToolingBox

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Toolingboxbuilder created boundingblock not selectable by name

Creator
Creator

Hi Inch,

 

Thanks man, I've been f*cking around on this one for hours...

You realy helped me out!

 

Cheers!