03_designing_for_3d_printing:02_design_with_svg
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
03_designing_for_3d_printing:02_design_with_svg [2024/10/16 11:34] – [Design using SVG's] jattie | 03_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.: | ^ Document No.: | ||
^ Author(s): | ^ Author(s): | ||
- | ^ Contributor(s): | + | ^ Contributor(s): |
Line 25: | Line 25: | ||
===== 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 | + | The idea was inspired by the [[https:// |
+ | |||
+ | The majority of the code was generated in copilot and then adjusting | ||
+ | |||
+ | <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 | ||
+ | |||
+ | </ | ||
<code python create_sundial_svg.py> | <code python create_sundial_svg.py> | ||
Line 109: | 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. | ||
</ | </ | ||
+ | |||
+ | <code python improved_version.py> | ||
+ | import svgwrite | ||
+ | import math | ||
+ | |||
+ | # Create a canvas of 200mm x 200mm | ||
+ | #conda install dwg = svgwrite.Drawing(' | ||
+ | # Create a canvas of 200mm x 200mm with units set to millimeters | ||
+ | dwg = svgwrite.Drawing(' | ||
+ | |||
+ | # 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, | ||
+ | |||
+ | # Function to create equal divider lines around the inner circumference of the circle | ||
+ | def create_divider_lines(dwg, | ||
+ | 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, | ||
+ | |||
+ | # Function to add Roman numerals around the outer circumference of the circle | ||
+ | def add_roman_numerals(dwg, | ||
+ | roman_numerals = [" | ||
+ | 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) | ||
+ | # | ||
+ | rotation_angle = i * angle_step | ||
+ | dwg.add(dwg.text(roman_numerals[i % 24], insert=(text_x, | ||
+ | | ||
+ | |||
+ | |||
+ | # Use the function to create 24 divider lines of 18mm long and 1mm wide | ||
+ | create_divider_lines(dwg, | ||
+ | create_divider_lines(dwg, | ||
+ | create_divider_lines(dwg, | ||
+ | create_divider_lines(dwg, | ||
+ | |||
+ | # Add one set of Roman numerals around the outer circumference of the circle | ||
+ | add_roman_numerals(dwg, | ||
+ | |||
+ | # Save the SVG file | ||
+ | dwg.save(pretty=True, | ||
+ | |||
+ | print(" | ||
+ | |||
+ | </ | ||
===== How to use the SVG in Fusion360 ===== | ===== How to use the SVG in Fusion360 ===== | ||
<WRAP center round todo 60%> | <WRAP center round todo 60%> | ||
- | Coming soon | + | 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. |
</ | </ | ||
+ | {{: | ||
03_designing_for_3d_printing/02_design_with_svg.1729078467.txt.gz · Last modified: 2024/10/16 11:34 by jattie