Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
KiCAD 5978, Python 2.7.2, Copper Fill Polygon Drawing Script
import sys, os
import shutil
import math
LIST_pts = [" (polygon\n (pts\n (xy "," (filled_polygon\n (pts\n (xy ",") (xy ",")\n )\n )"]
def FNC_poly (cntr, # (x,y)
radius,
sides,
startangle,
angle,
):
STR_data = ""
baseX = cntr[0]
baseY = cntr[1]
sideangle = angle / sides
for i in range(sides):
pointX = baseX + radius * math.sin(math.radians(sideangle*(i+0.5) + startangle))
pointY = baseY + radius * math.cos(math.radians(sideangle*(i+0.5) + startangle))
STR_data += "{:.4f}".format(pointX) + " " + "{:.4f}".format(pointY) + LIST_pts[2]
STR_data = STR_data[:-6] + LIST_pts[3]
return LIST_pts[0] + STR_data + "\n" + LIST_pts[1] + STR_data
if __name__ == '__main__':
Center = [105.0,105.0] # x/y coordinates of the centre of the pcb sheet
Radius = 30 # mm
Sides = 12
StartAngle = 30.0 # degrees
Angle = 270.0 # degrees
print FNC_poly (Center,
Radius,
Sides,
StartAngle,
Angle,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment