Bounding Ruler filter: adding an option to show X, Y, Z delta

Thanks for your help. I leave this script to calculate the delta here in case anyone needs

import os
import csv

# Function to generate a unique file name
def get_unique_filepath(basepath, index):
    return f"{basepath}_{index}.csv"

# Base filepath (directory + base name)
base_filepath = 'C:/Users/Dustwun/Desktop/firebrand_test_detector'  # Define your base path

# Function to calculate delta from bounding box
def calculate_delta(bounds):
    xmin, xmax, ymin, ymax, zmin, zmax = bounds
    delta_x = xmax - xmin
    delta_y = ymax - ymin
    delta_z = zmax - zmin
    return delta_x, delta_y, delta_z

# Get the bounding box points from the active source
bounding_box = GetActiveSource().GetDataInformation().GetBounds()
if not bounding_box:
    raise ValueError("Bounding box could not be retrieved. Ensure the active source has valid bounds.")

# Calculate delta values
delta_x, delta_y, delta_z = calculate_delta(bounding_box)

# Get the current time step from the time manager
time_keeper = GetTimeKeeper()
current_time_step = time_keeper.Time

# Generate a unique file name to prevent overwriting
index = 1
filepath = get_unique_filepath(base_filepath, index)
while os.path.exists(filepath):
    index += 1
    filepath = get_unique_filepath(base_filepath, index)

# Write to CSV
with open(filepath, mode='w', newline='') as file:
    writer = csv.writer(file)
    writer.writerow(['ObjectID', 'Delta_X', 'Delta_Y', 'Delta_Z'])
    writer.writerow([current_time_step, delta_x, delta_y, delta_z])

# Optional: Print the dimensions for verification
print(f'Bounding Box Deltas (X, Y, Z): {delta_x}, {delta_y}, {delta_z}')
print(f'Data saved to: {filepath}')
print(f'ObjectID (Time Step): {current_time_step}')

1 Like