Grasshopper Plugin (Rhino 3D)¶
USC provides 27 custom Grasshopper components for visual parametric workflows in Rhino.

Installation¶
Copy all .ghuser files from grasshopper/USC_GHplugin/ to your Grasshopper User Objects folder, or drag them onto the Grasshopper canvas. Requires Rhino 8 (the components are Python 3 script components).
Updating components on existing canvases¶
Components already placed on a canvas keep the code they were placed with. After installing new .ghuser files, drop USC_SyncCanvas (ribbon: Session) on the canvas:
- Leave
updateunconnected and readreport: it lists which USC components are up to date and which would change. Components whose code you edited by hand count as outdated and would be overwritten. - Connect a Button to
updateand click it. Components whose inputs and outputs are unchanged are replaced in place, keeping position, wires, internalised values (Set One String), graft/flatten/simplify settings, enabled/preview state and group membership. Components whose inputs or outputs changed are placed beside the old one inside a red group that names the new or removed ports: rewire the new component, then delete the old one and the group. - The whole update is one undo step (Ctrl+Z). If anything fails mid-update, the canvas is rolled back and the error appears in
report.
By default the updates come from the installed user objects (Grasshopper's User Objects folders); wire a folder path into folder to update from elsewhere, e.g. grasshopper/USC_GHplugin in a checkout.
Rebuilding the components¶
The .ghuser files are generated from the sources in grasshopper/components/; edit the .py, never the .ghuser. Each source declares its own ports: names and descriptions in its "GH UI" block, order and types in the numpydoc Inputs / Outputs docstring. grasshopper/components.json holds the ribbon subcategory and the stable user-object GUID; icons are grasshopper/icons/<source name>.png (24x24).
Code shared by several components (daemon calls, the run command wrapper run_stages, engine issues shown as warnings by show_issues, loading the engine's mode_registry.py and archetype_defaults.py by path with engine_module, PLY reading and writing, mesh conversion, override parsing) lives in grasshopper/usc_gh.py. The components load it at run time from <carver_root>/grasshopper/, where carver_root is the repository folder given to USC_Session, so editing it takes effect on the next solve without rebuilding any .ghuser. It uses only the standard library, RhinoCommon and the Grasshopper SDK, because the component scripts run in Rhino's own Python, not in the USC environment.
pip install -e .[ghbuild] # pythonnet
python grasshopper/build_ghuser.py # rebuild into USC_GHplugin/
python grasshopper/build_ghuser.py --check # exit 1 if any .ghuser is stale
The builder uses GH_IO.dll from the Rhino 8 install (--ghio <folder> to point elsewhere); Rhino does not need to be running. Rebuilds are byte-for-byte reproducible, so an unchanged source leaves its .ghuser untouched. tests/test_gh_components.py checks that every source's UI block matches its docstring and that every docstring type maps to a Grasshopper type hint.
A component already placed on a saved canvas keeps the code it was placed with; USC_SyncCanvas updates it (see above).
Smoke test in Rhino¶
tools/grasshopper_example_smoke_test.py solves examples/USC_components_for_grasshopper.gh in a running Rhino 8 (through RhinoCode.exe) and compares two runs, for example main against a branch. It needs Rhino open, so it is not part of pytest. Run it with the USC environment's python:
python tools/grasshopper_example_smoke_test.py run main D:\path\to\urbanSolarCarver
python tools/grasshopper_example_smoke_test.py run branch D:\path\to\worktree
python tools/grasshopper_example_smoke_test.py compare main branch
run stops any running daemon, fills the template definition in memory (root panel, output folders, EPW, start_daemon and run toggles, pipeline 1's geometry from examples/test_inputs/multiple_buildings), solves it with the root's usc_gh.py and daemon, stops the daemon again and closes the definition without saving. A root without .venv, venv or python_path.txt (a worktree) gets a python_path.txt pointing at the python running the script. The report (messages and output counts of every USC component) and the output folders go to ~/.urbansolarcarver/gh_runs/<label>, a short path because deep output folders exceed Windows' 260-character limit. Each run keeps its output there (about 120 MB for the example), replaced by the next run with the same label; delete the folder when done. The definition's start_daemon toggle also switches on verbose, so the daemon opens its own console window during a run. With several Rhinos open, pass --rhino <ID> from RhinoCode.exe list.
compare matches components by nickname and occurrence, compares their messages (paths, ids and timings removed) and output counts, the meshes byte for byte, integer and boolean arrays (masks) exactly and float arrays (scores) to a relative difference of 1e-5, since GPU atomic adds sum in a varying order (about 1e-7 between runs). It exits with 1 when anything differs.
Daemon¶
The components send their work to a persistent daemon process that keeps the CUDA context and compiled kernels loaded, so repeated runs skip the start-up cost:
urbansolarcarver daemon start # start GPU daemon
# ... use Grasshopper components ...
urbansolarcarver daemon stop # stop when done
The daemon binds to localhost only. Clients authenticate with a random key that the daemon generates on first start and stores in ~/.urbansolarcarver/.daemon_authkey.
Components¶
The ribbon shows each component as USC <Name> (for example USC Session). Below they are listed by their source file name in grasshopper/components/, grouped by ribbon tab.
Session (0::Session)
- USC_Session: finds the USC Python environment and starts or checks the daemon. Wire a Boolean
Truetostart_daemonto launch the daemon; when the input is unconnected orFalse, the component only reports whether a daemon is running. - USC_SyncCanvas: updates the USC components on the canvas to the installed versions (see Updating components on existing canvases)
Configuration (1::Config)
- USC_Config: builds a pipeline configuration from a mode, an EPW path, an output folder, an optional base YAML and the override strings of the parameter components below. With no YAML, the daemon starts from the mode's starting values (for example the analysis period of the benefit, irradiance and time-based modes) and applies the overrides;
configs/is not read. Spellings such astime_basedortilted-planeare accepted. - USC_Mode: selects the carving mode by number and outputs its name for USC_Config's
modeinput. The mode list and descriptions come from the engine (mode_registry.py), so solve USC_Session first; without it the component shows a message that says so. - USC_EPW (USC EPW Path): passes the EPW file path
- USC_AnalysisPeriod: defines the analysis date/time range
- USC_GridSettings: voxel size, surface sampling spacing (
grid_step), grid padding (margin_frac) - USC_RaySettings: ray length, minimum sun altitude, north direction (
north_deg),context_blocks_rays(Account for context blocking: with context or terrain, whether the rays that hit them are dropped; default true), andrays_per_patch(rays per sky patch in the weighted modes: 1, 4, 9 or 16; default 4) - USC_BenefitParams: benefit-mode hour weighting: balance temperature and offset (simple weights), or a
simulated_weights.jsonartifact plus the experimentalinclude_harmtoggle (simulated weights) - USC_TiltedPlane: fixed-angle envelope parameters
- USC_RadCooling (USC Radiative Cooling): radiative cooling parameters (dew point, Bliss constant)
- USC_Threshold: thresholding strategy, score smoothing, column carve-above post-processing, and the slope limit (
max_slope; empty = 75 degrees for the weighted modes, 90 = off). Connect its output to USC_ThresholdStage'sthreshold_overridesinput (not Config) so threshold changes only re-run thresholding. - USC_Postprocess: smoothing and cleanup settings. Connect its output to USC_Export's
postprocess_overridesinput (not Config) so mesh cleanup changes only re-run export. - USC_Diagnostics: detailed score statistics and diagnostic plot images
Pipeline execution (2::Main)
- USC_RunPipeline: runs all three stages in one go (quick prototyping)
- USC_Preprocess: runs preprocessing only (ray tracing + scoring). Errors turn the component red.
Both take the geometry: max_volume, test_surfaces, and the optional context (existing buildings and large trees that stay) and terrain (the ground), each a list of Meshes or Breps. Context removes every voxel column of the max volume it overlaps and, with context_blocks_rays on, drops the rays that hit it; terrain removes only the voxels below the ground and drops the rays that hit it. See Context and terrain. Leave them unconnected for a run without them.
- USC_ThresholdStage: runs thresholding only. Accepts
threshold_overridesdirectly. Its summary shows the slope limit (angle, voxels removed, share of the obstruction score). Errors turn the component red.
To chain two criteria, give the second one its own Config (a different out_dir), Preprocess and ThresholdStage, and wire the first ThresholdStage's thr_result into the second one's after input (the last input; empty = a single criterion as before). The second stage then decides only among the voxels the first kept and never keeps one it removed. A daemon started before the update cannot chain; the component then says so and asks for a restart from USC_Session.
- USC_Export: runs exporting only. Accepts postprocess_overrides directly. Errors turn the component red.
- USC_Massing: stage 4, builds floor plates from the carving mask (inputs config, thr_result, massing_overrides, run; outputs closed Breps, floor areas per floor and in total, and the plates.json path). See Floor-plate massing.
- USC_MassingSettings: floor heights, module size, tolerance and stacking for USC_Massing. Connect its output to USC_Massing's massing_overrides input so changes re-run only massing.
The stage components send the daemon's run command, each producing its own stage, and read the stage folders from the reply. A stage reads the output of the stage before it from <out_dir>/<stage> of its Config, so Preprocess and the stages after it need the same Config out_dir; the pre_result and thr_result inputs order the solve and still have to be connected. Conditions the engine reports (a setting the mode ignores, nothing carved, a footprint that could not be read, ...) appear as warnings on the component, one per issue, as <stage>: <message>. Re-running preprocessing makes the stages after it refuse their old output until they run again (the error names the stage to re-run).
Simulated weights (3::Weights)
- USC_Archetype: assembles a typical building for the simulated weights from the five parameter families below; every input is optional (neutral defaults, read from the engine's
archetype_defaults.py, so solve USC_Session first) - USC_ZoneGeometry / USC_ZoneFabric / USC_ZoneVent / USC_ZoneOperation / USC_ZoneShading: Honeybee-style family feeders for USC_Archetype: shoebox dimensions + per-facade window-to-wall ratio, envelope U-values + g-value + mass class, air-change rates + heat recovery, how the room runs + setpoints + internal gains + window opening, and declared shading coefficients. Each family is one wire into USC_Archetype.
- USC_Archetype's room runs free unless USC_ZoneOperation's
free_runningis False: no heating or cooling, the two setpoints are the comfort band, and the windows open abovevent_above(default 25 °C) by up tovent_achextra air changes per hour (default 4); the weights count the degree-hours below the band that the sun removes and above it that it adds (Simulated weights: free running). Withfree_runningFalse the room is heated and cooled to the setpoints, and USC_ZoneOperation refusesvent_aboveandvent_ach. USC_SimulateWeights'epsapplies to the heated and cooled room; a free-running one uses 10 W. - USC_SimulateWeights: runs the ISO 13790 5R1C simulation through the daemon; outputs the
simulated_weights.jsonpath (wire into USC_BenefitParams) and a heatmap preview image
Input geometry¶
Context should be closed bodies (Breps or closed Meshes): the voxels it takes are found by an inside test, and an open context gives a context_not_closed warning. Terrain may be an open sheet. A test surface on the face of a context building (a neighbour's facade) is not blocked by that face; one drawn inside a context mass or under the terrain has all its rays blocked and gives a test_points_blocked warning.
Test surfaces must be individual flat panels. If you are using extruded block boundaries or any joined polysurface, explode it into its faces before connecting it to USC_Preprocess. Otherwise the planarity check rejects the combined surface and preprocessing fails with a "No points sampled" error.
Recommended workflow¶
Use the decomposed pipeline (Preprocess → ThresholdStage → Export as separate components) rather than RunPipeline. This lets you:
- Adjust threshold parameters (USC_Threshold → USC_ThresholdStage) and re-export without re-running the expensive ray-tracing step.
- Adjust mesh cleanup settings (USC_PostProcess → USC_Export) and regenerate the mesh without re-thresholding or re-preprocessing.
Only USC_Preprocess needs to re-run when you change geometry, mode, or the analysis period.