part 4
Code literacy
present →How a script talks to Rhino, the six pieces of any program, and GitHub.
Back to the stack. We have covered company and model and harness (app or agent) and connection. Now: code literacy. How do I read a script the agent wrote? What is RhinoCommon, and how do I ask for it? Where does the team keep its scripts?
Everything you do with the mouse in Rhino is code underneath: typing Point and clicking is the same as the line rs.AddPoint(0, 0, 0). Rhino has two doors for scripts. rhinoscriptsyntax is the simple one: one line per action, much like the commands. RhinoCommon is the complete one: the parts Rhino itself is built from, with all the power and more words. And the simple one is built on top of the complete one: inside, rs.AddPoint calls RhinoCommon. RhinoCommon has four main areas: the application and document, geometry, the document's objects such as layers and attributes, and user input and files. It's also what C# and Grasshopper use. When you ask the agent for something, tell it Rhino 8, Python 3 and the library; otherwise it guesses.
- RhinoCommon
- The (.NET) programming interface Rhino is built on. Used from Python, C# and Grasshopper.
- rhinoscriptsyntax
- A simpler Python library built on top of RhinoCommon: one line per action, less complete.
We won't write code: we'll learn to read it, to review what the agent writes. Every program, in any language, is built from six pieces: variable, list, dictionary, function, loop and if. We see them by running a script that places circles in a row. Variables: how many circles and how far apart. A dictionary with three named sizes. An if that checks they don't overlap. A function that computes each center. A list to keep them and a loop to go through them. Before each step, ask the group what will happen. At the end we switch to “grande”: without the if, the circles overlap; with it, the spacing adjusts. It's an edge case: name it in the prompt to the agent.
- Variable
- A name that holds a value, for example radio = 1.0.
- List
- An ordered collection of values, like the list of circle centers.
- Dictionary
- A table of key → value pairs, like named size → radius.
- Function
- A named, reusable recipe: it takes data and returns a result.
- Loop (for)
- Repeating the same instructions for each item, like drawing a circle at each center.
- Condition (if)
- Doing something only when a condition is met.
- Edge case
- An unusual situation the code must account for, like overlapping circles or a nested layer.
GitHub is where a team keeps its code and its whole history. The repository is the project folder, like the document control archive. Each commit is a saved version with a note, like an issued revision. A branch is a parallel line of work on a copy, like testing a design option. A pull request proposes merging that line into the main one, with a review before issuing. Clone, push and pull are copying it down, sending your changes up, and bringing others' in: syncing with the central file. That way one person's script becomes the whole team's, and an agent can read and write the repository too.
- Repository
- A project's folder on GitHub, with the full history of every change.
- Commit
- A saved version of the code, with a note on what changed.
- Branch
- A parallel line of work, on a copy, to try things without affecting the main one.
- Pull request
- A proposal to merge a branch into the main line, with review.
- Clone, push, pull
- Copying the repository down, sending your changes up, and bringing others' changes in.
Thank you. All the material stays on the workshop site, with every part to read or present and the full glossary.