Creative Coding
for Newbies!

L.E.A.R.N. is a platform dedicated to beginner-friendly creative coding tutorials and exercises for building architecture with robots.

In these tutorials, we will introduce computational methods for architecture, fabrication & construction, incentivising computational literacy. Students will learn the theoretical background and basic implementation details of fundamental datastructures and algorithms, and to plan and control robot tasks in CAD environments using the COMPAS and COMPAS FAB framework, and other open-source libraries.

We want to provide access to our tutorials for as many students as possible. If you are affiliated with TUM or EPFL, you can register for the class. If you are a student from another university or simply interested in Digital Fabrication using robots, you can simply access the tutorial videos through this webpage.

Get Started

Just Start #1
Just Start #2
Python in VS Code
Python in Rhino and Grasshopper
  1. Setting up the Anaconda environment with COMPAS

Execute the commands below in Anaconda Prompt:

(base) conda config --add channels conda-forge
(base) conda create -n learn python=3.8 compas_fab=0.17 --yes
(base) conda activate learn

(base) conda create -n learn python=3.8 compas_fab=0.17 python.app --yes (base) conda activate learn

Verify Installation
(learn) pip show compas_fab ####
Name: compas-fab
Version: 0.13.1
Summary: Robotic fabrication package for the COMPAS Framework
Install on Rhino
(learn) python -m compas_rhino.install

NOTE: This installs to Rhino 6.0, use -v 5.0 or -v 7.0 if needed.

  1. Installation of Dependencies
(learn) conda install git
Assembly Information Model

(learn) python -m pip install git+https://github.com/augmentedfabricationlab/assembly_information_model@master#egg=assembly_information_model (learn) python -m compas_rhino.install -p assembly_information_model

UR Fabrication Control

(learn) python -m pip install git+https://github.com/augmentedfabricationlab/ur_fabrication_control@master#egg=ur_fabrication_control (learn) python -m compas_rhino.install -p ur_fabrication_control

ABB Fabrication Control

(learn) conda install compas_rrc (learn) python -m compas_rhino.install -p compas_rrc

  1. Cloning the Course Repository

Create a workspace directory:


Then open Github Desktop and clone the following repository into you workspace folder: L.E.A.R.N. repository

You can now go to VS Code, Rhino or Grasshopper to run the example files!


Python Basics
Quick start on Python
😎 😎 😎 View the Slides: Python Basics 😎 😎 😎
Datatypes, Operators, and Conditionals
Lists, Tuples, and Dictionaries


Data Type Description Examples
Integers Whole Numbers -2, -1, 0, 1, 2, 3, 4, 5
Floating-point numbers Numbers with decimal point -1.25, -1.0, –0.5, 0.0, 0.5, 1.0, 1.25
Strings Ordered sequence of characters β€˜a’, β€˜aa’, β€˜aaa’, β€˜Hello!’, β€˜11 cats’
List Ordered sequence of objects [10, β€œHello”, 20.3]
Dictonary Unordered key : value pairs {β€œMyKey” : β€œValue”}
Tuples Ordered immutable sequence of objects (10, β€œHello, 20.3)
Set Unordered collection of unique objects {β€œa”, β€œb”}
Bool Logical value indicating True or False True / False


