Skip to content

Instantly share code, notes, and snippets.

@fullcontrol-xyz
Last active November 27, 2023 02:51
Show Gist options
  • Save fullcontrol-xyz/fe80b7ae8af1f80eb601c3c1f480d8fe to your computer and use it in GitHub Desktop.
Save fullcontrol-xyz/fe80b7ae8af1f80eb601c3c1f480d8fe to your computer and use it in GitHub Desktop.
svg_demo.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/fullcontrol-xyz/fe80b7ae8af1f80eb601c3c1f480d8fe/svg_demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ac9_FmrCOwQL"
},
"source": [
"# svg demo\n",
"\n",
"press ctrl+F9 to run all cells in this notebook, or press shift+enter to run each cell sequentially \n",
" \n",
"if you change one of the code cells, make sure you run it and all subsequent cells again (in order)\n",
" \n",
"*this document is a jupyter notebook - if they're new to you, check out how they work: [link](https://www.google.com/search?q=ipynb+tutorial), [link](https://jupyter.org/try-jupyter/retro/notebooks/?path=notebooks/Intro.ipynb), [link](https://colab.research.google.com/)*"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XVYUcd_RO3BD"
},
"source": [
"### be patient :)\n",
"\n",
"the next code cell may take a while because running it causes several things to happen:\n",
"- connect to a google colab server -> download the fullcontrol code -> install the fullcontrol code\n",
"\n",
"check out [other tutorials](https://github.com/FullControlXYZ/fullcontrol/blob/master/docs/README.md) to understand the python code for the FullControl design"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "57XXnogSOvDx",
"outputId": "be034cf7-6bf2-4557-eceb-16074a142593",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n"
]
}
],
"source": [
"!pip install git+https://github.com/FullControlXYZ/fullcontrol --quiet\n",
"import fullcontrol as fc\n",
"from google.colab import files"
]
},
{
"cell_type": "markdown",
"source": [
"## new function: svg_to_points()\n",
"\n",
"the following cell takes code from [stack exchange](https://stackoverflow.com/questions/69313876/how-to-get-points-of-the-svg-paths\n",
") and creates the function *svg_to_points()* to convert the XY data to a list of FullControl Points"
],
"metadata": {
"id": "mKsxa83GfmnI"
}
},
{
"cell_type": "code",
"source": [
"!pip install svg.path\n",
"from svg.path import parse_path\n",
"from xml.dom import minidom\n",
"\n",
"# from https://stackoverflow.com/questions/69313876/how-to-get-points-of-the-svg-paths\n",
"\n",
"def get_point_at(path, distance, scale, offset):\n",
" pos = path.point(distance)\n",
" pos += offset\n",
" pos *= scale\n",
" return pos.real, pos.imag\n",
"\n",
"\n",
"def points_from_path(path, density, scale, offset):\n",
" step = int(path.length() * density)\n",
" last_step = step - 1\n",
"\n",
" if last_step == 0:\n",
" yield get_point_at(path, 0, scale, offset)\n",
" return\n",
"\n",
" for distance in range(step):\n",
" yield get_point_at(\n",
" path, distance / last_step, scale, offset)\n",
"\n",
"\n",
"def points_from_doc(doc, density=5, scale=1, offset=0):\n",
" offset = offset[0] + offset[1] * 1j\n",
" points = []\n",
" for element in doc.getElementsByTagName(\"path\"):\n",
" for path in parse_path(element.getAttribute(\"d\")):\n",
" points.extend(points_from_path(\n",
" path, density, scale, offset))\n",
"\n",
" return points\n",
"\n",
"\n",
"def svg_to_points(svg_str: str, z_height: float) -> list:\n",
" doc = minidom.parseString(svg_str)\n",
" points = points_from_doc(doc, density=1, scale=5, offset=(0, 5))\n",
" doc.unlink()\n",
" return [fc.Point(x=pt[0], y=pt[1], z=z_height) for pt in points]"
],
"metadata": {
"id": "1j29l3v-f4UN",
"outputId": "7d7d5862-062e-41ea-8ace-a100a69d9f3e",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
"Requirement already satisfied: svg.path in /usr/local/lib/python3.10/dist-packages (6.2)\n"
]
}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "CpjceGMcfhV2"
},
"outputs": [],
"source": [
"# printer/gcode parameters\n",
"\n",
"design_name = 'my_design'\n",
"nozzle_temp = 210\n",
"bed_temp = 40\n",
"print_speed = 1000\n",
"fan_percent = 100\n",
"printer_name='prusa_i3' # generic / ultimaker2plus / prusa_i3 / ender_3 / cr_10 / bambulab_x1 / toolchanger_T0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "DeWKjlzbPC0u"
},
"outputs": [],
"source": [
"# design parameters\n",
"\n",
"EW = 0.8 # extrusion width\n",
"EH = 0.3 # extrusion height (and layer height)\n",
"initial_z = EH*0.6 # initial nozzle position is set to 0.6x the extrusion height to get a bit of 'squish' for good bed adhesion"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "kLPh7aTwQKrF"
},
"outputs": [],
"source": [
"# generate the design (make sure you've run the above cells before running this cell)\n",
"\n",
"svg = \"\"\"<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">\n",
" <path fill=\"none\" stroke=\"red\"\n",
" d=\"M 10,30\n",
" A 20,20 0,0,1 50,30\n",
" A 20,20 0,0,1 90,30\n",
" Q 90,60 50,90\n",
" Q 10,60 10,30 z\" />\n",
"</svg>\"\"\"\n",
"\n",
"steps = svg_to_points(svg_str=svg, z_height=initial_z)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ZVdfnpt5RSUi",
"outputId": "2d917a88-37e5-4c2c-dbce-24e31ef72539",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 517
}
},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<html>\n",
"<head><meta charset=\"utf-8\" /></head>\n",
"<body>\n",
" <div> <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script> <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
" <script src=\"https://cdn.plot.ly/plotly-2.18.2.min.js\"></script> <div id=\"249b5516-f0e4-4bd3-be27-bb4d788d0c42\" class=\"plotly-graph-div\" style=\"height:500px; width:800px;\"></div> <script type=\"text/javascript\"> window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"249b5516-f0e4-4bd3-be27-bb4d788d0c42\")) { Plotly.newPlot( \"249b5516-f0e4-4bd3-be27-bb4d788d0c42\", [{\"line\":{\"color\":[\"rgb(204.00, 0.00, 255.00)\",\"rgb(202.47, 0.00, 255.00)\",\"rgb(200.94, 0.00, 255.00)\",\"rgb(199.41, 0.00, 255.00)\",\"rgb(197.88, 0.00, 255.00)\",\"rgb(196.61, 0.00, 255.00)\",\"rgb(195.08, 0.00, 255.00)\",\"rgb(193.55, 0.00, 255.00)\",\"rgb(192.02, 0.00, 255.00)\",\"rgb(190.48, 0.00, 255.00)\",\"rgb(188.95, 0.00, 255.00)\",\"rgb(187.42, 0.00, 255.00)\",\"rgb(185.89, 0.00, 255.00)\",\"rgb(184.62, 0.00, 255.00)\",\"rgb(183.09, 0.00, 255.00)\",\"rgb(181.56, 0.00, 255.00)\",\"rgb(180.03, 0.00, 255.00)\",\"rgb(178.50, 0.00, 255.00)\",\"rgb(176.97, 0.00, 255.00)\",\"rgb(175.44, 0.00, 255.00)\",\"rgb(173.91, 0.00, 255.00)\",\"rgb(172.38, 0.00, 255.00)\",\"rgb(171.11, 0.00, 255.00)\",\"rgb(169.58, 0.00, 255.00)\",\"rgb(168.05, 0.00, 255.00)\",\"rgb(166.52, 0.00, 255.00)\",\"rgb(164.99, 0.00, 255.00)\",\"rgb(163.46, 0.00, 255.00)\",\"rgb(161.93, 0.00, 255.00)\",\"rgb(160.40, 0.00, 255.00)\",\"rgb(159.12, 0.00, 255.00)\",\"rgb(157.59, 0.00, 255.00)\",\"rgb(156.06, 0.00, 255.00)\",\"rgb(154.53, 0.00, 255.00)\",\"rgb(153.00, 0.00, 255.00)\",\"rgb(151.47, 0.00, 255.00)\",\"rgb(149.94, 0.00, 255.00)\",\"rgb(148.41, 0.00, 255.00)\",\"rgb(146.88, 0.00, 255.00)\",\"rgb(145.60, 0.00, 255.00)\",\"rgb(144.07, 0.00, 255.00)\",\"rgb(142.55, 0.00, 255.00)\",\"rgb(141.02, 0.00, 255.00)\",\"rgb(139.49, 0.00, 255.00)\",\"rgb(137.96, 0.00, 255.00)\",\"rgb(136.43, 0.00, 255.00)\",\"rgb(134.90, 0.00, 255.00)\",\"rgb(133.62, 0.00, 255.00)\",\"rgb(132.09, 0.00, 255.00)\",\"rgb(130.56, 0.00, 255.00)\",\"rgb(129.03, 0.00, 255.00)\",\"rgb(127.50, 0.00, 255.00)\",\"rgb(125.97, 0.00, 255.00)\",\"rgb(124.44, 0.00, 255.00)\",\"rgb(122.91, 0.00, 255.00)\",\"rgb(121.38, 0.00, 255.00)\",\"rgb(120.10, 0.00, 255.00)\",\"rgb(118.58, 0.00, 255.00)\",\"rgb(117.05, 0.00, 255.00)\",\"rgb(115.52, 0.00, 255.00)\",\"rgb(113.98, 0.00, 255.00)\",\"rgb(112.45, 0.00, 255.00)\",\"rgb(110.92, 0.00, 255.00)\",\"rgb(109.39, 0.00, 255.00)\",\"rgb(108.12, 0.00, 255.00)\",\"rgb(106.59, 0.00, 255.00)\",\"rgb(105.06, 0.00, 255.00)\",\"rgb(103.53, 0.00, 255.00)\",\"rgb(102.00, 0.00, 255.00)\",\"rgb(100.47, 0.00, 255.00)\",\"rgb(98.94, 0.00, 255.00)\",\"rgb(97.41, 0.00, 255.00)\",\"rgb(95.88, 0.00, 255.00)\",\"rgb(94.61, 0.00, 255.00)\",\"rgb(93.08, 0.00, 255.00)\",\"rgb(91.55, 0.00, 255.00)\",\"rgb(90.02, 0.00, 255.00)\",\"rgb(88.48, 0.00, 255.00)\",\"rgb(86.96, 0.00, 255.00)\",\"rgb(85.43, 0.00, 255.00)\",\"rgb(83.90, 0.00, 255.00)\",\"rgb(82.62, 0.00, 255.00)\",\"rgb(81.09, 0.00, 255.00)\",\"rgb(79.56, 0.00, 255.00)\",\"rgb(78.03, 0.00, 255.00)\",\"rgb(76.50, 0.00, 255.00)\",\"rgb(74.97, 0.00, 255.00)\",\"rgb(73.44, 0.00, 255.00)\",\"rgb(71.91, 0.00, 255.00)\",\"rgb(70.38, 0.00, 255.00)\",\"rgb(69.11, 0.00, 255.00)\",\"rgb(67.58, 0.00, 255.00)\",\"rgb(66.05, 0.00, 255.00)\",\"rgb(64.52, 0.00, 255.00)\",\"rgb(62.98, 0.00, 255.00)\",\"rgb(61.45, 0.00, 255.00)\",\"rgb(59.92, 0.00, 255.00)\",\"rgb(58.40, 0.00, 255.00)\",\"rgb(57.12, 0.00, 255.00)\",\"rgb(55.59, 0.00, 255.00)\",\"rgb(54.06, 0.00, 255.00)\",\"rgb(52.53, 0.00, 255.00)\",\"rgb(51.00, 0.00, 255.00)\",\"rgb(49.47, 0.00, 255.00)\",\"rgb(47.94, 0.00, 255.00)\",\"rgb(46.41, 0.00, 255.00)\",\"rgb(44.88, 0.00, 255.00)\",\"rgb(43.61, 0.00, 255.00)\",\"rgb(42.08, 0.00, 255.00)\",\"rgb(40.55, 0.00, 255.00)\",\"rgb(39.02, 0.00, 255.00)\",\"rgb(37.48, 0.00, 255.00)\",\"rgb(35.95, 0.00, 255.00)\",\"rgb(34.43, 0.00, 255.00)\",\"rgb(32.90, 0.00, 255.00)\",\"rgb(31.62, 0.00, 255.00)\",\"rgb(30.09, 0.00, 255.00)\",\"rgb(28.56, 0.00, 255.00)\",\"rgb(27.03, 0.00, 255.00)\",\"rgb(25.50, 0.00, 255.00)\",\"rgb(23.97, 0.00, 255.00)\",\"rgb(22.44, 0.00, 255.00)\",\"rgb(20.91, 0.00, 255.00)\",\"rgb(19.38, 0.00, 255.00)\",\"rgb(18.10, 0.00, 255.00)\",\"rgb(16.57, 0.00, 255.00)\",\"rgb(15.04, 0.00, 255.00)\",\"rgb(13.51, 0.00, 255.00)\",\"rgb(11.98, 0.00, 255.00)\",\"rgb(10.46, 0.00, 255.00)\",\"rgb(8.93, 0.00, 255.00)\",\"rgb(7.40, 0.00, 255.00)\",\"rgb(6.12, 0.00, 255.00)\",\"rgb(4.59, 0.00, 255.00)\",\"rgb(3.06, 0.00, 255.00)\",\"rgb(1.53, 0.00, 255.00)\",\"rgb(0.00, 0.00, 255.00)\",\"rgb(0.00, 1.79, 255.00)\",\"rgb(0.00, 3.82, 255.00)\",\"rgb(0.00, 5.61, 255.00)\",\"rgb(0.00, 7.40, 255.00)\",\"rgb(0.00, 9.43, 255.00)\",\"rgb(0.00, 11.22, 255.00)\",\"rgb(0.00, 13.00, 255.00)\",\"rgb(0.00, 15.04, 255.00)\",\"rgb(0.00, 16.83, 255.00)\",\"rgb(0.00, 18.87, 255.00)\",\"rgb(0.00, 20.66, 255.00)\",\"rgb(0.00, 22.44, 255.00)\",\"rgb(0.00, 24.48, 255.00)\",\"rgb(0.00, 26.26, 255.00)\",\"rgb(0.00, 28.05, 255.00)\",\"rgb(0.00, 30.09, 255.00)\",\"rgb(0.00, 31.88, 255.00)\",\"rgb(0.00, 33.66, 255.00)\",\"rgb(0.00, 35.70, 255.00)\",\"rgb(0.00, 37.48, 255.00)\",\"rgb(0.00, 39.27, 255.00)\",\"rgb(0.00, 41.31, 255.00)\",\"rgb(0.00, 43.10, 255.00)\",\"rgb(0.00, 44.88, 255.00)\",\"rgb(0.00, 46.92, 255.00)\",\"rgb(0.00, 48.70, 255.00)\",\"rgb(0.00, 50.75, 255.00)\",\"rgb(0.00, 52.53, 255.00)\",\"rgb(0.00, 54.31, 255.00)\",\"rgb(0.00, 56.36, 255.00)\",\"rgb(0.00, 58.14, 255.00)\",\"rgb(0.00, 59.92, 255.00)\",\"rgb(0.00, 61.96, 255.00)\",\"rgb(0.00, 63.75, 255.00)\",\"rgb(0.00, 65.53, 255.00)\",\"rgb(0.00, 67.58, 255.00)\",\"rgb(0.00, 69.36, 255.00)\",\"rgb(0.00, 71.15, 255.00)\",\"rgb(0.00, 73.18, 255.00)\",\"rgb(0.00, 74.97, 255.00)\",\"rgb(0.00, 76.75, 255.00)\",\"rgb(0.00, 78.80, 255.00)\",\"rgb(0.00, 80.58, 255.00)\",\"rgb(0.00, 82.62, 255.00)\",\"rgb(0.00, 84.41, 255.00)\",\"rgb(0.00, 86.19, 255.00)\",\"rgb(0.00, 88.23, 255.00)\",\"rgb(0.00, 90.02, 255.00)\",\"rgb(0.00, 91.80, 255.00)\",\"rgb(0.00, 93.84, 255.00)\",\"rgb(0.00, 95.62, 255.00)\",\"rgb(0.00, 97.41, 255.00)\",\"rgb(0.00, 99.45, 255.00)\",\"rgb(0.00, 101.23, 255.00)\",\"rgb(0.00, 103.02, 255.00)\",\"rgb(0.00, 105.06, 255.00)\",\"rgb(0.00, 106.84, 255.00)\",\"rgb(0.00, 108.63, 255.00)\",\"rgb(0.00, 110.67, 255.00)\",\"rgb(0.00, 112.45, 255.00)\",\"rgb(0.00, 114.50, 255.00)\",\"rgb(0.00, 116.28, 255.00)\",\"rgb(0.00, 118.07, 255.00)\",\"rgb(0.00, 120.10, 255.00)\",\"rgb(0.00, 121.89, 255.00)\",\"rgb(0.00, 123.67, 255.00)\",\"rgb(0.00, 125.72, 255.00)\",\"rgb(0.00, 127.50, 255.00)\",\"rgb(0.00, 129.28, 255.00)\",\"rgb(0.00, 131.33, 255.00)\",\"rgb(0.00, 133.11, 255.00)\",\"rgb(0.00, 134.90, 255.00)\",\"rgb(0.00, 136.94, 255.00)\",\"rgb(0.00, 138.72, 255.00)\",\"rgb(0.00, 140.51, 255.00)\",\"rgb(0.00, 142.55, 255.00)\",\"rgb(0.00, 144.33, 255.00)\",\"rgb(0.00, 146.37, 255.00)\",\"rgb(0.00, 148.16, 255.00)\",\"rgb(0.00, 149.94, 255.00)\",\"rgb(0.00, 151.98, 255.00)\",\"rgb(0.00, 153.76, 255.00)\",\"rgb(0.00, 155.55, 255.00)\",\"rgb(0.00, 157.59, 255.00)\",\"rgb(0.00, 159.38, 255.00)\",\"rgb(0.00, 161.16, 255.00)\",\"rgb(0.00, 163.20, 255.00)\",\"rgb(0.00, 164.99, 255.00)\",\"rgb(0.00, 166.77, 255.00)\",\"rgb(0.00, 168.81, 255.00)\",\"rgb(0.00, 170.59, 255.00)\",\"rgb(0.00, 172.38, 255.00)\",\"rgb(0.00, 174.42, 255.00)\",\"rgb(0.00, 176.20, 255.00)\",\"rgb(0.00, 178.24, 255.00)\",\"rgb(0.00, 180.03, 255.00)\",\"rgb(0.00, 181.81, 255.00)\",\"rgb(0.00, 183.85, 255.00)\",\"rgb(0.00, 185.64, 255.00)\",\"rgb(0.00, 187.42, 255.00)\",\"rgb(0.00, 189.47, 255.00)\",\"rgb(0.00, 191.25, 255.00)\",\"rgb(0.00, 193.03, 255.00)\",\"rgb(0.00, 195.08, 255.00)\",\"rgb(0.00, 196.86, 255.00)\",\"rgb(0.00, 198.65, 255.00)\",\"rgb(0.00, 200.69, 255.00)\",\"rgb(0.00, 202.47, 255.00)\",\"rgb(0.00, 204.26, 255.00)\",\"rgb(0.00, 206.30, 255.00)\",\"rgb(0.00, 208.08, 255.00)\",\"rgb(0.00, 210.12, 255.00)\",\"rgb(0.00, 211.91, 255.00)\",\"rgb(0.00, 213.69, 255.00)\",\"rgb(0.00, 215.73, 255.00)\",\"rgb(0.00, 217.51, 255.00)\",\"rgb(0.00, 219.30, 255.00)\",\"rgb(0.00, 221.34, 255.00)\",\"rgb(0.00, 223.12, 255.00)\",\"rgb(0.00, 224.91, 255.00)\",\"rgb(0.00, 226.95, 255.00)\",\"rgb(0.00, 228.74, 255.00)\",\"rgb(0.00, 230.52, 255.00)\",\"rgb(0.00, 232.56, 255.00)\",\"rgb(0.00, 234.34, 255.00)\",\"rgb(0.00, 236.13, 255.00)\",\"rgb(0.00, 238.17, 255.00)\",\"rgb(0.00, 239.95, 255.00)\",\"rgb(0.00, 241.99, 255.00)\",\"rgb(0.00, 243.78, 255.00)\",\"rgb(0.00, 245.56, 255.00)\",\"rgb(0.00, 247.60, 255.00)\"],\"width\":4},\"mode\":\"lines\",\"showlegend\":false,\"x\":[50.0,50.133,50.53,51.191,52.114,53.297,54.736,56.428,58.368,60.551,62.971,65.622,68.497,71.588,74.887,78.385,82.073,85.941,89.979,94.176,98.521,103.002,107.609,112.327,117.146,122.051,127.031,132.072,137.16,142.282,147.425,152.575,157.718,162.84,167.928,172.969,177.949,182.854,187.673,192.391,196.998,201.479,205.824,210.021,214.059,217.927,221.615,225.113,228.412,231.503,234.378,237.029,239.449,241.632,243.572,245.264,246.703,247.886,248.809,249.47,249.867,250.0,250.133,250.53,251.191,252.114,253.297,254.736,256.428,258.368,260.551,262.971,265.622,268.497,271.588,274.887,278.385,282.073,285.941,289.979,294.176,298.521,303.002,307.609,312.327,317.146,322.051,327.031,332.072,337.16,342.282,347.425,352.575,357.718,362.84,367.928,372.969,377.949,382.854,387.673,392.391,396.998,401.479,405.824,410.021,414.059,417.927,421.615,425.113,428.412,431.503,434.378,437.029,439.449,441.632,443.572,445.264,446.703,447.886,448.809,449.47,449.867,450.0,449.962,449.85,449.662,449.4,449.062,448.649,448.161,447.598,446.96,446.247,445.459,444.596,443.657,442.644,441.556,440.392,439.154,437.84,436.451,434.988,433.449,431.835,430.146,428.382,426.543,424.629,422.64,420.576,418.437,416.223,413.933,411.569,409.129,406.615,404.025,401.36,398.621,395.806,392.916,389.951,386.911,383.796,380.606,377.341,374.001,370.585,367.095,363.53,359.889,356.174,352.383,348.518,344.577,340.561,336.47,332.304,328.063,323.747,319.356,314.89,310.349,305.733,301.041,296.275,291.434,286.517,281.526,276.459,271.317,266.101,260.809,255.442,250.0,244.558,239.191,233.899,228.683,223.541,218.474,213.483,208.566,203.725,198.959,194.267,189.651,185.11,180.644,176.253,171.937,167.696,163.53,159.439,155.423,151.482,147.617,143.826,140.111,136.47,132.905,129.415,125.999,122.659,119.394,116.204,113.089,110.049,107.084,104.194,101.379,98.64,95.975,93.385,90.871,88.431,86.067,83.777,81.563,79.424,77.36,75.371,73.457,71.618,69.854,68.165,66.551,65.012,63.549,62.16,60.846,59.608,58.444,57.356,56.343,55.404,54.541,53.753,53.04,52.402,51.839,51.351,50.938,50.6,50.338,50.15,50.038,50.0],\"y\":[175.0,169.852,164.718,159.611,154.545,149.533,144.589,139.725,134.955,130.291,125.745,121.33,117.058,112.939,108.985,105.206,101.611,98.212,95.016,92.032,89.269,86.732,84.43,82.368,80.551,78.985,77.674,76.62,75.828,75.298,75.033,75.033,75.298,75.828,76.62,77.674,78.985,80.551,82.368,84.43,86.732,89.269,92.032,95.016,98.212,101.611,105.206,108.985,112.939,117.058,121.33,125.745,130.291,134.955,139.725,144.589,149.533,154.545,159.611,164.718,169.852,175.0,169.852,164.718,159.611,154.545,149.533,144.589,139.725,134.955,130.291,125.745,121.33,117.058,112.939,108.985,105.206,101.611,98.212,95.016,92.032,89.269,86.732,84.43,82.368,80.551,78.985,77.674,76.62,75.828,75.298,75.033,75.033,75.298,75.828,76.62,77.674,78.985,80.551,82.368,84.43,86.732,89.269,92.032,95.016,98.212,101.611,105.206,108.985,112.939,117.058,121.33,125.745,130.291,134.955,139.725,144.589,149.533,154.545,159.611,164.718,169.852,175.0,179.11,183.219,187.329,191.438,195.548,199.658,203.767,207.877,211.986,216.096,220.205,224.315,228.425,232.534,236.644,240.753,244.863,248.973,253.082,257.192,261.301,265.411,269.521,273.63,277.74,281.849,285.959,290.068,294.178,298.288,302.397,306.507,310.616,314.726,318.836,322.945,327.055,331.164,335.274,339.384,343.493,347.603,351.712,355.822,359.932,364.041,368.151,372.26,376.37,380.479,384.589,388.699,392.808,396.918,401.027,405.137,409.247,413.356,417.466,421.575,425.685,429.795,433.904,438.014,442.123,446.233,450.342,454.452,458.562,462.671,466.781,470.89,475.0,470.89,466.781,462.671,458.562,454.452,450.342,446.233,442.123,438.014,433.904,429.795,425.685,421.575,417.466,413.356,409.247,405.137,401.027,396.918,392.808,388.699,384.589,380.479,376.37,372.26,368.151,364.041,359.932,355.822,351.712,347.603,343.493,339.384,335.274,331.164,327.055,322.945,318.836,314.726,310.616,306.507,302.397,298.288,294.178,290.068,285.959,281.849,277.74,273.63,269.521,265.411,261.301,257.192,253.082,248.973,244.863,240.753,236.644,232.534,228.425,224.315,220.205,216.096,211.986,207.877,203.767,199.658,195.548,191.438,187.329,183.219,179.11,175.0],\"z\":[0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18,0.18],\"type\":\"scatter3d\"},{\"marker\":{\"color\":\"red\",\"size\":2},\"mode\":\"markers\",\"showlegend\":false,\"x\":[],\"y\":[],\"z\":[],\"type\":\"scatter3d\"}], {\"template\":{\"data\":{\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"rgb(17,17,17)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"bar\":[{\"error_x\":{\"color\":\"#f2f5fa\"},\"error_y\":{\"color\":\"#f2f5fa\"},\"marker\":{\"line\":{\"color\":\"rgb(17,17,17)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#A2B1C6\",\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"minorgridcolor\":\"#506784\",\"startlinecolor\":\"#A2B1C6\"},\"baxis\":{\"endlinecolor\":\"#A2B1C6\",\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"minorgridcolor\":\"#506784\",\"startlinecolor\":\"#A2B1C6\"},\"type\":\"carpet\"}],\"choropleth\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"choropleth\"}],\"contourcarpet\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"contourcarpet\"}],\"contour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"contour\"}],\"heatmapgl\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"heatmapgl\"}],\"heatmap\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"heatmap\"}],\"histogram2dcontour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2dcontour\"}],\"histogram2d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2d\"}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"mesh3d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"mesh3d\"}],\"parcoords\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"parcoords\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}],\"scatter3d\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatter3d\"}],\"scattercarpet\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattercarpet\"}],\"scattergeo\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattergeo\"}],\"scattergl\":[{\"marker\":{\"line\":{\"color\":\"#283442\"}},\"type\":\"scattergl\"}],\"scattermapbox\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattermapbox\"}],\"scatterpolargl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolargl\"}],\"scatterpolar\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolar\"}],\"scatter\":[{\"marker\":{\"line\":{\"color\":\"#283442\"}},\"type\":\"scatter\"}],\"scatterternary\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterternary\"}],\"surface\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"surface\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#506784\"},\"line\":{\"color\":\"rgb(17,17,17)\"}},\"header\":{\"fill\":{\"color\":\"#2a3f5f\"},\"line\":{\"color\":\"rgb(17,17,17)\"}},\"type\":\"table\"}]},\"layout\":{\"annotationdefaults\":{\"arrowcolor\":\"#f2f5fa\",\"arrowhead\":0,\"arrowwidth\":1},\"autotypenumbers\":\"strict\",\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]],\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]},\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#f2f5fa\"},\"geo\":{\"bgcolor\":\"rgb(17,17,17)\",\"lakecolor\":\"rgb(17,17,17)\",\"landcolor\":\"rgb(17,17,17)\",\"showlakes\":true,\"showland\":true,\"subunitcolor\":\"#506784\"},\"hoverlabel\":{\"align\":\"left\"},\"hovermode\":\"closest\",\"mapbox\":{\"style\":\"dark\"},\"paper_bgcolor\":\"rgb(17,17,17)\",\"plot_bgcolor\":\"rgb(17,17,17)\",\"polar\":{\"angularaxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"},\"bgcolor\":\"rgb(17,17,17)\",\"radialaxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"}},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"rgb(17,17,17)\",\"gridcolor\":\"#506784\",\"gridwidth\":2,\"linecolor\":\"#506784\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#C8D4E3\"},\"yaxis\":{\"backgroundcolor\":\"rgb(17,17,17)\",\"gridcolor\":\"#506784\",\"gridwidth\":2,\"linecolor\":\"#506784\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#C8D4E3\"},\"zaxis\":{\"backgroundcolor\":\"rgb(17,17,17)\",\"gridcolor\":\"#506784\",\"gridwidth\":2,\"linecolor\":\"#506784\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#C8D4E3\"}},\"shapedefaults\":{\"line\":{\"color\":\"#f2f5fa\"}},\"sliderdefaults\":{\"bgcolor\":\"#C8D4E3\",\"bordercolor\":\"rgb(17,17,17)\",\"borderwidth\":1,\"tickwidth\":0},\"ternary\":{\"aaxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"},\"bgcolor\":\"rgb(17,17,17)\",\"caxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"}},\"title\":{\"x\":0.05},\"updatemenudefaults\":{\"bgcolor\":\"#506784\",\"borderwidth\":0},\"xaxis\":{\"automargin\":true,\"gridcolor\":\"#283442\",\"linecolor\":\"#506784\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"#283442\",\"zerolinewidth\":2},\"yaxis\":{\"automargin\":true,\"gridcolor\":\"#283442\",\"linecolor\":\"#506784\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"#283442\",\"zerolinewidth\":2}}},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"black\",\"nticks\":10,\"range\":[49.998999999999995,450.001]},\"yaxis\":{\"backgroundcolor\":\"black\",\"nticks\":10,\"range\":[75.01557662428436,475.0175766242844]},\"zaxis\":{\"backgroundcolor\":\"black\",\"nticks\":10,\"range\":[0,400.002]},\"camera\":{\"eye\":{\"x\":-0.5,\"y\":-1.0,\"z\":0.0},\"center\":{\"x\":0,\"y\":0,\"z\":-0.5}},\"aspectmode\":\"cube\"},\"margin\":{\"l\":10,\"r\":10,\"b\":10,\"t\":10,\"pad\":4},\"paper_bgcolor\":\"black\",\"width\":800,\"height\":500}, {\"responsive\": true} ).then(function(){\n",
" \n",
"var gd = document.getElementById('249b5516-f0e4-4bd3-be27-bb4d788d0c42');\n",
"var x = new MutationObserver(function (mutations, observer) {{\n",
" var display = window.getComputedStyle(gd).display;\n",
" if (!display || display === 'none') {{\n",
" console.log([gd, 'removed!']);\n",
" Plotly.purge(gd);\n",
" observer.disconnect();\n",
" }}\n",
"}});\n",
"\n",
"// Listen for the removal of the full notebook cells\n",
"var notebookContainer = gd.closest('#notebook-container');\n",
"if (notebookContainer) {{\n",
" x.observe(notebookContainer, {childList: true});\n",
"}}\n",
"\n",
"// Listen for the clearing of the current output cell\n",
"var outputEl = gd.closest('.output');\n",
"if (outputEl) {{\n",
" x.observe(outputEl, {childList: true});\n",
"}}\n",
"\n",
" }) }; </script> </div>\n",
"</body>\n",
"</html>"
]
},
"metadata": {}
}
],
"source": [
"# preview the design\n",
"\n",
"fc.transform(steps, 'plot', fc.PlotControls(color_type='print_sequence'))\n",
"# uncomment the next line to create a neat preview (click the top-left button in the plot for a .png file) - post and tag @FullControlXYZ :)\n",
"# fc.transform(steps, 'plot', fc.PlotControls(neat_for_publishing=True)) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 17
},
"id": "tggFoUeJReQR",
"outputId": "bec2fc74-a12d-4fef-8c6b-cc536c666a5b"
},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Javascript object>"
],
"application/javascript": [
"\n",
" async function download(id, filename, size) {\n",
" if (!google.colab.kernel.accessAllowed) {\n",
" return;\n",
" }\n",
" const div = document.createElement('div');\n",
" const label = document.createElement('label');\n",
" label.textContent = `Downloading \"${filename}\": `;\n",
" div.appendChild(label);\n",
" const progress = document.createElement('progress');\n",
" progress.max = size;\n",
" div.appendChild(progress);\n",
" document.body.appendChild(div);\n",
"\n",
" const buffers = [];\n",
" let downloaded = 0;\n",
"\n",
" const channel = await google.colab.kernel.comms.open(id);\n",
" // Send a message to notify the kernel that we're ready.\n",
" channel.send({})\n",
"\n",
" for await (const message of channel.messages) {\n",
" // Send a message to notify the kernel that we're ready.\n",
" channel.send({})\n",
" if (message.buffers) {\n",
" for (const buffer of message.buffers) {\n",
" buffers.push(buffer);\n",
" downloaded += buffer.byteLength;\n",
" progress.value = downloaded;\n",
" }\n",
" }\n",
" }\n",
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
" const a = document.createElement('a');\n",
" a.href = window.URL.createObjectURL(blob);\n",
" a.download = filename;\n",
" div.appendChild(a);\n",
" a.click();\n",
" div.remove();\n",
" }\n",
" "
]
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Javascript object>"
],
"application/javascript": [
"download(\"download_754d8936-b4e4-4a2b-8260-6563d244ba46\", \"my_design.gcode\", 9429)"
]
},
"metadata": {}
}
],
"source": [
"# generate and save gcode\n",
"\n",
"gcode_controls = fc.GcodeControls(\n",
" printer_name=printer_name,\n",
" initialization_data={\n",
" 'primer': 'front_lines_then_y',\n",
" 'print_speed': print_speed,\n",
" 'nozzle_temp': nozzle_temp,\n",
" 'bed_temp': bed_temp,\n",
" 'fan_percent': fan_percent,\n",
" 'extrusion_width': EW,\n",
" 'extrusion_height': EH})\n",
"gcode = fc.transform(steps, 'gcode', gcode_controls)\n",
"open(f'{design_name}.gcode', 'w').write(gcode)\n",
"files.download(f'{design_name}.gcode')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "NTRSnY-ffhV4"
},
"source": [
"#### please tell us what you're doing with FullControl!\n",
"\n",
"- tag FullControlXYZ on social media ([twitter](https://twitter.com/FullControlXYZ), [instagram](https://www.instagram.com/fullcontrolxyz/), [linkedin](https://www.linkedin.com/in/andrew-gleadall-068587119/), [tiktok](https://www.tiktok.com/@fullcontrolxyz))\n",
"- email [[email protected]](mailto:[email protected])\n",
"- post on the [subreddit](https://reddit.com/r/fullcontrol)\n",
"- post in the [github discussions or issues tabs](https://github.com/FullControlXYZ/fullcontrol/issues)\n",
"\n",
"in publications, please cite the original FullControl paper and the github repo for the new python version:\n",
"\n",
"- Gleadall, A. (2021). FullControl GCode Designer: open-source software for unconstrained design in additive manufacturing. Additive Manufacturing, 46, 102109. \n",
"- Gleadall, A. and Leas, D. (2023). FullControl [electronic resource: python source code]. available at: https://github.com/FullControlXYZ/fullcontrol"
]
}
],
"metadata": {
"colab": {
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@dicksondickson
Copy link

dicksondickson commented Apr 30, 2023

Fixed scale issue and cleaned up code and moved vars to top so its more clear.

WORKFLOW: In whatever program you are creating the SVG, work in pixel units, export/save as SVG then load into FC.

# derived from https://stackoverflow.com/questions/69313876/how-to-get-points-of-the-svg-paths

from svg.path import parse_path
from xml.dom import minidom


density = 2 # set point density
scale = 1 # set SVG scale factor
offset = (0,0) # set SVG coordinate offset



def get_point_at(path, distance, scale, offset, height):
    pos = path.point(distance)
    pos += offset
    pos *= scale
    return pos.real, height - pos.imag  # invert the y-coordinate


def points_from_path(path, density, scale, offset, height):
    step = int(path.length() * density)
    last_step = step - 1

    if last_step == 0:
        yield get_point_at(path, 0, scale, offset, height)
        return

    for distance in range(step):
        yield get_point_at(path, distance / last_step, scale, offset, height)


def points_from_doc(doc, density, scale, offset):
    height = float(doc.getElementsByTagName("svg")[0].getAttribute("viewBox").split()[3])
    offset = offset[0] + offset[1] * 1j
    points = []
    for element in doc.getElementsByTagName("path"):
        for path in parse_path(element.getAttribute("d")):
            points.extend(points_from_path(path, density, scale, offset, height))

    return points


def svg_to_points(svg_str: str, z_height: float) -> list:
    doc = minidom.parseString(svg_str)
    points = points_from_doc(doc, density, scale, offset)
    doc.unlink()
    return [fc.Point(x=pt[0], y=pt[1], z=z_height) for pt in points]

READING SVG FILE

svgFile = "type_px.svg"

with open(svgFile, 'rb') as f:
    svg = f.read().decode('utf-8')

SVG FILE

type_px

OUTPUT

Screenshot 2023-04-30 002854

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment