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
03_designing_for_3d_printing:02_design_with_svg [2024/10/17 08:18] – [How to use the SVG in Fusion360] jattie03_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.
 </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 ===== ===== How to use the SVG in Fusion360 =====
03_designing_for_3d_printing/02_design_with_svg.txt · Last modified: 2024/10/18 09:39 by jattie