# coding: cp1251 # 2D-API|Демо|2D построение import Kompas6API5, LDefin2D import func2d import math Kompas, doc2d = start2d() # Фланец td = 60 tD = 100 tB = 45 totd = 10 totos = td+(tD-td)/2 totbr = 6 # Основание pL = 60 pH = 40 pS = 12 pB = 75 ps = 2 pbaza = pL-20 # Ребро rdL = 10 rH = 30 rB = 8 rh = 10 rang = 20 # Виды front = True top = False left = False kap = False read( td='01.Диаметр 1' , tD='02.Диаметр 2' , tB='02.Ширина' , totd='03.Диам. отверстий 3' , totos='04.Диам. размещ. болтов' , totbr='05.Количество болтовых отв.' , pL = '06.Пята L' , pH = '07.Пята H' , pB = '08.Пята B' , pS = '08.Пята S' , ps = '09.Пята 2' , rdL = '10.Ребро dL', rB = '11.Ребро B' , rH = '11.Ребро H' , rh = '12.Ребро h' , rang = '13.Ребро ', front = '14.Вид спереди', top = '15.Вид сверху' , left = '16.Вид слева', ) t1x = tD/2 t1y = 0 t_top1x = 0 t_top1y = tB/2 t_top2x = math.sqrt(tD/2*tD/2-pS*pS) t_top2y = tB/2 t_top3x = t_top2x t_top3y = rB/2 t_left1x = 0 t_left1y = tD/2 t_left2x = tB/2 t_left2y = tD/2 t_left3x = tB/2 t_left3y = pS t_left4x = tB/2 t_left4y = 0 t_left5x = tB/2 t_left5y = -tD/2 t_left6x = 0 t_left6y = -tD/2 # пета p1x = math.sqrt(tD/2*tD/2-ps*ps) p1y = ps p2x = tD/2+pL-pbaza p2y = ps p3x = tD/2+pL-pbaza p3y = 0 p4x = tD/2+pL p4y = 0 p5x = tD/2+pL p5y = pS p6x = t_top3x p6y = pS p_top1x = t_top2x p_top1y = t_top2y p_top2x = p2x p_top2y = pB/2 p_top3x = p5x p_top3y = p_top2y p_top4x = p5x p_top4y = 0 p_left1x = 0 p_left1y = pS p_left2x = pB/2 p_left2y = pS p_left3x = pB/2 p_left3y = 0 p_left4x = 0 p_left4y = 0 # ребро rrad_l = math.pi*(90-rang)/180 r1x = math.sqrt(tD/2*tD/2-pS*pS) r2x = tD/2+pL-rdL r2y = pS r3x = tD/2+pL-rdL r3y = pS+rh r4x = (tD/2+pL-rdL)-(math.tan(rrad_l)*(rH-rh)) r4y = pS+rH r5x = math.sqrt(tD/2*tD/2-(pS+rH)*(pS+rH)) r5y =pS+rH r4x = r5x+rh+5 r4y = pS+rH r_top1x = r5x r_top1y = 0 r_top2x = r5x r_top2y = rB/2 r_top3x = r4x r_top3y = r_top2y r_top4x = r3x r_top4y = r_top2y r_top5x = r3x r_top5y = 0 r_top6x = r4x r_top6y = r_top2y r_top7x = r4x r_top7y = 0 r_left1x = 0 r_left1y = r4y r_left2x = rB/2 r_left2y = r4y r_left3x = r_left2x r_left3y = pS r_left4x = 0 r_left4y = pS r_left5x = r_left2x r_left5y = r3y r_left6x = 0 r_left6y = r3y kD = tD-4 kds = kD*0.625 kSf = 6 kSs = 5 k_top1x = 0 k_top1y = kD/2 k_top2x = kSf k_top2y = kD/2 k_top3x = k_top2x k_top3y = kds/2 k_top4x = kSf+kSs k_top4y = k_top3y k_top5x = k_top4x k_top5y = 0 k_top6x = k_top2x k_top6y = 0 if front: doc2d.ksMacro(1) doc2d.ksCircle( 0,0,td/2,1 ) doc2d.ksCircle( 0,0,tD/2,1 ) doc2d.ksCircle( 0,0,totos/2,3 ) i=1 while i < totbr+1: a = math.pi * 2 * i / totbr x = math.cos( a ) * totos/2 y = math.sin( a ) * totos/2 doc2d.ksCircle( x,y,totd/2,1 ) i+=1 j=3 i=1 a=1 while i < j: i+=1 doc2d.ksLineSeg( a*p1x,p1y, a*p2x,p2y,1 ) doc2d.ksLineSeg( a*p2x,p2y, a*p3x,p3y,1 ) doc2d.ksLineSeg( a*p3x,p3y, a*p4x,p4y,1 ) doc2d.ksLineSeg( a*p4x,p4y, a*p5x,p5y,1 ) doc2d.ksLineSeg( a*p5x,p5y, a*p6x,p6y,1 ) doc2d.ksLineSeg( a*r2x,r2y, a*r3x,r3y,1 ) doc2d.ksLineSeg( a*r3x,r3y, a*r4x,r4y,1 ) doc2d.ksLineSeg( a*r4x,r4y, a*r5x,r5y,1 ) a = -1 doc2d.ksEndObj() if top: doc2d.ksMacro(1) j=5 i=0 a=1 b=1 while i < j: i+=1 doc2d.ksLineSeg( a*t_top1x, b*t_top1y, a*t_top2x, b*t_top2y,1 ) doc2d.ksLineSeg( a*t_top2x, b*t_top2y, a*t_top3x, b*t_top3y,1 ) doc2d.ksLineSeg( a*r_top1x, b*r_top1y, a*r_top2x, b*r_top2y,1 ) doc2d.ksLineSeg( a*r_top2x, b*r_top2y, a*r_top3x, b*r_top3y,1 ) doc2d.ksLineSeg( a*r_top3x, b*r_top3y, a*r_top4x, b*r_top4y,1 ) doc2d.ksLineSeg( a*r_top4x, b*r_top4y, a*r_top5x, b*r_top5y,1 ) doc2d.ksLineSeg( a*r_top6x, b*r_top6y, a*r_top7x, b*r_top7y,1 ) doc2d.ksLineSeg( a*p_top1x, b*p_top1y, a*p_top2x, b*p_top2y,1 ) doc2d.ksLineSeg( a*p_top2x, b*p_top2y, a*p_top3x, b*p_top3y,1 ) doc2d.ksLineSeg( a*p_top3x, b*p_top3y, a*p_top4x, b*p_top4y,1 ) if i==1 or i==3: a = -1 elif i == 2 : a = 1 b = -1 doc2d.ksEndObj() if left: doc2d.ksMacro(1) j=3 i=1 a=1 while i < j: i+=1 doc2d.ksLineSeg( a*t_left1x, t_left1y,a*t_left2x,t_left2y,1 ) doc2d.ksLineSeg( a*t_left2x, t_left2y,a*t_left3x,t_left3y,1 ) doc2d.ksLineSeg( a*t_left4x, t_left4y,a*t_left5x,t_left5y,1 ) doc2d.ksLineSeg( a*t_left5x, t_left5y,a*t_left6x,t_left6y,1 ) doc2d.ksLineSeg( a*p_left1x, p_left1y,a*p_left2x,p_left2y,1 ) doc2d.ksLineSeg( a*p_left2x, p_left2y,a*p_left3x,p_left3y,1 ) doc2d.ksLineSeg( a*p_left3x, p_left3y,a*p_left4x,p_left4y,1 ) doc2d.ksLineSeg( a*r_left1x, r_left1y,a*r_left2x,r_left2y,1 ) doc2d.ksLineSeg( a*r_left2x, r_left2y,a*r_left3x,r_left3y,1 ) doc2d.ksLineSeg( a*r_left5x, r_left5y,a*r_left6x,r_left6y,1 ) a = -1 doc2d.ksEndObj() if kap: doc2d.ksMacro(1) j=3 i=1 a=1 while i < j: i+=1 doc2d.ksLineSeg( k_top1x, a*k_top1y,k_top2x,a*k_top2y,1 ) doc2d.ksLineSeg( k_top2x, a*k_top2y,k_top3x,a*k_top3y,1 ) doc2d.ksLineSeg( k_top3x, a*k_top3y,k_top4x,a*k_top4y,1 ) doc2d.ksLineSeg( k_top4x, a*k_top4y,k_top5x,a*k_top5y,1 ) doc2d.ksLineSeg( k_top3x, a*k_top3y,k_top6x,a*k_top6y,1 ) a = -1 doc2d.ksEndObj()