Files
wheel/scripts/render_kfl_plate_draft.py

46 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Draw a clearly provisional dimension diagram for the KFL001 plate."""
from pathlib import Path
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import landscape,A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib.colors import HexColor
import pypdfium2
out=Path(r'C:\projects\wheel\models\kfl001_plate_draft')
pdfmetrics.registerFont(TTFont('Chinese',r'C:\Windows\Fonts\simhei.ttf'))
p=out/'KFL001板_尺寸草图_禁止加工.pdf'
c=canvas.Canvas(str(p),pagesize=landscape(A4));W,H=landscape(A4)
c.setTitle('KFL001 mounting plate - provisional dimensions')
def txt(x,y,t,size=11,color='#17202a'):
c.setFillColor(HexColor(color));c.setFont('Chinese',size);c.drawString(x,y,t)
def ln(x1,y1,x2,y2,col='#444444',width=.7):
c.setStrokeColor(HexColor(col));c.setLineWidth(width);c.line(x1,y1,x2,y2)
def tick(x,y):ln(x-3,y-3,x+3,y+3)
txt(36,555,'KFL001 固定板尺寸草图',23)
txt(36,532,'草图:中心孔仅按直径 39 mm 示意,必须实测后才能加工',13,'#B42318')
txt(36,512,'两块几何相同;厚 8 mm;下方尺寸单位均为 mm',11)
k=3.6;x0=110;y0=125;w=76*k;h=80*k;cx=x0+w/2;cy=y0+51*k
c.setFillColor(HexColor('#eef2f6'));c.setStrokeColor(HexColor('#263444'));c.setLineWidth(1.1);c.rect(x0,y0,w,h,fill=1,stroke=1)
c.setFillColor(HexColor('#ffffff'));c.circle(cx,cy,19.5*k,stroke=1,fill=1)
for xx in (-24,24):c.circle(cx+xx*k,cy,3.5*k,stroke=1,fill=1)
for xx in (-23.5,23.5):c.roundRect(cx+(xx-4.75)*k,y0+(9-2.75)*k,9.5*k,5.5*k,2.75*k,stroke=1,fill=1)
c.setDash(4,3);ln(cx-23*k,cy,cx+23*k,cy,'#858b93',.5);ln(cx,cy-23*k,cx,cy+23*k,'#858b93',.5);c.setDash()
# Outside dimensions: overall width, height, axis height and KFL bolt pitch.
for x in (x0,x0+w):ln(x,y0-3,x,y0-31)
ln(x0,y0-23,x0+w,y0-23);tick(x0,y0-23);tick(x0+w,y0-23);txt(cx-8,y0-19,'76',10)
for y in (y0,y0+h):ln(x0-2,y,x0-38,y)
ln(x0-30,y0,x0-30,y0+h);tick(x0-30,y0);tick(x0-30,y0+h);txt(x0-50,y0+h/2,'80',10)
ln(x0+w+10,y0,x0+w+38,y0);ln(x0+w+10,cy,x0+w+38,cy)
ln(x0+w+30,y0,x0+w+30,cy);tick(x0+w+30,y0);tick(x0+w+30,cy);txt(x0+w+34,y0+(cy-y0)/2,'51',10)
by=cy+30*k
for x in (cx-24*k,cx+24*k):ln(x,cy+4*k,x,by+4)
ln(cx-24*k,by,cx+24*k,by);tick(cx-24*k,by);tick(cx+24*k,by);txt(cx-8,by+5,'48',10)
txt(472,454,'孔位说明',15)
for i,t in enumerate(['1 中心孔:直径 39 暂定,真实凸起待实测','2 两侧轴承孔:直径 7,孔距 48','3 底部两槽:9.5 × 5.5,横向','4 两槽中心距 47,槽心距底边 9','5 M5 名义横向总行程 4.5','6 中心孔到轴承孔边名义余量仅 1','7 直径 12 垫圈向中心孔悬出约 1.5','8 与 3030 连接用长角码及实物复核']):txt(472,424-i*24,t,11,'#B42318' if i in (0,5,6) else '#17202a')
ln(472,217,805,217,'#b9c0c9');txt(472,196,'中心孔可能需要改小或改轮廓,',11,'#B42318');txt(472,178,'请勿用本图或草模直接下单加工。',11,'#B42318')
txt(36,42,'注意:圆孔、板边与调节槽均贯穿,轴承真实外形、螺丝及垫圈待核对。',10)
c.showPage();c.save()
doc=pypdfium2.PdfDocument(str(p));page=doc[0];page.render(scale=1.6).to_pil().save(str(out/'尺寸草图_禁止加工.png'))