--- name: sofistik-rhino-cdb description: Write C# scripts for the Grasshopper C# Script component or the Rhino script editor that read a SOFiSTiK CDB database (*.cdb) through the SOFiSTiK.Analysis.Database assembly - geometry, analysis results, cross sections, tendons and axes. Use this skill whenever the user wants to pull FEA data into Rhino or Grasshopper, mentions a .cdb file, DataAccess, ReadData, KWH/KWL keys, any Cdb* type (CdbNode, CdbBeam, CdbQuad, CdbN_disp, CdbBeam_for, CdbSect_ppt, ...), load cases, support reactions, beam forces, quad stresses, or the SOFiSTiK Rhino Interface. Trigger it even for partial requests like "get the support reactions into Grasshopper", "show me the deformed shape", "which KWH holds beam stresses" or "why is my displacement 1000x too small" - anything that ends in C# touching a CDB. --- # SOFiSTiK CDB access from Rhino / Grasshopper C# Read a `.cdb` with the managed `SOFiSTiK.Analysis.Database` assembly that ships with the SOFiSTiK Rhino Interface, and turn the records into Rhino geometry and flat lists. Targets **SOFiSTiK 2026 and newer**. ## The mental model The CDB is an index-sequential store addressed by two integer keys: - **KWH** - primary key. The category: nodes are 20, beams 100, beam forces 102, nodal results 24, quads 200. - **KWL** - secondary key. Either a fixed number (usually 0 for model data) or, **for every result record, the load case number**. `db.ReadData(kwh, kwl)` returns a heterogeneous `IEnumerable`, because one key can hold several record types at once. `.OfType()` is what picks the one you want - it is load-bearing, not tidiness: ```csharp // 100/0 holds BOTH beams and their section assignments var beams = db.ReadData(100, 0).OfType().ToList(); var sections = db.ReadData(100, 0).OfType().ToList(); ``` The type name tells you the mnemonic in the SOFiSTiK documentation: `CdbBeam_for` is the `BEAM_FOR` record, `CdbN_disp` is `N_DISP`. Field names are the documented item names in PascalCase - `UX` -> `Ux`, `SPAR` -> `Spar`, `MNR` -> `Mnr`. ## Workflow Not every request needs a script. "Which KWH holds beam stresses?", "what unit is `Sigc` in?", "why is my displacement 1000x too small?" are answered from `references/cdb_type_index.md`, `references/units.md` and `scripts/lookup_record.py` directly - answer them and stop. The steps below are for when the user wants code. **No C# before the plan is approved.** Steps 1-3 are cheap and catch the expensive mistakes - a record that does not hold what the user assumed, a unit that is off by 1000, an output shape that does not fit what they want to do next. Those are all far cheaper to fix in a five-line plan than in a written component the user has already pasted into Grasshopper. ### 1. Capture intent Ask only for what you cannot infer: - **What is being read?** Forces, displacements, reactions, stresses, geometry, sections, tendons. - **Which environment?** Grasshopper component or Rhino script editor. "In Grasshopper" or a mention of inputs and outputs means the component; "in Rhino", "as a command", or adding objects to the document means the editor. - **What does the user do with the result?** Display it, tag it, colour it, export it, drive downstream geometry. This decides the output shape more than anything else. - **Scoped to part of the model?** A group, a list of element ids, one load case or several. If the request already answers these, go straight to step 2. ### 2. Find the record and confirm its fields Look up the type and its KWH/KWL in `references/cdb_type_index.md`. The quick table at the top covers most requests; grep the full index for anything else (`grep -i tendon references/cdb_type_index.md`). Never read that file whole - it is ~950 lines. Then confirm the fields, before planning and before writing code: ```bash python scripts/lookup_record.py CdbBeam_for # or 102/LC, or BEAM_FOR ``` That prints the record's item table straight out of `cdbase.txt`, with the unit code for every float. Decode the codes with `references/units.md`. This step takes seconds and prevents the two most common failures: a property that does not exist (the script will not compile) and a value that is silently 1000x off. If a field still looks ambiguous, put that in the plan as an open question rather than inventing a meaning. ### 3. Propose the plan, then stop Write the plan in this format and **end the turn**. Do not write any C# yet. ``` ## Plan: