Getting Started
Your first py2g sketch in about five minutes
What You'll Learn
You will create a compact parametric design, execute it entirely in the browser, and inspect the resulting toolpath and G-code. The workflow is identical whether you're using the Pyodide-powered Python runtime, so finishing this guide gives you the full mental model for py2g: edit → run → inspect → share.
- How the code editor, controls panel, visualizer, and G-code viewer stay in sync
- Where the FullControl scaffold injects helpers like
fc,steps, and printer defaults - How to iterate quickly by tweaking parameters and re-running your sketch
Before You Begin
- Use the latest Chrome, Edge, or Firefox (Safari works, but Python cold-starts take longer)
- Create or sign in to a py2g account if you want to save or share sketches
- Plan for ~5 minutes of focused time—ideal for a short break
Step 1: Create a New Sketch
- Click the Create New Sketch button in the header
- You're dropped into the editor with a pre-loaded starter template
- The left pane is your Python editor; right panes handle controls, visualization, and G-code
Step 2: Understand the Template
The template already imports FullControl, initializes steps, and wires the return value into our visualization + G-code generation pipeline. All you have to do is add geometry operations:
import fullcontrol as fclayer_height = 0.2line_width = 0.4steps = []steps.append(fc.ExtrusionGeometry(width=line_width, height=layer_height))square = fc.rectangleXY(start_point=fc.Point(x=0, y=0, z=layer_height),x_size=20,y_size=20)steps.extend(square)
Each time you click Run Code, we execute your snippet inside Pyodide (CPython compiled to WebAssembly), capture the resultingsteps, and update both the viewer and G-code panel—no local installs or slicers required.
Step 3: Tour the Editor
- Code Panel: Monaco editor with Python syntax highlighting, IntelliSense, and handy shortcuts (Ctrl/Cmd + S runs your sketch)
- Controls Panel: Define sliders/inputs that inject variables before execution—ideal for presentation mode
- 3D View: Inspect extrusion (green) vs travel (gray) moves, drag to orbit, scroll to zoom
- G-code Panel: Review, copy, or download the generated commands for your printer
Step 4: Run, Inspect, Iterate
- Click Run Code (or press Ctrl/Cmd + S)
- Watch the status pill in the controls panel—first runs may take a few seconds while the runtime warms up
- Adjust dimensions, layer heights, or loop counts; re-run until the visualization matches your intent
- Promote frequently tweaked values to controls so others can explore the design without touching code
💡 Tip
Need to debug? Open the browser console for stack traces, or skim the G-code panel to verify extrusion distances.
Step 5: Save, Share, Present
- Give your sketch a memorable title and short summary describing what it generates
- Click Save (sign-in required) to store it privately or publish it to your profile
- Use the Presentation View link to share an interactive, code-free experience that only exposes the controls you configured
- Share the sketch URL with collaborators—they can fork it directly inside the browser
What's Next?
Ready to go deeper? Pick one:
Common Issues
Code not running?
Look for syntax or runtime errors in the console. The editor also underlines issues inline so you can jump straight to the line in question.
Nothing in the visualizer?
Make sure your sketch produces at least one movement in steps. Zero-length designs (or designs where the extruder stays off) render as blank scenes.
Runtime feels slow?
Large loops can generate tens of thousands of points. Start simple, then scale up. Python users can also benefit from letting Pyodide warm up once per session.