import copy #ステップ選択 #ポリゴンメッシュの面選択モードで、指定した間隔をあけて面をループ選択するスクリプト #メッシュツールウィジェットに追加する場合はutf-8の対応をしておく #辺もステップ選択できるように改良 #アルゴリズム変更(2010.02.10) #動作条件 #選択形状がポリゴンメッシュ #編集モードに入っている #面選択モード #面が一つ以上選択されている #最後に選択した面の頂点の数が4個(ループ選択は端か、面の頂点数が4個以外のところでとまる。) #設定項目 #方向(houkou) 縦か横か #向き(muki) 左周りか右周りか #モード(mode) 選択に追加するか、選択から除外するか #間隔(step) この間隔で選択に追加 def sort_face_by_active_order(facelist): #頂点の選択番号(active_order)順にリストの面番号をソートしてリストを返す #ソート templist=[] for i in facelist: templist.append(i) newlist=[] while(len(newlist)0: activefacelist.append(i) if len(activefacelist)>0: #選択番号順に並び替える activefacelist=sort_face_by_active_order(activefacelist) startface=activefacelist[len(activefacelist)-1] startfacevlist=xshade.scene().active_shape().face(startface).vertex_indices if len(startfacevlist)==4:dousasuru=1 if dousasuru==1: #ここに初期値 houkou=0 muki=0 mode=0 step=1 renzoku=1 while(renzoku==1): #ダイアログ開く dialog=xshade.create_dialog() idx0=dialog.append_radio_button('/選択に追加する/選択から除外する') idx1=dialog.append_radio_button('方向(縦・横)/A/B') idx2=dialog.append_radio_button('向き/1/2') idx3=dialog.append_selection('間隔/0/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30') dialog.set_value(idx0,mode) dialog.set_value(idx1,houkou) dialog.set_value(idx2,muki) dialog.set_value(idx3,step) kekka=dialog.ask('ステップ選択') if kekka==False:renzoku=0 if kekka==True: mode=dialog.get_value(idx0) houkou=dialog.get_value(idx1) muki=dialog.get_value(idx2) step=dialog.get_value(idx3) if step<0:step=0 #開始辺を決める if houkou==0: hen1=return_edge_number(startfacevlist[0],startfacevlist[1]) hen2=return_edge_number(startfacevlist[2],startfacevlist[3]) else: hen1=return_edge_number(startfacevlist[1],startfacevlist[2]) hen2=return_edge_number(startfacevlist[0],startfacevlist[3]) if muki==1: temphen=hen1 hen1=hen2 hen2=temphen #追加リストを作っていく tuikalist=[] imaedge=hen1 startedge=hen1 imamen=startface tuikalist.append(startface) loop=1 syuuryou=0 imanum=0 while(loop==1): rinsetumen=copy.copy(eflist[imaedge]) rinsetumen.remove(imamen) if len(rinsetumen)<1: loop=0 else: if rinsetumen[0]==startface: loop=0 syuuryou=1 else: imanum+=1 if imanum>step:imanum=0 if imanum==0: tuikalist.append(rinsetumen[0]) imamen=rinsetumen[0] tempvlist2=list(xshade.scene().active_shape().face(imamen).vertex_indices) if len(tempvlist2)!=4: loop=0 else: tempvlist2.remove(xshade.scene().active_shape().edge(imaedge).v0) tempvlist2.remove(xshade.scene().active_shape().edge(imaedge).v1) imaedge=return_edge_number(tempvlist2[0],tempvlist2[1]) imaedge=hen2 imamen=startface loop=1 imanum=0 if syuuryou==0: while(loop==1): rinsetumen=copy.copy(eflist[imaedge]) rinsetumen.remove(imamen) if len(rinsetumen)<1: loop=0 else: imanum+=1 if imanum>step:imanum=0 if imanum==0: tuikalist.append(rinsetumen[0]) imamen=rinsetumen[0] tempvlist2=list(xshade.scene().active_shape().face(imamen).vertex_indices) if len(tempvlist2)!=4: loop=0 else: tempvlist2.remove(xshade.scene().active_shape().edge(imaedge).v0) tempvlist2.remove(xshade.scene().active_shape().edge(imaedge).v1) imaedge=return_edge_number(tempvlist2[0],tempvlist2[1]) #面の追加(あるいは除外)を行う for i in tuikalist: if mode==0:xshade.scene().active_shape().face(i).active=True else:xshade.scene().active_shape().face(i).active=False xshade.scene().exit_modify_mode() xshade.scene().enter_modify_mode() #ダイアログで確認して確定するかどうか決定 dialog2=xshade.create_dialog() iidx1=dialog2.append_push_button('選択を確定しますか?') kekka2=dialog2.ask('ステップ選択') if kekka2==True: renzoku=0 else: #選択状態を元に戻す for i in range(xshade.scene().active_shape().number_of_faces): xshade.scene().active_shape().face(i).active=False for i in activefacelist: xshade.scene().active_shape().face(i).active=True xshade.scene().active_shape().face(i).active_order=(i+1) xshade.scene().exit_modify_mode() xshade.scene().enter_modify_mode() #面ステップ選択終了 def step_sel_edge(): dousasuru=0 if xshade.scene().is_modify_mode==True and xshade.scene().active_shape().type==7: activeedgelist=[] for i in range(xshade.scene().active_shape().number_of_edges): if xshade.scene().active_shape().edge(i).active_order>0: activeedgelist.append(i) if len(activeedgelist)>0: #選択番号順に並び替える activeedgelist=sort_edge_by_active_order(activeedgelist) startedge=activeedgelist[len(activeedgelist)-1] temprin2=return_menlist(startedge) if len(temprin2)>0:dousasuru=1 if dousasuru==1: #ここに初期値 houkou=0 muki=0 mode=0 step=1 renzoku=1 while(renzoku==1): #ダイアログ開く dialog=xshade.create_dialog() idx0=dialog.append_radio_button('/選択に追加する/選択から除外する') idx2=dialog.append_radio_button('向き/1/2') idx3=dialog.append_selection('間隔/0/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30') dialog.set_value(idx0,mode) dialog.set_value(idx2,muki) dialog.set_value(idx3,step) kekka=dialog.ask('ステップ選択') if kekka==False:renzoku=0 if kekka==True: mode=dialog.get_value(idx0) muki=dialog.get_value(idx2) step=dialog.get_value(idx3) if step<0:step=0 #開始面を決める tempmen4=eflist[startedge] if len(tempmen4)>1: men1=tempmen4[0] men2=tempmen4[1] else: men1=tempmen4[0] men2=tempmen4[0] if muki==1: tempmen=men1 men1=men2 men2=tempmen #追加リストを作っていく tuikalist=[] imaedge=startedge imamen=men1 tuikalist.append(startedge) loop=1 syuuryou=0 imanum=0 while(loop==1): tempvlist=list(xshade.scene().active_shape().face(imamen).vertex_indices) if len(tempvlist)!=4: loop=0 else: tempvlist.remove(xshade.scene().active_shape().edge(imaedge).v0) tempvlist.remove(xshade.scene().active_shape().edge(imaedge).v1) newedge=return_edge_number(tempvlist[0],tempvlist[1]) if newedge==startedge: loop=0 syuuryou=1 else: imanum+=1 if imanum>step:imanum=0 if imanum==0: tuikalist.append(newedge) temprin6=copy.copy(eflist[newedge]) if len(temprin6)<2: loop=0 else: temprin6.remove(imamen) imamen=temprin6[0] imaedge=newedge imaedge=startedge imamen=men2 loop=1 imanum=0 if syuuryou==0: while(loop==1): tempvlist=list(xshade.scene().active_shape().face(imamen).vertex_indices) if len(tempvlist)!=4: loop=0 else: tempvlist.remove(xshade.scene().active_shape().edge(imaedge).v0) tempvlist.remove(xshade.scene().active_shape().edge(imaedge).v1) newedge=return_edge_number(tempvlist[0],tempvlist[1]) imanum+=1 if imanum>step:imanum=0 if imanum==0: tuikalist.append(newedge) temprin6=copy.copy(eflist[newedge]) if len(temprin6)<2: loop=0 else: temprin6.remove(imamen) imamen=temprin6[0] imaedge=newedge #辺の追加(あるいは除外)を行う for i in tuikalist: if mode==0:xshade.scene().active_shape().edge(i).active=True else:xshade.scene().active_shape().edge(i).active=False xshade.scene().exit_modify_mode() xshade.scene().enter_modify_mode() #ダイアログで確認して確定するかどうか決定 dialog2=xshade.create_dialog() iidx1=dialog2.append_push_button('選択を確定しますか?') kekka2=dialog2.ask('ステップ選択') if kekka2==True: renzoku=0 else: #選択状態を元に戻す for i in range(xshade.scene().active_shape().number_of_edges): xshade.scene().active_shape().edge(i).active=False for i in activeedgelist: xshade.scene().active_shape().edge(i).active=True xshade.scene().active_shape().edge(i).active_order=(i+1) xshade.scene().exit_modify_mode() xshade.scene().enter_modify_mode() #辺ステップ選択終了 if xshade.scene().active_shape().type==7: velist=[]#頂点に接続されている辺リストを頂点番号順に格納したもの for i in range(xshade.scene().active_shape().total_number_of_control_points): velist.append([]) for i in range(xshade.scene().active_shape().number_of_edges): vv0=xshade.scene().active_shape().edge(i).v0 vv1=xshade.scene().active_shape().edge(i).v1 tempvv=velist[vv0] tempvv.append(i) velist[vv0]=tempvv tempvv=velist[vv1] tempvv.append(i) velist[vv1]=tempvv eflist=[]#辺に隣接されている面リストを辺番号順に格納したもの #return_henlist必要 for i in range(xshade.scene().active_shape().number_of_edges): eflist.append([]) xshade.scene().active_shape().setup_winged_edge() for i in range(xshade.scene().active_shape().number_of_faces): thenlist=return_henlist(i) for gg in thenlist: tempf=eflist[gg] tempf.append(i) eflist[gg]=tempf xshade.scene().active_shape().clean_winged_edge() if xshade.scene().selection_mode==0:step_sel_face() if xshade.scene().selection_mode==1:step_sel_edge()