You can name a variable anything as long as it obeys the following rules:

  • It can be only one word.
  • It can use only letters, numbers, and the underscore (_) character.
  • It can’t begin with a number.
  • Variable name starting with an underscore (_) are considered as β€œunuseful`.


    >>> spam = 'Hello'
    >>> spam


Operators Operation Example
** Exponent 2 ** 3 = 8
% Modulus/Remaider 22 % 8 = 6
// Integer division 22 // 8 = 2
/ Division 22 / 8 = 2.75
* Multiplication 3 * 3 = 9
- Subtraction 5 - 2 = 3
+ Addition 2 + 2 = 4

Comparison Operators

a = 3 b = 4

Operators Operation Example
> If the value of left operand is greater than the value of right operand, the condition becomes true (a > b) -> False
< If the value of left operand is less than the value of right operand, the condition becomes true. (a < b) -> True
== If the values of two operands are equal, then the condition becomes true. (a == b) -> False
>= If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. (a >= b) -> False
<= If the value of left operand is less than or equal to the value of right operand, then condition becomes true. (a <= b) -> True
!= If values of two operands are not equal, then condition becomes true. (a != b) -> True

If - elif - else statements


if my_condition is equal a value:
    execute some code
elif my_other_condition is equal another value:
    execute something different
    do something else

While loop


  • repeats statment(s) while a condition is TRUE
  • requires an exit condition
while some_boolean_condition:
    do something
    do something different


break_condition = 0
while break_condition < 10:
    break_condition = break_condition + 1
    print("out of while loop")

For loop

  • iterating over items of a sequence (usually a list)
mylist = [1,2,3,4,5,6,7,8,9,10]
for item in mylist:
  • iterating over numbers in range()
for i in range(0, 10, 2):
  • iterating over characters in a string
for letter in "Python":
    print("current letter: ", letter)
  • iterating over every key in a dictonary
d = {"k1":1, "k2":2, "k3":3}
for item in d:
  • index in range

for index in range(0,len(pets)):
    print(index, pets[index])
  • index and objects in list
for p,x in enumerate(pets):
    print(p, x)
  • BREAK: Breaks out of the current closest enclosing loop
  • CONTINUE: Goes to the top of the closest enclosing loop
  • PASS: Does nothing at all
while True:
    print('Who are you?')
    name = input()
    if name != 'Joe':
    print('Hello, Joe. What is the password? (It is a fish.)')
    password = input()
    if password == 'swordfish':
print('Access granted.')


  • Unlike strings, they are mutable
  • elements inside a list can be changed
>>> spam = ['cat', 'bat', 3, 'elephant']

>>> spam
['cat', 'bat', 'rat', 'elephant']

>>> len(spam)
  • Indexing
>>> spam = ['cat', 'bat', 3, 'elephant']

>>> spam[2]

>>> spam[-1]
  • Slicing
>>> spam = ['cat', 'bat', 3, 'elephant']
>>> spam[0:4]
['cat', 'bat', 3, 'elephant']

>>> spam[1:3]
['bat', 3]

>>> spam[:2]
['cat', 'bat']
  • Reassign
>>> spam = spam + ['add new item']
>>> spam
['cat', 'bat', 3, 'elephant', 'add new item']
  • Create a new list
>>> spam = ['cat', 'bat', 3, 'elephant']
>>> spam.append('append me!')

>>> spam
['cat', 'bat', 3, 'elephant', 'append me!']


  • unordered mappings of stored objects by using a key-value pairing (lists store objects in ordered sequence, can therefore be indeced or sliced)
  • key value: allows to grab an object without knowing the index location
  • {key1:value1, key2:value2} the key itself should always be a string


>>> my_dict = {'key1':'value1', 'key2':'value2', 'key3':'value3'} 

>>> my_dict
{'key1': 'value1', 'key2': 'value2', 'key3':'value3'} 

>>> my_dict['key1']


>>> prices_lookup = {'apples': 2.99, 'oranges': 1.89}

>>> prices_lookup['apples']
  • d.keys(): giving all the key inputs
>>> key = {'color': 'pink', 'age': 22}
>>> for k in key.keys():
>>>     print(k)

  • d.values(): giving all the values
>>> value = {'color': 'pink', 'age': 22}
>>> for v in value.values():
>>>     print(v)

  • d.items(): giving the pairings - (result is also a tuple as it is in ())
>>> item = {'color': 'pink', 'age': 22}
>>> for i in item.items():
>>>     print(i)

('color', 'pink')
('age', 22)


  • for creating a clean, repeatable code
  • allow us to create blocks of code that can be easily executed many times
  • without needing to constantly rewrite the entire block of code


def name_of_function(name):
    do something


>>> def print_hello():
>>>     print("Hello")

>>> print_hello()
>>> def run_check(num,low,high):
>>>     if num in range(low,high):
>>>         print (f"{num} is in the range between {low} and {high}")
>>> run_check(5,2,7)
5 is in the range between 2 and 7

When creating a function using the def statement, you can specify what the return value should be with a return statement. A return statement consists of the following:

  • The return keyword
  • The value or expression that the function should return


  • Write a function that computes the volume of a sphere given its radius.
  • The volume of a sphere is given as \(\frac{4}{3} Ο€r^3\)
>>> import math
>>> def vol(rad=5):
>>>    V = 4/3 * math.pi* rad**3 
>>>    return V

>>> vol()


  • if word starts with a vowel, add β€œay” to end
  • if word does not start with a vowel, put first letter at the end, then add β€œay”
>>> def latin(word):
>>>     first_letter = word[0] 
>>>     if first_letter in "aeiou":
>>>         pig_word = word + "ay"
>>>     else:
>>>         pig_word = word[1:] + first_letter + "ay"        
>>>     return pig_word

>>> latin("apple")


Dataclasses are python classes but are suited for storing data objects. This module provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes.

  • Storing data and representing certain data type
  • Comparing to other objects of the same type


  • representing the instance of a class
  • accessing the attributes and methods of the class in python


  • A reseved method in python classes
  • Called as constructor in object oriented terminology: Called when an object is created from a class and allows the class to initialize the attributes of the class


>>> class Vehicle():
>>>     def __init__(self, colour, nb_wheels, name):
>>>         self.colour = colour
>>>         self.nb_wheels = nb_wheels
>>>         self.name = name
>>> vehicle_1 = Vehicle("blue", 2, "bike")
>>> vehicle_2 = Vehicle("red", 4, "car")

>>> print("This is a " + vehicle_1.colour + " " + vehicle_1.name + " with ", vehicle_1.nb_wheels, " " + "wheels")
This is a blue bike with  2  wheels
>>> print("This is a " + vehicle_2.colour + " " + vehicle_2.name + " with " + str(vehicle_2.nb_wheels) + " " + "wheels")
This is a red car with 4 wheels


  • Find out the cost of a rectangular field with breadth(b=120), length(l=160). It costs x (2000) rupees per 1 square unit:
>>> class Rectangle:
>>>    def __init__(self, length, breadth, unit_cost=0):
>>>        self.length = length
>>>        self.breadth = breadth
>>>        self.unit_cost = unit_cost
>>>    def get_area(self):
>>>        return self.length * self.breadth
>>>    def calculate_cost(self):
>>>        area = self.get_area()
>>>        return area * self.unit_cost
>>> r = Rectangle(160, 120, 2000)
>>> print("Area of Rectangle: %s sq units" % (r.get_area()))

Area of Rectangle: 19200 sq units


  • getting access to code from another module by importing file/function
  • import module_name:
>>> import math
>>> print(math.pi)

  • import module_name.member_name
>>> from math import pi 
>>> print(pi) 

  • import COMPAS in Grasshopper

In Grasshopper, COMPAS is imported from within a GhPython component. To verify that everything is working properly, simply create a GhPython component on your Grasshopper canvas, paste the following script and hit OK

import compas

from compas.datastructures import Mesh
from compas_ghpython.artists import MeshArtist
mesh = Mesh.from_obj(compas.get('faces.obj'))

artist = MeshArtist(mesh)

a = artist.draw_mesh()
COMPAS Geometry
😎 😎 😎 View the Slides: Geometry 😎 😎 😎
Point Cloud and Plotters
Point Cloud in Grasshopper
Data Structures
COMPAS data structures
😎 😎 😎 View the Slides: Data Structures 😎 😎 😎
Mesh in VS Code #1
Mesh in VS Code #2
Network in VS Code
Mesh in Grasshopper
Network in GH
Assembly Information Model
Assembly and Element data structures
😎 😎 😎 View the Slides: Assembly Information Model 😎 😎 😎
Assembly Information Model
AM Information Model
Additive Manufacturing data structures
😎 😎 😎 View the Slides: AM Information Model 😎 😎 😎

Coming soon!

XR Assembly
XR Assembly
😎 😎 😎 View the Slides: XR Assembly 😎 😎 😎
XR Concepts and Application
XR App
Robotic Fabrication Planning
Robotic Fabrication Planning with COMPAS FAB and MoveIt
😎 😎 😎 View the Slides: Robotic Fabrication Planning 😎 😎 😎
Planning for Assembly with MoveIt

Useful links:

Robotic Fabrication Control
Control of a robotic assembly process
😎 😎 😎 View the Slides: Robotic Fabrication Control 😎 😎 😎
ABB Robots workflow

Useful links: