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 CreateForm(): "create a form with n pages." #check whether view exist. ViewName = 'KT_FORM' for view in ktDraft.GetViews(): if view[1] == 'KT_FORM': print 'view already exist.' return hd = kcs_draft.view_new(ViewName) res = kcs_ui.int_req("How many pages do you want?", 1) if res[0] == kcs_util.ok(): for i in range(res[1]): pg = Page() pg.Location = Point2D(i * 420, 0) pg.Index = i + 1 kcs_draft.subpicture_current_set(hd) pg.Draw() kcs_draft.dwg_purge()
def Draw(self): "Draw table on current drawing" if self.Handle==None: #create a new view for this table #get the max index and create view tbViews=ktDraft.GetViews(r'^KT_TABLE_.\d*$') maxIndex=1 if len(tbViews)>0: maxIndex=max([int(i[1][9:]) for i in tbViews])+1 viewName='KT_TABLE_%s'%(maxIndex) self.Handle=kcs_draft.view_new(viewName) kcs_draft.subpicture_current_set(self.Handle) #create subview subName='KT%sX%s'%(self.NColumn,self.NRow) hdSub=kcs_draft.subview_new(subName) #create component for cells for c in self.Cells: kcs_draft.subpicture_current_set(hdSub) c.Draw() else: for c in self.Cells: c.Draw() kcs_draft.subpicture_current_set()
def GetKtView(): #obsolete, do not use it. """返回KNOT_VIEW handle""" try: return kcs_draft.view_identify("KNOT_VIEW") except: return kcs_draft.view_new("KNOT_VIEW")