Showing results for 
Search instead for 
Do you mean 
Reply

Objects in bounding box

Is there a way to get all objects within a certain defined bounding box?

2 REPLIES

Re: Objects in bounding box

i worked on something similar, i'll see if i can dig up the code. For now, you can use this to write a bounding box journal

 

 blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature)


blockFeatureBuilder1.SetHeight(str(h))
blockFeatureBuilder1.SetWidth(str(w))
blockFeatureBuilder1.SetLength(str(l))
blockFeatureBuilder1.Origin=originpt
bodyFeat=blockFeatureBuilder1.CommitFeature()
bodies=bodyFeat.GetBodies()   

   #calculates the bounding box and then creates a box via the "create box command"
        for body in bodies:
            global xmin, ymin, zmin, directions, distances, min_corner, zvector

            #method for getting bounding box, using a tuple
            (min_corner, directions, distances) = self.theUfSession.ModlGeneral.AskBoundingBoxExact(body.Tag, 0)

            #this is the origin
            xmin=min_corner[0]
            ymin=min_corner[1]
            zmin=min_corner[2]

        # create box command

        box_builder = workPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(NXOpen.Features.ToolingBox.Null)

        #create instance of a class
        matrix = NXOpen.Matrix3x3()

        #defining attributes
        matrix.Xx = 1.0
        matrix.Xy = 0.0
        matrix.Xz = 0.0
        matrix.Yx = 0.0
        matrix.Yy = 1.0
        matrix.Yz = 0.0
        matrix.Zx = 0.0
        matrix.Zy = 0.0
        matrix.Zz = 1.0

        #get origin from ask_bounding box function
        xmid=min_corner[0]+(distances[0]/2)
        ymid=min_corner[1]+(distances[1]/2)
        zmid=min_corner[2]+(distances[2]/2)
        #ex) min_corner=[-24.7,-24.7,0.0], [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)], [49.4, 49.4, 29.0]

        #sets origin of bounding box
        boxorigin = NXOpen.Point3d(xmid, ymid, zmid)

        #call create_box method
        box_builder.SetBoxMatrixAndPosition(matrix, boxorigin)

        box_builder.XValue.RightHandSide = str(distances[0])

        box_builder.YValue.RightHandSide = str(distances[1])

        box_builder.ZValue.RightHandSide = str(distances[2])

#call bounding box methods
box_builder.CalculateBoxSize()
box_builder.Commit()
box_builder.Destroy()

Re: Objects in bounding box

 

We have the functions, but you'll need to do a little clever programming.

 

For details, see the Overview in the uf_fltr.h chapter of the Open C Reference Guide.  I think the two you will help the most are

 

UF_FLTR_create_box_zone() and UF_FLTR_is_obj_inside_box_zone().

 

These are wrapped for use in .Net, but it is important that you read the docs for the original methods in the Open C Reference.