Queries

Extract measurements, properties, and geometric information from your CAD models

Overview

Query operations allow you to extract information from your CAD models without modifying them. These commands are essential for verification, analysis, and ensuring your designs meet specifications.

Queries return numerical values or data structures containing measurements, properties, and geometric characteristics. They are non-destructive and can be called multiple times on the same shape.

Commands

measure

Calculates linear dimensions of a shape's bounding box. Returns the maximum extent of the shape along each axis.

Parameters:

  • shape - The shape object to measure

Returns:

  • length - Size along X axis (mm)
  • width - Size along Y axis (mm)
  • height - Size along Z axis (mm)
// Measure a simple box
box = create_box(50, 30, 20)
dimensions = measure(box)
// Returns: {length: 50, width: 30, height: 20}

// Measure a complex shape
cylinder = create_cylinder(radius=25, height=60)
sphere = create_sphere(radius=25)
sphere = translate(sphere, 0, 0, 60)
combined = union(cylinder, sphere)
dims = measure(combined)
// Returns bounding box dimensions: {length: 50, width: 50, height: 110}

// Verify dimensions after transforms
rotated = rotate(box, "Z", 45)
new_dims = measure(rotated)
// Bounding box will be larger due to rotation

Note: The measure() command returns the axis-aligned bounding box, not the actual geometric dimensions. Rotated shapes will have larger bounding boxes.

volume

Calculates the total volume of a shape in cubic millimeters. Useful for material calculations, weight estimation, and verification.

Parameters:

  • shape - The shape object to analyze

Returns:

  • volume - Volume in cubic millimeters (mm³)
// Calculate volume of a box
box = create_box(10, 10, 10)
vol = volume(box)
// Returns: 1000.0 mm³

// Volume of a cylinder
cylinder = create_cylinder(radius=10, height=50)
cyl_vol = volume(cylinder)
// Returns: ~15707.96 mm³ (π × r² × h)

// Volume after boolean operations
outer = create_cylinder(radius=20, height=100)
inner = create_cylinder(radius=15, height=105)
inner = translate(inner, 0, 0, -2.5)
hollow_tube = cut(outer, inner)
tube_vol = volume(hollow_tube)
// Returns volume of material remaining

// Estimate weight (volume × density)
part = create_box(100, 50, 25)
part_vol = volume(part)  // 125000 mm³
// Aluminum density: 2.7 g/cm³ = 0.0027 g/mm³
weight_grams = part_vol * 0.0027  // ~337.5 grams

area

Calculates the total surface area of a shape in square millimeters. Important for coating calculations, heat transfer analysis, and material finishing.

Parameters:

  • shape - The shape object to analyze

Returns:

  • area - Surface area in square millimeters (mm²)
// Calculate surface area of a box
box = create_box(10, 20, 30)
surface = area(box)
// Returns: 2200.0 mm² (2 × (10×20 + 10×30 + 20×30))

// Surface area of a sphere
sphere = create_sphere(radius=15)
sphere_area = area(sphere)
// Returns: ~2827.43 mm² (4 × π × r²)

// Area after adding features
base = create_box(100, 100, 10)
pocket = create_cylinder(radius=20, height=6)
pocket = translate(pocket, 50, 50, 4)
machined_part = cut(base, pocket)
total_area = area(machined_part)
// Surface area increases due to the pocket

// Calculate paint needed (area × coating thickness)
part = create_box(200, 150, 50)
surf_area = area(part)  // mm²
coating_thickness = 0.05  // mm
paint_volume = surf_area * coating_thickness  // mm³

center_of_mass

Determines the center of mass (centroid) of a shape, assuming uniform density. Returns the X, Y, Z coordinates of the balance point.

Parameters:

  • shape - The shape object to analyze

Returns:

  • x - X coordinate of center of mass (mm)
  • y - Y coordinate of center of mass (mm)
  • z - Z coordinate of center of mass (mm)
// Center of mass of a symmetric box
box = create_box(20, 20, 20)
com = center_of_mass(box)
// Returns: {x: 10, y: 10, z: 10} (center of the box)

// Center of mass of offset shape
cylinder = create_cylinder(radius=10, height=50)
cylinder = translate(cylinder, 30, 0, 0)
cyl_com = center_of_mass(cylinder)
// Returns: {x: 30, y: 0, z: 25}

// Center of mass after boolean operations
base = create_box(100, 100, 20)
base = translate(base, 0, 0, 0)
weight = create_cylinder(radius=15, height=40)
weight = translate(weight, 80, 80, 20)
assembly = union(base, weight)
asm_com = center_of_mass(assembly)
// Returns coordinates shifted toward the heavier side

// Verify balance point for mechanical design
lever_arm = create_box(200, 20, 10)
lever_arm = translate(lever_arm, -100, 0, 0)
fulcrum = center_of_mass(lever_arm)
// Place pivot at fulcrum.x for balance

Note: The center of mass calculation assumes uniform material density throughout the shape. For multi-material parts, manual calculations will be needed.

Practical Applications

Design Verification

// Ensure a part fits within size constraints
enclosure = create_box(95, 95, 45)
internal_component = create_box(90, 90, 40)
internal_component = translate(internal_component, 2.5, 2.5, 2.5)

// Verify clearance
dims = measure(internal_component)
if dims.length > 90 or dims.width > 90 or dims.height > 40:
    print("Warning: Component exceeds maximum dimensions!")

// Check volume for 3D printing material estimation
print_vol = volume(enclosure)
print_time_hours = print_vol / 15000  // Rough estimate at 15000 mm³/hour

Material Cost Estimation

// Calculate material costs
part = create_box(150, 100, 50)
mounting_holes = []
for x in [20, 80, 140]:
    for y in [20, 80]:
        hole = create_cylinder(radius=4, height=52)
        hole = translate(hole, x, y, -1)
        mounting_holes.append(hole)

final_part = cut(part, *mounting_holes)

// Material calculations
part_volume = volume(final_part)  // mm³
aluminum_density = 0.0027  // g/mm³
part_weight = part_volume * aluminum_density  // grams
material_cost_per_kg = 15  // dollars
total_cost = (part_weight / 1000) * material_cost_per_kg

print(f"Part weight: {part_weight:.2f}g")
print(f"Material cost: ${total_cost:.2f}")

Assembly Balance Analysis

// Create an asymmetric assembly
base_plate = create_box(200, 100, 10)
heavy_component = create_box(50, 50, 80)
heavy_component = translate(heavy_component, 150, 25, 10)
assembly = union(base_plate, heavy_component)

// Find center of mass
com = center_of_mass(assembly)
print(f"Center of mass: X={com.x:.2f}, Y={com.y:.2f}, Z={com.z:.2f}")

// Determine if additional counterweight is needed
if com.x > 100:  // More than halfway along base
    print("Assembly is unbalanced - add counterweight on left side")
    counterweight_offset = com.x - 100
    print(f"Suggested counterweight position: X={counterweight_offset:.2f}")

Quality Assurance Checks

// Automated quality checks
def verify_part(shape, specs):
    """Verify part meets specifications"""
    results = {}

    # Check dimensions
    dims = measure(shape)
    results['length_ok'] = abs(dims.length - specs['length']) < specs['tolerance']
    results['width_ok'] = abs(dims.width - specs['width']) < specs['tolerance']
    results['height_ok'] = abs(dims.height - specs['height']) < specs['tolerance']

    # Check volume (for material usage)
    vol = volume(shape)
    results['volume'] = vol
    results['volume_ok'] = vol < specs['max_volume']

    # Check surface area (for coating requirements)
    surf = area(shape)
    results['surface_area'] = surf

    # Verify center of mass for stability
    com = center_of_mass(shape)
    results['center_of_mass'] = com
    results['balanced'] = abs(com.x - specs['length']/2) < 10  # Within 10mm of center

    return results

# Run verification
specs = {
    'length': 100,
    'width': 50,
    'height': 30,
    'tolerance': 0.5,
    'max_volume': 150000
}

my_part = create_box(100, 50, 30)
verification = verify_part(my_part, specs)
print(verification)

Best Practices

  • Use queries during development to verify your design meets requirements before manufacturing
  • Run volume and area calculations to estimate material costs and production time
  • Check center of mass for mechanical assemblies to ensure proper balance and stability
  • Remember that measure() returns bounding box dimensions, not actual geometry - for precise measurements, consider the shape's orientation
  • Store query results in variables for reuse rather than calling the same query multiple times
  • Use queries to validate that boolean operations (cut, union) produced the expected results
  • Consider creating utility functions that combine multiple queries for common verification tasks

Units Reference

Linear Dimensions

  • • Default unit: millimeters (mm)
  • • 1 inch = 25.4 mm
  • • 1 cm = 10 mm
  • • 1 m = 1000 mm

Volume

  • • Default unit: cubic millimeters (mm³)
  • • 1 cm³ = 1000 mm³
  • • 1 liter = 1,000,000 mm³
  • • 1 in³ = 16,387 mm³

Area

  • • Default unit: square millimeters (mm²)
  • • 1 cm² = 100 mm²
  • • 1 m² = 1,000,000 mm²
  • • 1 in² = 645.16 mm²

Common Densities

  • • Aluminum: 0.0027 g/mm³
  • • Steel: 0.0078 g/mm³
  • • Plastic (PLA): 0.00124 g/mm³
  • • Brass: 0.0085 g/mm³