Example Scripts#

The scripts/ directory contains ready-to-run example scripts demonstrating the routing library across a range of scenarios, folder by folder. To pick a script from what you want to do, see Use Cases: Which Script to Start From.

Simple Test Cases (scripts/simple_test_cases/)#

Most of these scripts use the window case, a small window-frame assembly (data/step/Cas_test_windows_V5.step), and are the best starting point.

Script

Description

window_test_case.py

Start here. Full routing workflow: load STEP file, define pipe types and ports, build a CadMap, run pathfinding (A*), visualize results, run optimization. Matches the Tutorial: Routing Pipes Through a CAD Assembly tutorial.

window_test_case_multi.py

Multi-grid version of the window test case: the map cut into several grids at one voxel size. Includes bifurcation point detection.

window_test_case_multi_scale.py

Multi-scale version (size_factor=3): a coarse grid completed by a finer one, searched with Theta*.

shaped_zone_example.py

Demonstrates the zone rules: an attractive and a repulsive WeightedZone (cone, box), a ForbiddenZone cutting the ports it catches, and a ForcedZone every conduit is routed through. Matches the Tutorial: Routing Zones tutorial.

shaped_zone_example_multi.py

Multi-grid version of the zones example; two conduits whose cut ports the packs wall in are left unrouted, as the 3D view shows.

shaped_zone_example_multi_scale.py

Multi-scale (coarse and fine grids) version of the zones example.

window_forced_zones.py

The window case forced through three zones, against the same case routed without them: zones order, tunnels taken, length and detour per conduit.

constraint_rules_example.py

Demonstrates constraint rules: ClampingConstraint, GravityRule, StraightLengthRule, DistanceAttributeToggler, and a custom UserDefinedConstraint. Matches the Tutorial: Engineering Design Rules tutorial.

labyrinth_toggled_constraint.py

A custom length rule on a toggled attribute, routed on one grid and on coarse and fine grids of the large room, with a check of what the search counted and charged.

large_room_with_obstacles.py

Routing in a large space with multiple obstacles using the multi-scale approach. Useful reference for real-size assemblies. Matches the Tutorial: Routing in Large Spaces with Obstacles tutorial.

specification_from_spreadsheet.py

Loads pipe types and specifications from Excel (.xlsx) and CSV files via from_xlsx() / from_csv(). Matches the Tutorial: Defining Specifications in a Spreadsheet tutorial.

cube_case.py

Routes a pipe both outside and through the interior of a single cube, contrasting the default obstacle behavior with voxel_inside=True. Matches the Tutorial: Routing Inside a Closed Volume tutorial.

weighting_overwrite_case.py

The window case with the outer volume overriding the composed weights up to 0.1 m from itself (RuledVolume.overwrite_distance), generation only, then the same routing without the override to measure what it changed.

window_input_data.py

Input data module shared by many test scripts: defines multiple pipe types and their port configurations. Import as a module rather than running directly.

packing_metrics.py

Helpers parallel_packs/ramp_room_test_case.py imports: six numbers to judge how tight the packs are. Import as a module rather than running directly.

For pathfinding without a CAD file, see the examples of Tutorial: 3D Pathfinding with routing.pathfinding and Tutorial: Smoother Paths with Theta*.

Tees (scripts/route_planning/)#

Conduits tapping other conduits, on the window case. See Tutorial: Tees — Tapping a Routed Conduit.

Script

Description

window_tees.py

Tees in automatic mode: four conduits and seven tees given out of order — one tee at a declared site, one explored every 0.3 m, a tee of a tee — generated, optimized, summarized. Matches the Tutorial: Tees — Tapping a Routed Conduit tutorial.

window_tees_by_hand.py

The same tees with the cycle held by hand: the conduits generated, one picked and optimized; the tees declared on the routed conduits, generated and optimized alone; a tee explored before it is laid, picked near a point, optimized alone.

window_tees_base.py

Inputs shared by the two tee scripts: the window map, the conduits tapped, the tee pipe types and the tees. Import as a module rather than running directly.

