UNSW Making

Advanced 3D printing with Grasshopper

It is recommended in doing this learn module that you have already completed the Digital Fabrication Badge and the 3D printing learn module. In this learn module you will build an understanding of:

  • Key features of 3D printing
  • G-Code and how to create your own G-Code
  • Key components in grasshopper for creating G-Code
  • Different parametric modelling techniques in grasshopper

3D Printing Overview


In the design futures lab, we have a range of plastic 3D printers and clay 3D printers – below are the printers and the firmware that they use.

grasshopper 3d printing-01.png

Understanding 3D Printing

3D printing can involve lots of confusing terminology that may take a little while to become familiar with. Below are some of the basic terms and concepts that you will be working with when 3D printing. Make sure to check out the 3D printing learn module for more information.

3D Printing Learn Module
grasshopper 3d printing-02.png
3D Printing Path

Path is the route the 3D printer nozzle follows. When creating your own G-Code you must make sure to pick the most optimal route between each layer. This is important for the speed of the print but also for the deposition of material to avoid over extrusion or under extrusion in certain areas of the 3D print.

Feed Rate

Feed rate (F) is how fast the extruder moves as it is printing and is measured in mm³/s (cubic millimetres per second). The feed rate can be constant or a variable throughout the print which will create a range of different results that can be experimented with in the printing process. Slower feed rates will allow for more material to be extruded as it moves slower around the model. This is required for flexible materials to help it build up enough materials each layer. Faster feed rates create thinner extruded 'lines' as there is less time for the extruder to deposit material.

Extrusion Rate

Extrusion Rate (E) or Flow determines how much material is being pushed out of the nozzle. Adjusting the extrusion rate in combination with the feed rate can alter the wall thickness as well as how each layer sticks together. A faster extrusion rate will push out more clay as opposed to a slower extrusion rate. This can sometimes be expressed in a speed (mm/sec) or as a percentage of 'flow' where 100% is normal flow rate and can be increased or decreased to alter how much material is extruded.

G-Code Basics


G-Code is a set of instructions that provide the path, speed and extrusion rates for various digital fabrication machines such as 3D printers and CNC routers. Most commonly, software such a CURA is used to automatically generate G-Code based on an inputted 3D model in the form of an .STL file. This learn module will help you to generate and completely customise your own G-Code for advanced applications. Whilst at first it may look complicated, once you understand the structure of G-Code you will be writing code with your eyes closed!

G-Code for 3-axis machines are usually structured as follows:

Start Protocol – This code is what gets the printer ready and generally homes the extruder.

Core (Instructions) – This code is what carries out the printing process of the 3D model. Move commands are provided with x,y,z coordinates to determine where the machine moves.

End Protocol – This code runs once the print finishes and generally homes the extruder again.

Anatomy of G-Code

grasshopper 3d printing-03.png

The following information is reference from : https://reprap.org/wiki/G-code By following this link you can learn about different firmware that your printer might use or other instructions or commands that aren’t listed here.

The following commands are the most common and are also used for the clay 3D printers at the design futures lab:

Move Commands

G0 – Is a rapid movement (Supported by majority of 3D printer firmware)

G1 – Is a linear movement (Supported by majority of 3D printer firmware)

Parameters of G0 & G1 movements:

  • X – Movement in the X axis
  • Y – Movement in the Y axis
  • Z – Movement in the Z axis
  • E – The amount to extrude between the start and end point of a movement
  • F – Feed rate per minute as described previously

G2 – A controlled ARC movement (Clockwise) – Not supported by all firmware

G3 – Controlled ARC movement (Counter-clockwise) – Not supported by all firmware

G4 – “Dwell” – Pauses the mG2achine for a period of time

Parameters of a Dwell

  • S – Time to wait in seconds

G21 - Set units to MM – This always has to be set in the Gcode.

G28 – Move to Origin (Home)

Parameters of move to origin (Optional, should also be already programmed by the machine):

  • X
  • Y
  • Z

Positioning Commands

G90 – All coordinates from now on are absolute relative to the origin of the machine.

G91 – All coordinates from now are relative to the last position

M82 - Set an extruder to absolute coordinates – equivalent to G90 but for the extruder.

M83 - Set an extruder to relative coordinates – equivalent to G91 but for the extruder.

