def run(): """ Do not place the fake vitesse file at python path. Place it at 'external libraries' of eclipse is recommended """ names = [i.__name__ for i in modList] res, action = kcs_ui.string_select( 'fake vitesse generator', 'Please select the module you want to generate fake vitesse py.', 'Press option to generate for all modules.', names) if res == kcs_util.ok(): mod = modList[action - 1] des = kcs_ui.string_req('Where do you want to place the file?', r'C:\temp') if des[0] == kcs_util.ok(): # des = os.path.join(os.path.join(os.getcwd(), "FakeVitesse")) fname = des[1] + "\\" + mod.__name__ + ".py" GenPy(mod, fname) elif res == kcs_util.options(): des = kcs_ui.string_req('Where do you want to place the file?', r'C:\temp') if des[0] == kcs_util.ok(): for mod in modList: fname = des[1] + "\\" + mod.__name__ + ".py" GenPy(mod, fname)
def run(): """ Do not place the fake vitesse file at python path. Place it at 'external libraries' of eclipse is recommended """ names = [i.__name__ for i in modList] res, action = kcs_ui.string_select( "fake vitesse generator", "Please select the module you want to generate fake vitesse py.", "Press option to generate for all modules.", names, ) if res == kcs_util.ok(): mod = modList[action - 1] des = kcs_ui.string_req("Where do you want to place the file?", r"C:\temp") if des[0] == kcs_util.ok(): # des = os.path.join(os.path.join(os.getcwd(), "FakeVitesse")) fname = des[1] + "\\" + mod.__name__ + ".py" GenPy(mod, fname) elif res == kcs_util.options(): des = kcs_ui.string_req("Where do you want to place the file?", r"C:\temp") if des[0] == kcs_util.ok(): for mod in modList: fname = des[1] + "\\" + mod.__name__ + ".py" GenPy(mod, fname)
def FindText(): res=kcs_ui.string_req('请输入需要查找的文字','') if res[0]==kcs_util.ok(): hdList=FindString(res[1]) if len(hdList) == 1: ZoomElement(hdList[0]) res=kcs_ui.answer_req('Find','是否要替换文本?') if res[0]==kcs_util.yes(): ReplaceOne(hdList[0]) elif len(hdList) > 1: ZoomElement(hdList[0]) index=1 while True: if index>len(hdList): kcs_ui.message_noconfirm("已经是最后一个") return res=kcs_ui.answer_req(r'共找到%s个,当前第%s个'%(len(hdList),index),'是否要替换文本?') if res==kcs_util.yes(): ReplaceOne(hdList[index-1]) index+=1 continue elif res==kcs_util.no(): ZoomElement(hdList[index]) index+=1 continue else: return elif len(hdList) == 0: kcs_ui.message_confirm("没有找到任何匹配的文字")
def Grid(): """Create a grid on a new view""" res=kcs_ui.string_req('请输入格子的长,宽、列数,行数','30,10,8,5') if res[0]==kcs_util.ok(): w,h,m,n=[float(i) for i in res[1].split(',')] pt=Point2D() res=kcs_ui.point2D_req('请选择Grid左上角位置,回车设为原点',pt) if res[0]==kcs_util.ok(): csm=CurrentSubpictureManager() hd=kcs_draft.view_new('') csm.Set(hd) for i in range(n+1): #horizontal line p1=Point2D(pt.X,pt.Y-h*i) p2=Point2D(pt.X+w*m,pt.Y-h*i) kcs_draft.line_new(Rline2D(p1,p2)) for j in range(m+1): #vertical line p1=Point2D(pt.X+j*w,pt.Y) p2=Point2D(pt.X+j*w,pt.Y-h*n) kcs_draft.line_new(Rline2D(p1,p2)) csm.Back() elif res[0]==kcs_util.operation_complete(): pt=Point2D(0,0) csm=CurrentSubpictureManager() hd=kcs_draft.view_new('') csm.Set(hd) for i in range(n+1): #horizontal line p1=Point2D(pt.X,pt.Y-h*i) p2=Point2D(pt.X+w*m,pt.Y-h*i) kcs_draft.line_new(Rline2D(p1,p2)) for j in range(m+1): #vertical line p1=Point2D(pt.X+j*w,pt.Y) p2=Point2D(pt.X+j*w,pt.Y-h*n) kcs_draft.line_new(Rline2D(p1,p2)) csm.Back()
def run(): pt = Point2D() res = kcs_ui.point2D_req('请选择中心点', pt) if res[0] == kcs_util.ok(): res2 = kcs_ui.string_req('请输入菱形的尺寸', '300,100') if res2[0] == kcs_util.ok(): li = [float(s) for s in res2[1].split(',')] if len(li) == 2: a, b = li else: raise 'wrong input' ktBasic.Diamond(res[1], a, b)
def run(): pt=Point2D() res=kcs_ui.point2D_req('请选择中心点',pt) if res[0]==kcs_util.ok(): res2=kcs_ui.string_req('请输入菱形的尺寸','300,100') if res2[0]==kcs_util.ok(): li=[float(s) for s in res2[1].split(',')] if len(li)==2: a,b=li else: raise 'wrong input' ktBasic.Diamond(res[1], a, b)
def FindAndReplace(): res, txt = kcs_ui.string_req("请输入需要查找的内容", "") if res == kcs_util.ok(): hdList = FindString(txt) if len(hdList) == 1: ZoomElement(hdList[0]) Replace(hdList) elif len(hdList) > 1: kcs_ui.message_noconfirm("找到" + str(len(hdList)) + "个匹配的文字,将显示第一个") ZoomElement(hdList[0]) Replace(hdList) elif len(hdList) == 0: kcs_ui.message_confirm("没有找到任何匹配的文字")
def ChangeColumnText(): pt=Point2D() res=kcs_ui.point2D_req('Please select the column',pt) if res[0]==kcs_util.ok(): hdView=kcs_draft.view_identify(res[1]) comp=kcs_draft.component_identify(res[1]) #get column index from comp name name=kcs_draft.subpicture_name_get(comp) colIndex=int(name[2:].split('X')[0]) table=Table(hdView) res=kcs_ui.string_req('Please enter the string','iknot') if res[0]==kcs_util.ok(): table.ChangeColumnText(colIndex, res[1])
def run(): pt=Point2D() res=kcs_ui.point2D_req('请选择中心点',pt) if res[0]==kcs_util.ok(): res2=kcs_ui.string_req('请输入外接圆半径、数量和旋转角度(默认为0)','100,6,0') if res2[0]==kcs_util.ok(): li=[float(s) for s in res2[1].split(',')] radius,number,angle=0.0,0.0,0.0 if len(li)==2: radius,number=li elif len(li)==3: radius,number,angle=li else: raise 'wrong input' ktBasic.Polygon(res[1], radius, number, angle)
def run(): pt = Point2D() res = kcs_ui.point2D_req('请选择中心点', pt) if res[0] == kcs_util.ok(): res2 = kcs_ui.string_req('请输入外接圆半径、数量和旋转角度(默认为0)', '100,6,0') if res2[0] == kcs_util.ok(): li = [float(s) for s in res2[1].split(',')] radius, number, angle = 0.0, 0.0, 0.0 if len(li) == 2: radius, number = li elif len(li) == 3: radius, number, angle = li else: raise 'wrong input' ktBasic.Polygon(res[1], radius, number, angle)
def ReplaceOne(hdText): "replace one text" txt=Text() kcs_draft.text_properties_get(hdText,txt) res=kcs_ui.string_req('请输入要替换的文本',txt.String) if res[0]==kcs_util.ok(): old = kcs_draft.subpicture_current_get() #make the old subpicture father = kcs_draft.element_parent_get(hdText) # 文字所在图层 txt.SetString(res[1]) kcs_draft.element_delete(hdText) # 删除原文字 kcs_draft.subpicture_current_set(father) # 重设图层 kcs_draft.text_new(txt) # 写文字 if len(old) == 3: kcs_draft.subpicture_current_set(old[2]) else: kcs_draft.subpicture_current_set()
def CreateEmptyTable(): """ Create an m x n table without text. """ res=kcs_ui.string_req('please enter the column number,row number and the width of each cell', '5,3,30') if res[0]==kcs_util.ok(): li=res[1].split(',') m,n,width=int(li[0]),int(li[1]),float(li[2]) pt=Point2D() res=kcs_ui.point2D_req('Please pick the left-top corner of table.',pt) if res[0]==kcs_util.ok(): t=Table() t.Init(m, n, width, res[1]) t.Draw()
def Replace(hdList): res = kcs_ui.answer_req("文字替换", "是否要替换文字?") if res == kcs_util.yes(): txt = Text() kcs_draft.text_properties_get(hdList[0], txt) res = kcs_ui.string_req("请输入要替换的文字", txt.GetString()) if res[0] == kcs_util.ok(): content = res[1] old = kcs_draft.subpicture_current_get() for hd in hdList: father = kcs_draft.element_parent_get(hd) # 文字所在图层 kcs_draft.text_properties_get(hd, txt) txt.SetString(content) kcs_draft.element_delete(hd) # 删除原文字 kcs_draft.subpicture_current_set(father) # 重设图层 kcs_draft.text_new(txt) # 写文字 if len(old) == 3: kcs_draft.subpicture_current_set(old[2]) else: kcs_draft.subpicture_current_set()
def main(): dataExtra = aadAssDataExtraction.DataExtraction() temp_file = '%s\\%s.txt' % ( os.environ['TEMP'], datetime.datetime.now().strftime('%y%m%d%H%M%S')) f = open(temp_file, 'w') f.writelines('%20s %20s %20s %20s %20s %20s\n' % ('设备名', '重量', 'X', 'Y', 'Z', '模块')) res, input_name = kcs_ui.string_req('请输入设备名称', '') if res == kcs_util.ok(): dex_str = "EQUIPMENT.ITEM('%s'*).NAME" % input_name dataExtra.ExtractData(dex_str) eqp_name_list = dataExtra.DataResult for eqp_name in eqp_name_list: dex_str = "EQUIPMENT.ITEM('%s').REFERENCE.POINT" % eqp_name dataExtra.ExtractData(dex_str) ref_point = dataExtra.DataResult[0] dex_str = "EQUIPMENT.ITEM('%s').COMP_NAME" % eqp_name dataExtra.ExtractData(dex_str) comp_name = dataExtra.DataResult[0] weight = 0 dex_str = "COMPONENT('%s').GEN_PROPERTY.WEIGHT" % comp_name dataExtra.ExtractData(dex_str) weight = dataExtra.DataResult[0] dex_str = "EQUIPMENT.ITEM('%s').MODULE(*).NAME" % eqp_name dataExtra.ExtractData(dex_str) mod_name = dataExtra.DataResult[0] f.writelines('%20s %20s %20s %20s %20s %20s\n' % (eqp_name, round(weight), round(ref_point[0]), round(ref_point[1]), round(ref_point[2]), mod_name)) f.close() os.startfile(temp_file)
def AddNote(): res=kcs_ui.string_req("请输入标注内容") if res[0]==kcs_util.ok(): content=res[1] cor1=Point2D() cor2=Point2D() res=kcs_ui.point2D_req("请选择标注点",cor1) if res[0]==kcs_util.ok(): res=kcs_ui.point2D_req("请选择标注文字位置",cor2) if res[0]==kcs_util.ok(): #开始标注 #记录原来状态 old=kcs_draft.subpicture_current_get() #创建component subView=ktDraft.GetKtSubView(SUB_VIEW_NAME) #检查是否在KNOT_VIEW下 parent=kcs_draft.element_parent_get(subView) parentName=kcs_draft.subpicture_name_get(parent) if parentName!="KNOT_VIEW": return kcs_draft.subpicture_current_set(subView) compName="NOTE_"+str(GetID(subView)) comp=kcs_draft.component_new(compName) kcs_draft.subpicture_current_set(comp) #写文字 txt=Text(content) txt.SetPosition(cor2) txt.SetColour(Colour("Red")) txt.SetFont("黑体") txt.SetHeight(5) hTxt=kcs_draft.text_new(txt) #画边框 rect=Rectangle2D() rect=kcs_draft.element_extent_get(hTxt) offset=1 rect.SetCorner1(Point2D(rect.Corner1.X-offset,rect.Corner1.Y-offset)) rect.SetCorner2(Point2D(rect.Corner2.X+offset,rect.Corner2.Y+offset)) hd=kcs_draft.rectangle_new(rect) kcs_draft.element_colour_set(hd,Colour("Red")) #画引线 sta=cor1 end=rect.GetCorner1() if end.X<sta.X: end.SetX(end.X+rect.Corner2.X-rect.Corner1.X) if end.Y<sta.Y: end.SetY(end.Y+rect.Corner2.Y-rect.Corner1.Y) line=Rline2D(sta,end) hd=kcs_draft.line_new(line) kcs_draft.element_colour_set(hd,Colour("Red")) #画圆圈 circle=Circle2D(sta,2) hd=kcs_draft.circle_new(circle) kcs_draft.element_colour_set(hd,Colour("Red")) #恢复原来状态 if len(old)==3: kcs_draft.subpicture_current_set(old[2]) else: kcs_draft.subpicture_current_set()