|
| 1 | +================================================================================ |
| 2 | + GCodePlotter — Command Reference |
| 3 | + Processing 4.x Library for Bambu Lab A1 Mini Pen Plotter |
| 4 | +================================================================================ |
| 5 | + |
| 6 | +Config file location: |
| 7 | + ~/Documents/Processing/libraries/GCodePlotter/Config/gcodeplotter.config |
| 8 | + |
| 9 | +GCode files (optional, auto-loaded if present): |
| 10 | + ~/Documents/Processing/libraries/GCodePlotter/Config/StartGCode.txt |
| 11 | + ~/Documents/Processing/libraries/GCodePlotter/Config/EndGCode.txt |
| 12 | + |
| 13 | +Find & Replace regex (to convert existing sketches): |
| 14 | + Search: \b(line|rect|ellipse|bezier|curve|beginShape|endShape|vertex|bezierVertex|curveVertex|pushMatrix|popMatrix|translate|rotate|scale)\( |
| 15 | + Replace: plotter.$1( |
| 16 | + |
| 17 | +──────────────────────────────────────────────────────────────────────────────── |
| 18 | + CONSTRUCTOR |
| 19 | +──────────────────────────────────────────────────────────────────────────────── |
| 20 | + |
| 21 | + new GCodePlotter(this) |
| 22 | + Load all settings from config file. |
| 23 | + |
| 24 | + new GCodePlotter(this, buildWidthMm, buildHeightMm) |
| 25 | + Load settings from config, but override build volume with given values. |
| 26 | + Example: new GCodePlotter(this, 180, 180) |
| 27 | + |
| 28 | +──────────────────────────────────────────────────────────────────────────────── |
| 29 | + CONFIGURATION (override config file values for the current sketch) |
| 30 | +──────────────────────────────────────────────────────────────────────────────── |
| 31 | + |
| 32 | + PRINTER |
| 33 | + plotter.setYDeadzone(mm) Unusable zone at the rear of the bed (mm). |
| 34 | + Center Y is calculated as (buildHeight + yDeadzone) / 2. |
| 35 | + Example: plotter.setYDeadzone(32) |
| 36 | + |
| 37 | + OUTPUT SIZE & POSITION |
| 38 | + plotter.setOutputSize(w, h) Set drawing size on the bed in mm. |
| 39 | + The center of the drawing always stays at the |
| 40 | + bed center — independent of this size. |
| 41 | + Example: plotter.setOutputSize(140, 140) |
| 42 | + |
| 43 | + plotter.setOriginOffset(x, y) Shift the drawing from the bed center by x/y mm. |
| 44 | + Default (0, 0) = perfectly centered. |
| 45 | + Example: plotter.setOriginOffset(10, 0) |
| 46 | + |
| 47 | + plotter.setFlipY(bool) Flip the Y axis. true = sketch-top maps to |
| 48 | + printer-front (large Y). Default: false. |
| 49 | + |
| 50 | + PEN |
| 51 | + plotter.setZOffsetMm(mm) Z offset of pen holder (mm). Applied via |
| 52 | + G1 Z{value} before G92 Z0. Calibrate this |
| 53 | + for your specific pen holder! |
| 54 | + Example: plotter.setZOffsetMm(17.0) |
| 55 | + |
| 56 | + plotter.setPenDownZ(z) Z height when the pen is drawing. Default: 0.0 |
| 57 | + plotter.setPenUpZ(z) Z height when the pen is traveling. Default: 3.0 |
| 58 | + plotter.setPauseZ(z) Z height during a pause (pen change). Default: 20.0 |
| 59 | + |
| 60 | + FEED RATES (mm/min) |
| 61 | + plotter.setDrawFeedRate(f) Speed while drawing. Default: 3000 |
| 62 | + plotter.setTravelFeedRate(f) Speed while traveling (pen up). Default: 18000 |
| 63 | + plotter.setZFeedRate(f) Speed for Z moves. Default: 900 |
| 64 | + |
| 65 | + E VALUE |
| 66 | + plotter.setUseEValue(bool) Enable/disable E value in G1 lines. |
| 67 | + Recommended true for Bambu Lab firmware. |
| 68 | + plotter.setEValuePerMm(e) E increment per mm of travel. Default: 0.0001 |
| 69 | + |
| 70 | + CURVES |
| 71 | + plotter.setCurveDetail(n) Number of segments per curve/ellipse. Default: 30 |
| 72 | + Higher = smoother, more GCode lines. |
| 73 | + |
| 74 | + CUSTOM GCODE |
| 75 | + plotter.setStartGCode(string) Override start GCode with a string. |
| 76 | + plotter.setEndGCode(string) Override end GCode with a string. |
| 77 | + plotter.setStartGCodeFromFile(path) Load start GCode from a .txt file. |
| 78 | + Example: plotter.setStartGCodeFromFile(sketchPath("start.txt")) |
| 79 | + plotter.setEndGCodeFromFile(path) Load end GCode from a .txt file. |
| 80 | + |
| 81 | +──────────────────────────────────────────────────────────────────────────────── |
| 82 | + RECORDING |
| 83 | +──────────────────────────────────────────────────────────────────────────────── |
| 84 | + |
| 85 | + plotter.beginRecord() Start recording. Clears all previous paths. |
| 86 | + Call this before your drawing commands. |
| 87 | + |
| 88 | + plotter.endRecord("filename") Stop recording and save filename.gcode |
| 89 | + and filename.svg to the sketch folder. |
| 90 | + |
| 91 | + plotter.saveGCode("file.gcode") Save GCode only (no SVG). |
| 92 | + plotter.saveSVG("file.svg") Save SVG only (no GCode). |
| 93 | + |
| 94 | + plotter.pause() Insert a user-input pause (M400 U1). |
| 95 | + Z lifts to pauseZ, printer waits until |
| 96 | + user presses resume on the touchscreen |
| 97 | + or in Bambu Studio. Z returns to penUpZ. |
| 98 | + Example: |
| 99 | + plotter.ellipse(300, 300, 400, 400); // pen 1 |
| 100 | + plotter.pause(); // wait for user |
| 101 | + plotter.ellipse(300, 300, 200, 200); // pen 2 |
| 102 | + |
| 103 | + plotter.pause(seconds) Insert a timed pause (M400 S{t}). |
| 104 | + Z lifts to pauseZ, printer waits for the |
| 105 | + given number of seconds, then continues. |
| 106 | + No user interaction needed. |
| 107 | + Example: |
| 108 | + plotter.pause(30); // wait 30 seconds |
| 109 | + |
| 110 | +──────────────────────────────────────────────────────────────────────────────── |
| 111 | + DRAWING COMMANDS |
| 112 | + Call these instead of Processing's built-in versions. |
| 113 | + They draw to the screen AND record the path for GCode export. |
| 114 | +──────────────────────────────────────────────────────────────────────────────── |
| 115 | + |
| 116 | + PRIMITIVES |
| 117 | + plotter.line(x1, y1, x2, y2) Draw a straight line. |
| 118 | + |
| 119 | + plotter.rect(x, y, w, h) Draw a rectangle (4 sides, closed path). |
| 120 | + x/y = top-left corner, w/h = width/height. |
| 121 | + |
| 122 | + plotter.ellipse(cx, cy, w, h) Draw an ellipse or circle (discretized). |
| 123 | + cx/cy = center, w/h = width/height. |
| 124 | + |
| 125 | + BEZIER & SPLINES |
| 126 | + plotter.bezier(x1,y1, cx1,cy1, cx2,cy2, x2,y2) |
| 127 | + Draw a cubic Bezier curve. |
| 128 | + (x1,y1) = start, (cx1,cy1)+(cx2,cy2) = control points, |
| 129 | + (x2,y2) = end. |
| 130 | + |
| 131 | + plotter.curve(x1,y1, x2,y2, x3,y3, x4,y4) |
| 132 | + Draw a Catmull-Rom spline segment. |
| 133 | + Curve runs from (x2,y2) to (x3,y3). |
| 134 | + (x1,y1) and (x4,y4) are outer control points. |
| 135 | + |
| 136 | + SHAPES |
| 137 | + plotter.beginShape() Start a shape (polygon mode). |
| 138 | + plotter.beginShape(mode) Start a shape with a Processing mode constant. |
| 139 | + |
| 140 | + plotter.vertex(x, y) Add a straight vertex to the current shape. |
| 141 | + |
| 142 | + plotter.bezierVertex(cx1,cy1, cx2,cy2, x,y) |
| 143 | + Add a Bezier vertex. Needs a preceding vertex() |
| 144 | + as anchor point. |
| 145 | + |
| 146 | + plotter.curveVertex(x, y) Add a Catmull-Rom spline vertex. |
| 147 | + Minimum 4 consecutive curveVertex calls |
| 148 | + for a smooth curve. First and last are |
| 149 | + outer control points (not drawn). |
| 150 | + |
| 151 | + plotter.endShape() Close and finalize the shape (open path). |
| 152 | + plotter.endShape(CLOSE) Close and finalize the shape (closed path, |
| 153 | + last point connects back to first). |
| 154 | + |
| 155 | +──────────────────────────────────────────────────────────────────────────────── |
| 156 | + TRANSFORMS |
| 157 | + Mirror these calls alongside Processing's own transform calls. |
| 158 | + Processing transforms affect the screen preview. |
| 159 | + Plotter transforms affect the recorded GCode coordinates. |
| 160 | +──────────────────────────────────────────────────────────────────────────────── |
| 161 | + |
| 162 | + plotter.pushMatrix() Save current transform to stack. |
| 163 | + plotter.popMatrix() Restore previous transform from stack. |
| 164 | + |
| 165 | + plotter.translate(dx, dy) Shift origin by (dx, dy) in pixels. |
| 166 | + plotter.rotate(angle) Rotate around current origin (radians). |
| 167 | + Example: plotter.rotate(PI / 4) // 45 degrees |
| 168 | + plotter.scale(s) Scale uniformly. |
| 169 | + plotter.scale(sx, sy) Scale separately in X and Y. |
| 170 | + plotter.resetMatrix() Reset all transforms (like resetMatrix() in Processing). |
| 171 | + |
| 172 | + USAGE PATTERN: |
| 173 | + pushMatrix(); plotter.pushMatrix(); |
| 174 | + translate(cx, cy); plotter.translate(cx, cy); |
| 175 | + rotate(angle); plotter.rotate(angle); |
| 176 | + rect(-w/2, -h/2, w, h); plotter.rect(-w/2, -h/2, w, h); |
| 177 | + popMatrix(); plotter.popMatrix(); |
| 178 | + |
| 179 | +──────────────────────────────────────────────────────────────────────────────── |
| 180 | + INFO & DEBUGGING |
| 181 | +──────────────────────────────────────────────────────────────────────────────── |
| 182 | + |
| 183 | + plotter.getPathCount() Returns number of recorded paths (int). |
| 184 | + plotter.getBuildWidth() Returns build volume width in mm (float). |
| 185 | + plotter.getBuildHeight() Returns build volume height in mm (float). |
| 186 | + plotter.printConfigPath() Prints the active config file path to console. |
| 187 | + |
| 188 | +──────────────────────────────────────────────────────────────────────────────── |
| 189 | + CONSOLE WARNINGS |
| 190 | +──────────────────────────────────────────────────────────────────────────────── |
| 191 | + |
| 192 | + The library prints a warning once per export if any point falls outside |
| 193 | + the bed boundaries: |
| 194 | + |
| 195 | + GCodePlotter WARNING: X < 0 Point is left of the bed. |
| 196 | + GCodePlotter WARNING: X > {buildWidth} Point is right of the bed. |
| 197 | + GCodePlotter WARNING: Y < yDeadzone Point is inside the rear deadzone. |
| 198 | + GCodePlotter WARNING: Y > {buildHeight} Point is beyond the front of the bed. |
| 199 | + |
| 200 | + If you see these, reduce your output size or adjust the origin offset. |
| 201 | + |
| 202 | +──────────────────────────────────────────────────────────────────────────────── |
| 203 | + MINIMAL SKETCH TEMPLATE |
| 204 | +──────────────────────────────────────────────────────────────────────────────── |
| 205 | + |
| 206 | + import gcodeplotter.*; |
| 207 | + GCodePlotter plotter; |
| 208 | + |
| 209 | + void setup() { |
| 210 | + size(600, 600); |
| 211 | + plotter = new GCodePlotter(this); // all values from config |
| 212 | + draw_everything(); |
| 213 | + } |
| 214 | + |
| 215 | + void draw() {} |
| 216 | + |
| 217 | + void draw_everything() { |
| 218 | + background(255); |
| 219 | + stroke(0); noFill(); |
| 220 | + plotter.ellipse(300, 300, 500, 500); |
| 221 | + plotter.rect(50, 50, 500, 500); |
| 222 | + } |
| 223 | + |
| 224 | + void keyPressed() { |
| 225 | + if (key == 's') { |
| 226 | + plotter.beginRecord(); |
| 227 | + draw_everything(); |
| 228 | + plotter.endRecord("output"); |
| 229 | + } |
| 230 | + } |
| 231 | + |
| 232 | +================================================================================ |
0 commit comments