G92 - Sets a particular position. Overwrite the position of an axis to zero or to the specified value. No physical motion will occur. (G92 X50 will reset the current machine’s X coordinate to 50. If no values are specified, all axes will be set to zero).

Temperature Commands

(Not needed for clay printing)

M104 – Start heating the extruder. Temperature is most important for plastic 3D printing. The temperature is in degrees Celsius. Not needed for clay printing.

Parameters for M104:

  • S – Target temperature

M106 – Set fan On.

Parameters for M106:

  • S – Fan Speed ( The values for this ranges from 0 to 255)

M017 – Set fan OFF, or can use the M106 to change the speed to 0. Example: “M106 S0”. Not needed for Clay printing.

M109 – Set Extruder Temperature and wait. Not needed for clay printing

Parameters of M109:

  • S – minimum target temperature – waits until heating

M117 – It is used to display a message on the LCD screen

M140 – Sets the Bed Temperature in degrees Celsius. Not needed for clay printing.

Parameters of M140:

  • S – sets the temperature.

M190 – Wait for bed temperature to reach target temp. Not needed for clay printing.


  • S – minimum target temperature, waits until heating
  • R – Accurate target temperature, waits until heating and cooling (Marlin)

Start & End G-Code Protocols

Delta Printer (Clay)

Start G-Code :
G92 E0.0000
G1 E-4.0000 F6000

End G-Code:
G92 E0.0000
G1 E-4.0000 F6000

3D Potter (Clay)

Start G-Code:
M106 S0
M104 S0 T0
G0 Z-10 F500
G92.4 X0 Y152
G1 X450.761 Y6.784 F2400
;Process PROCESS1
; Layer 1, Z=2.00
; Feature Skirt
; Tool H2.000 W4.200
G1 Z2.0000 F1200

End G-Code:
G1 Z200 F500
G28 F500
G0 Z-10

Prusa Printers (Plastic)

Start G-Code

M82 ;absolute extrusion mode

G21 ; set units to millimetres

G90 ; use absolute positioning

M82 ; absolute extrusion mode

M104 S250 ; set extruder temp

M140 S60 ; set bed temp

M190 S60 ; wait for bed temp

M109 S250 ; wait for extruder temp

G28 W ; home all without mesh bed level

G80 ; mesh bed leveling

G92 E0.0 ; reset extruder distance position

G1 Y-3.0 F1000.0 ; go outside print area

G1 X60.0 E9.0 F1000.0 ; intro line

G1 X100.0 E21.5 F1000.0 ; intro line

G92 E0.0 ; reset extruder distance position

G92 E0

G92 E0

G1 F2100 E-0.8

End G-Code

G1 F2100 E2686.24656

M140 S0


M104 S0 ; turn off extruder

M140 S0 ; turn off heat-bed

M107 ; turn off fan

G1 X0 Y210; home X axis and push Y forward

M84 ; disable motors

M82 ;absolute extrusion mode

M104 S0

Ultimaker (Plastic)

Start G-Code

M82 ;absolute extrusion mode

G92 E0

M109 S210

G0 F15000 X204 Y6 Z2


G1 F1500 E-6.5

End G-Code

G1 F1500 E467.40607

M140 S0

M204 S3000

M205 X20 Y20


G91 ;Relative movement

G0 F15000 X8.0 Z0.5 E-4.5 ;Wiping+material retraction

G0 F10000 Z1.5 E4.5 ;Compensation for the retraction

G90 ;Disable relative movement

M82 ;absolute extrusion mode

M104 T0 S0

M104 S0

Generating G-Code in Grasshopper

grasshopper 3d printing-09.png

3D printing from Grasshopper


To create G-Code in grasshopper we need to be able to turn 3D geometries into structured points that the printer can follow.

This module will work well with the following downloadable file “Basic-Gcode.gh”.

Basic G-Code Script


concat g-code

The key component that joins all the code together is the 'Concatenate'component. The concatenate component links series of inputs (things) together in a chain or series. It will only input and output text parameters.

Here we can formulate the “movement” code of the GCODE, this is predominately the G1 code (Linear movement). Refer to what parameters we need in order to complete the movement (coordinates, feed rate, extrusion rate).

