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 revision | |||
03_designing_for_3d_printing:02_design_with_svg [2024/10/17 08:18] – [How to use the SVG in Fusion360] jattie | 03_designing_for_3d_printing:02_design_with_svg [2024/10/18 09:39] (current) – [Create a SVG using Python code] jattie | ||
---|---|---|---|
Line 118: | 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 ===== |
03_designing_for_3d_printing/02_design_with_svg.1729153131.txt.gz · Last modified: 2024/10/17 08:18 by jattie