Trays (scripts/parallel_packs/)#

Pipes pooled as trays (parallel=True): side by side on the face they run along, in layers. See Parallel Packs: Trays.

Script

Description

ramp_room_test_case.py

A room with a floor, two walls, a ramp up to a mezzanine and obstacles; conduits of four diameters leaving, crossing and joining it, their ports close together or spread. model switches between trays and generic packs; inspect_conduit replays the routing up to one conduit and shows the field it sees.

ramp_room_geometry.py, ramp_room_specifications.py

The room and the conduits of ramp_room_test_case.py. Import as modules rather than running directly.

window_parallel_packs.py

window_test_case.py without the optimization: the window case, its conduits pooled as trays.

large_room_with_obstacles.py

The large room of simple_test_cases/ without the optimization: the labyrinth, its conduits pooled as trays.

parallel_packs_report.py

Helpers ramp_room_test_case.py imports: per tray, its support and its layers cut by cut, and the field it paints for a candidate. Import as a module rather than running directly.

Electrical Harness (scripts/electrical_harness/)#

Routed cables turned into one optimized harness. See User Guide: Harness Generation.

Script

Description

consolidate_topology_window_case.py

One generate_harness() call on the window case: route, bundle, optimize the harness geometry. --smoke runs it on a tiny optimization budget, --headless skips the 3D view.

window_input_data.py

The window inputs with eleven conduits. Import as a module rather than running directly.

optimizer_calibration.py, optimizer_tuning.py

Benches for tuning the harness optimizer, not examples.

Otter Test Cases (scripts/otter_test_cases/)#

More complex test cases based on a multi-part assembly with static and mobile parts, its ports, pipes and cables read from Excel nomenclatures. Run them from their folder: they open ./data relative to the working directory.

Script

Description

DAR_test_case.py

Advanced routing with multiple pipe types, clamping set per pipe type, conduits pooled as trays, and turn penalties. Generates multiple routing solutions and runs simulated annealing optimization. The first run caches the voxelized CAD in processed_data/.

DAR_test_case_multi_grid.py

Multi-grid version of the DAR test case: several grids at one voxel size.

DAR_test_case_multi_scale.py

Multi-scale version with hierarchical resolution levels.

DAR_utils.py

Reads the STEP assembly and the Excel nomenclatures into volumes, ports and pipe types. Import as a module rather than running directly.

Building Test Case (scripts/building_test_case/)#

Routing in a building-scale environment. Run it from its folder: it opens its STEP file relative to the working directory.

Script

Description

building_test_case.py

Sets up a 12.5 m room with obstacles and routes two cables across it, inside the room volume (voxel_inside=True).

GRIT Test Case (scripts/grit_test_case/)#

Script

Description

GRIT_test_case.py

Complex routing scenario with many interconnected cables. Extracts ports from CAD geometry automatically, creates specifications programmatically, and runs the harness pipeline (generate_harness()). Its first run needs vtk to decimate the CAD; run it from its folder.

Running the Scripts#

Most scripts find their data from their own folder and run from anywhere, the repository root included. The industrial cases — otter_test_cases/, building_test_case/ and grit_test_case/ — open files relative to the working directory: run them from their folder.

# From the repository root
python scripts/simple_test_cases/window_test_case.py

# The industrial cases, from their folder
cd scripts/otter_test_cases
python DAR_test_case.py

Data files used by the scripts:

  • data/step/Cas_test_windows_V5.step — the window case

  • data/step/use_case_labyrinth.stp — the large room with obstacles

  • data/json/cubic_volume_model.json — the cube of cube_case.py

  • scripts/test_specification_full.xlsx, scripts/test_pipe_types.csv, scripts/test_specifications.csv — the spreadsheets of specification_from_spreadsheet.py

  • scripts/otter_test_cases/data/Maquette_Dessia_1.3.stp and its Excel nomenclatures — the Otter assembly

  • scripts/building_test_case/routing-room_w_obstacles.step — the building room

  • scripts/grit_test_case/01 Grit4pi_*.stp — the GRIT product