# The size and position of the bounding box

**URL:** <https://discourse.slicer.org/t/the-size-and-position-of-the-bounding-box/44289>\
**Category:** Support\
**Created:** [August 31, 2025, 11:22am UTC](https://discourse.slicer.org/t/the-size-and-position-of-the-bounding-box/44289 "2025-08-31T11:22:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Konstantin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/konstantin/32/80910_2.png) [@Konstantin](https://discourse.slicer.org/u/Konstantin)\
**Post date:** [August 31, 2025, 11:22am UTC](https://discourse.slicer.org/t/the-size-and-position-of-the-bounding-box/44289/1 "2025-08-31T11:22:44Z")

</div>

Hello. How can I make the position and dimensions of the bounding box like the 3D model?

 ![bounding box](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/e/ee3e0df38656e6ff02d977c47fb3e40e1aa85d04.png)

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 1, 2025, 9:14am UTC](https://discourse.slicer.org/t/the-size-and-position-of-the-bounding-box/44289/2 "2025-09-01T09:14:38Z")

</div>

I asked the AI to write me such a script, and it works (I tried it):

```auto
import vtk
import slicer

def createBoundingBoxModel(inputModelNode, boundingBoxModelName="BoundingBox"):
    """
    Create a model node that represents the bounding box of the input model.
    
    Args:
        inputModelNode: The model node whose bounding box to visualize
        boundingBoxModelName: Name for the new bounding box model node
        
    Returns:
        The created bounding box model node
    """
    if not inputModelNode or not inputModelNode.GetPolyData():
        raise ValueError("Invalid input model node")
    
    # Get bounding box of the input model
    bounds = inputModelNode.GetPolyData().GetBounds()
    # bounds = [xmin, xmax, ymin, ymax, zmin, zmax]
    
    # Create a cube source with the bounding box dimensions
    cubeSource = vtk.vtkCubeSource()
    cubeSource.SetBounds(bounds)
    cubeSource.Update()
    
    # Alternative approach: Create cube and transform it
    # center = [(bounds[0] + bounds[1])/2, (bounds[2] + bounds[3])/2, (bounds[4] + bounds[5])/2]
    # size = [bounds[1] - bounds[0], bounds[3] - bounds[2], bounds[5] - bounds[4]]
    # cubeSource.SetCenter(center)
    # cubeSource.SetXLength(size[0])
    # cubeSource.SetYLength(size[1])
    # cubeSource.SetZLength(size[2])
    
    # Create a new model node for the bounding box
    boundingBoxModelNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode", boundingBoxModelName)
    boundingBoxModelNode.SetAndObservePolyData(cubeSource.GetOutput())
    
    # Create display node to make it visible
    boundingBoxModelNode.CreateDefaultDisplayNodes()
    displayNode = boundingBoxModelNode.GetDisplayNode()
    
    # Configure display properties for wireframe representation
    displayNode.SetRepresentation(displayNode.WireframeRepresentation)
    displayNode.SetColor(1.0, 1.0, 0.0) # Yellow color
    displayNode.SetLineWidth(2)
    displayNode.SetOpacity(0.8)
    
    return boundingBoxModelNode

```
