3D Printing Wiki

Advancing 3D printing mastery

User Tools

Site Tools


03_designing_for_3d_printing:02_design_with_svg

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
03_designing_for_3d_printing:02_design_with_svg [2024/10/16 11:30] jattie03_designing_for_3d_printing:02_design_with_svg [2024/10/18 09:39] (current) – [Create a SVG using Python code] jattie
Line 1: Line 1:
-~~NOTOC~~+~~CLOSETOC~~
 |<100% 25% - >| |<100% 25% - >|
 ^  \\ 3D PRINTING AND DESIGN REFERENCE DOCUMENT\\ \\   ^^ ^  \\ 3D PRINTING AND DESIGN REFERENCE DOCUMENT\\ \\   ^^
Line 5: Line 5:
 ^  Document No.:|1729077206| ^  Document No.:|1729077206|
 ^  Author(s):|jattie| ^  Author(s):|jattie|
-^  Contributor(s):|https://www.printables.com/@yba2cuo3_12119  |+^  Contributor(s):|[[https://www.printables.com/@yba2cuo3_12119|yba2cuo3]]  |
  
  
Line 17: Line 17:
 ---- ----
  
-====== Design using SVG's ======+====== Design generating SVG'with Python ======
  
  
 SVG's(Scalable Vector Graphics) are very powerful in designs because of the scalability. Any existing logo or image can be converted to a .svg and as I recently discovered during a conversation with [[https://www.printables.com/@yba2cuo3_12119|@yba2cuo3]] on printables, there are very cool svg libraries available in python to exploit and generate sophisticated and intricate details for 3D designs.  SVG's(Scalable Vector Graphics) are very powerful in designs because of the scalability. Any existing logo or image can be converted to a .svg and as I recently discovered during a conversation with [[https://www.printables.com/@yba2cuo3_12119|@yba2cuo3]] on printables, there are very cool svg libraries available in python to exploit and generate sophisticated and intricate details for 3D designs. 
  
 +This page aims to showcase this use case.
 ===== Create a SVG using Python code ===== ===== Create a SVG using Python code =====
  
-The majority of this code was generated in copilot and I played around with the parameters until I managed to get what I wanted to see in the svg. +The idea was inspired by the [[https://www.printables.com/model/998688-heliochronometer-worlds-most-accurate-sundial|Heliochronometer project on printables]] and discussions with the designer on the faceplates and dual colour designs.  
 + 
 +The majority of the code was generated in copilot and then adjusting the parameters until to get a similar faceplate dial in the svg as can be seen in the original design 
 + 
 +<WRAP center round info 60%> 
 + 
 +**My initial prompt to copilot was:**\\  
 +create python code to generate a 24hour sundial face with roman numerals, hour line, half hour lines, 15 minute and 5 minute lines at varying lengths and produce an svg 
 + 
 +</WRAP>
  
 <code python create_sundial_svg.py> <code python create_sundial_svg.py>
Line 108: Line 118:
 This is the SVG file, right click this to download directly for use. This is the SVG file, right click this to download directly for use.
 </WRAP> </WRAP>
 +
 +<code python improved_version.py>
 +import svgwrite
 +import math
 +
 +# Create a canvas of 200mm x 200mm
 +#conda install dwg = svgwrite.Drawing('circle_with_dividers_and_numerals.svg', profile='tiny', size=('200mm', '200mm'))
 +# Create a canvas of 200mm x 200mm with units set to millimeters
 +dwg = svgwrite.Drawing('circle_with_dividers_and_numerals.svg', profile='full', size=('200mm', '200mm'), viewBox=('0 0 200 200'))
 +
 +# Draw a circle in the middle with a diameter of 140mm and 2mm wide
 +circle_center = (100, 100)
 +circle_radius = 70
 +dwg.add(dwg.circle(center=circle_center, r=circle_radius, stroke='black', fill='none', stroke_width=2))
 +
 +# Function to create equal divider lines around the inner circumference of the circle
 +def create_divider_lines(dwg, center, radius, num_lines, line_length, line_width):
 +    angle_step = 360 / num_lines
 +    center_x, center_y = center
 +    for i in range(num_lines):
 +        angle = math.radians(i * angle_step)
 +        start_x = center_x + (radius - line_width / 2) * math.cos(angle)
 +        start_y = center_y + (radius - line_width / 2) * math.sin(angle)
 +        end_x = center_x + (radius - line_width / 2 - line_length) * math.cos(angle)
 +        end_y = center_y + (radius - line_width / 2 - line_length) * math.sin(angle)
 +        dwg.add(dwg.line(start=(start_x, start_y), end=(end_x, end_y), stroke='black', stroke_width=line_width))
 +
 +# Function to add Roman numerals around the outer circumference of the circle
 +def add_roman_numerals(dwg, center, radius, num_numerals):
 +    roman_numerals = ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII"]
 +    roman_numerals = roman_numerals*2
 +    angle_step = 360 / num_numerals
 +    center_x, center_y = center
 +    for i in range(num_numerals):
 +        angle = math.radians(i * angle_step - 90)  # Adjust angle to start from the top
 +        text_x = center_x + radius * math.cos(angle)
 +        text_y = center_y + radius * math.sin(angle)
 +        #dwg.add(dwg.text(roman_numerals[i % len(roman_numerals)], insert=(text_x, text_y + 3), text_anchor="middle", font_size="10pt"))
 +        rotation_angle = i * angle_step
 +        dwg.add(dwg.text(roman_numerals[i % 24], insert=(text_x, text_y + 0), text_anchor="middle", font_size="8pt", 
 +                         transform=f"rotate({rotation_angle} {text_x},{text_y + 0})"))
 +
 +
 +# Use the function to create 24 divider lines of 18mm long and 1mm wide
 +create_divider_lines(dwg, circle_center, circle_radius, 24, 10, 0.8)
 +create_divider_lines(dwg, circle_center, circle_radius, 24*2, 7, 0.8)
 +create_divider_lines(dwg, circle_center, circle_radius, 24*4, 6, 0.4)
 +create_divider_lines(dwg, circle_center, circle_radius, 24*12, 4, 0.4)
 +
 +# Add one set of Roman numerals around the outer circumference of the circle
 +add_roman_numerals(dwg, circle_center, circle_radius + 3, 24)
 +
 +# Save the SVG file
 +dwg.save(pretty=True, indent=2)
 +
 +print("SVG saved: 'circle_with_dividers_and_numerals.svg'")
 +
 +</code>
 +
 +===== How to use the SVG in Fusion360 =====
 +
 +<WRAP center round todo 60%>
 +At the moment there is some fusion specific issue encountered importing the python generated SVG. It seems related to scaling and coordinate calculations. I suspect them to also be related to radians.
 +</WRAP>
 +
 +{{:03_designing_for_3d_printing:screenshot_2024-10-17_091637.png?nolink|}}
 +
  
03_designing_for_3d_printing/02_design_with_svg.1729078244.txt.gz · Last modified: 2024/10/16 11:30 by jattie