This data can then be merged with the start and end code which will be added via panels. The start and end code are determined by the firmware your printer is using. ENSURE to check or change the start and end code for each printer. The output of the merge component will provide us with the G-Code required to print. Right click on the panel to export the content. Make sure to COPY DATA ONLY do not copy over the index values in the panel. You can then paste this into a text editor and save as a “.gcode” file type and you are ready to print.


Decimal Places

Grasshopper uses 6 digits when there is a decimal place. If more than 6 digits are necessary grasshopper begins using scientific notations. To ensure we reduce the decimal place for the printer we need to complete the following step below after the deconstruction point for the XYZ values before the Concatenate Component.

decimal places.png


The contour will be a commonly used component throughout the GCODE process as it will cut contours of the object (each layer) at certain heights (which will be like layer height). It can take both BREP and meshes so it is highly useful tool.



There are a range of division tools that can be used on any curve to create points for printing coordinates. Divide curve will divide curves evenly by a set number input, divide length will divide the curve using a pre-set length and divide distance will divide the curve via a pre-set distance between points.



Control points, control polygons and discontinuity will allow the user to take all the control points of the curve for printing coordinates in the G-Code. Control points extract NURB points and knots, Control polygon extracts the NURBS control point (Not always sitting on the curve) and discontinuity extracts the discontinuities points along a curve. All these tools will not provide the same outcomes so ensure you use the correct one when creating your G-Code.

control points.png

Layer Management

It is important to consider the nozzle size and the layer height before you get started with each design. If your layers are too high the clay will have poor adhesion and if the layers are too small you run the risk of over-extruding and pushing too much clay on top of each other, which could cause clogging or ruin prints.

Information about the different nozzles available at the DFL and the recommended layers heights can be found here.

Constant Extrusion Rate

In this example we can see that the explode segment only counts the segments between the start and end points. This can be solved by closing the polygon or if this is not possible in the design we can do the following script.

The 'mass addition' is important as the printer will only add materials if there is an addition to the previous number.

constant extrusion.png

Variable Layer Heights

This section of script needs to be added into the script of designs that do not have constant layer heights. See Isocurve example. This stops larger distribution of materials with short layer heights.

variable extrusion.png

Stop & Go Printing



This definition reduces the travel time between layers of an open geometry. To stop the printer finishing a layer and returning all the way back to the start of the next layer we can dispatch the contours which splits the group into 2 different groups based off a pattern ( 0 & 1 ). In this instance 0,1 is the correct pattern so every second layer is moved to group B. once we have two groups we can flip the start and end point of one group and weave the data back together into its original structure. Now if we take the control points and create a polyline the printer never travels off the print back to the start.

stopgo printing.JPG



Stop and go printing prints each individual layer as a separate line. Due to the fact it isn’t one continuous line there is generally a small build up of clay at the seam of the design, being visible when printing. Depending on the design you might want to include the seam. This is the easiest grasshopper script as you just need to cut contours of your shape at a designated layer height and create a polyline and take the control points for the G-Code.

seam printing.JPG

Continuous Polyline

This method is different from the stop & go and it creates one continuous polyline or essentially one “layer” as it does not stop extruding. This method avoids the seam in the design but requires some further steps.

You will need to either cull index “0” or shift list “1” and invert the Boolean to remove the first point of each layer and then create a new polyline that joins all the points of the whole BREP together. By deleting these points it creates a ramp between each different layer allowing for a continuous flow.

Remember to use the flatten tool on the polyline to ensure the points are in one group to create one polyline.

continuous polyline.JPG

Ramp for Uniform Shapes

If a 1-point ramp is not long enough depending on the design this can also be altered by using some simple maths to extend the ramp. To complete this method, we need to move the points in the Z axis by a predetermined amount dependant on layer height. Firstly, we need to split the list into points that are staying at the same height and points that are moving. This is done by the split list component – The split index is the amount we want in each group, to do this we subtraction the number of points in the ramp by the total number of points on each layer. This gives us two different groups of points. Points on each layer that don’t move (output A) and the points that move (output B). To move the points, we need to do some simple maths, we can do this by using the series tool. Series creates a list of numbers that are determined by a starting number, the step and the count. The step is the layer height divided by the number of points in the ramp and the count is the number of points in the ramp (EG, in this example each point is moving by 0.33, 0.66 and so on). This new list of numbers can be used to move the points in the Z axis. The points are then merged back into their correct groups and then create a polyline.

Keep in mind in this example the touch on the build plate could be comprised as the ramp starts on layer 1. This could be altered.

ramp uniform.png

Ramp for Non-Uniform Shapes

For shapes that non-uniform the ramp strategy could potentially fail. This is due to the start and end points are not exactly aligned for each layer which could cause problems. The movement of the points for the ramp should follow the direction of the next layer. To do this we need to use vectors instead of the series tool. To do this we need to flip matrix the division points and create polylines between each layer using the new point structure. We can explode the polylines which we can extract the start and end points between each layer, here we can use the vector 2Pt tool which allows us to create a vector in a certain direction.
Now we have these vectors we can flip matrix again to revert back to our original point structure (one layer at a time) and we can move each point by these new vectors. We use a range to determine the percentage each point will move between 0 to 1. We can then create a polyline that follows the exact structure of the shape not losing any definition.

ramp non uniform.png

Example Files and Templates


Generating G-Code Template

Parametric Modelling Techniques


Waves - Weave and Dispatch

This script uses the weave and dispatch components to create wave like patterns seen in the following examples pictures. This particular example dispatches the contours of a vase into two groups (Pattern = 0, 1). From the first dispatch we take group B (every second contour) and divide them by a set number (remember the more points, the more accurate the print will be). Here we then use the dispatch tool again, this time to split the points for each contour into two separate groups so we can create the wave pattern.

The wave pattern will be determined by the input in the dispatch P. This example uses 0,1 but it can be different. To change the pattern input a panel (Set to multi-line data) with your pattern inside.

waves step 1.png

Using the BREP closest points tool we can take the normal vector of each point and move them out radially at a set distance determined by the amplitude tool (The further out, the more droopy the print).

Once we have our pattern, we need to weave the original points back together with the wavy points into their original data structure. Then we need to create a polyline from our two sets of points.

The last step is to weave the new “wavy” contours with the originally dispatched contours. From here you can add in the required layer management and flow management scrips that are required (Depending on your design).

waves step 2.png

Image Sampling

This script allows you to take an image and turn it into a pattern on the surface of your vase or geometry. In this example we have take the surface of our geometry and used the divide surface complete to gain a series of points based of a (UV) count. From here we can take these points and input the values into the surface closest points these can output the exact UV points on the surface that can be used in the image sampler.

image sampling.jpg
image sampling 1.png

The image sampling tools divides your image input into the X and Y domain between 0 to 1. (NEED TO ADD XY PARAMETER TO THE IMAGE). You can also exact different channels from the image to use in the script. If the image is colour, then you can use (RBG, Red, Blue, Green, Alpha, Colour Hue or Colour Saturation or colour brightness). For the best results, the colour brightness works the best, especially on black and white images.

image sampling 2.png

Our UV points from our surface are mapped on the XY domain of the image (The more points the more detail). From here we can take the mapped values that are outputted from the image (Between 0 and 1) and remap them to real-world values that match how we want the vase to look.

The numbers are between (0 to 1) so we can use the remap tool to create a new target domain. By construction a domain this will set the new position of the points. (See image with left: Values outputted from image sampler; Right) Remapped values).

image sampling 3.png

We can use these new values to create lengths that the points move following the normal vector of their original position. We can take the vector from “BREP closest points”, similar to the wave example. We can now take the original points from the divide surface and move them according to the remap values and amplitude lengths we have created. From here we can flatten the points into one group and create a surface from points. The U count of in the input comes from the U number slider from the original divide surface. The U input needs an expression X+1 to ensure there are enough points otherwise it will not work. From here we can cut contours of the new shape and follow the earlier scripts to create GCODE.

image sampling 4.png

Attractor Points

An attractor script behaves like a magnet that modify scale, lengths or positions of objects. The most common entities used to create attractor definitions are points, curves, vectors or images.

curve attrac ex

Single Attractor

single attract 1.png single attrac 2.png
single attrac.jpg

Multiple Attractors

multiple attrac 1.png
multiple attrac 2.jpg

Curve as an Attractor

This example uses a predefined curve instead of points. This way you can wrap the curve around the shape.

curve attrac 1.png
curve attrac 2.jpg