import copy #頂点の等間隔配置 #使えるのはshade13以上 #shade13,14,15で動作確認 #このスクリプトの機能 #選択している頂点を、最初に選択した頂点と最後に選択した頂点の間に等間隔に再配置します。 #上位パートに変換がかかっていると使用できません #動作条件 #選択形状がポリゴンメッシュで、選択している形状は一つのみ #編集モードに入っていて、頂点編集モードで、三点以上を選択している事 #パラメーター #XYZ座標変更/X座標のみ変更/Y座標のみ変更/Z座標のみ変更/XY座標のみ変更/YZ座標のみ変更/XZ座標のみ変更 #グループで整列(ブール型) #グループ数(intで2以上) グループで整列がONの場合   # def arrange_vertex(aplist,groupsuu2,tempvec,groupon): #頂点の位置を変更 ashape=xshade.scene().active_shape() #最初の頂点と最後の頂点 for i in aplist: if ashape.vertex(i).active_order==1:apfirst=i if ashape.vertex(i).active_order==len(aplist):apend=i apfirstpos=[ashape.vertex(apfirst).position[0],ashape.vertex(apfirst).position[1],ashape.vertex(apfirst).position[2]] apendpos=[ashape.vertex(apend).position[0],ashape.vertex(apend).position[1],ashape.vertex(apend).position[2]] tempvec2=[apendpos[0]-apfirstpos[0],apendpos[1]-apfirstpos[1],apendpos[2]-apfirstpos[2]] tempvec2=[tempvec2[0]*tempvec[0],tempvec2[1]*tempvec[1],tempvec2[2]*tempvec[2]] for i in aplist: acnum=ashape.vertex(i).active_order if groupon==True: dev=int(len(aplist)/groupsuu2) if acnum%dev==0: acnum=acnum/dev else: acnum=int(acnum/dev)+1 ddousa=1 if groupon==False: if acnum==1 or acnum==len(aplist): ddousa=0 if ddousa==1: if(tempvec[0]==0): posx=ashape.vertex(i).position[0] else: posx=apfirstpos[0]+(tempvec2[0]/(groupsuu2-1))*(acnum-1) if(tempvec[1]==0): posy=ashape.vertex(i).position[1] else: posy=apfirstpos[1]+(tempvec2[1]/(groupsuu2-1))*(acnum-1) if(tempvec[2]==0): posz=ashape.vertex(i).position[2] else: posz=apfirstpos[2]+(tempvec2[2]/(groupsuu2-1))*(acnum-1) ashape.vertex(i).position=[posx,posy,posz] return def arrange_edges(aelist,groupsuu2,tempvec): #辺の位置を変更 ashape=xshade.scene().active_shape() return dousasuru=0 ashape=xshade.scene().active_shape() xscene=xshade.scene() selmode=xshade.scene().selection_mode if xshade.scene().active_shape().type==7: if len(xshade.scene().active_shapes)==1: if xshade.scene().is_modify_mode==True: if selmode==2: aplist=xshade.scene().active_shape().active_vertex_indices if len(aplist)>=3: dousasuru=1 if selmode==1: aelist=[] for i in range(ashape.number_of_edges): if ashape.edge(i).active==True: aelist.append(i) if len(aelist)>=3: dousasuru=1 if dousasuru>0: #上位パートに変換がかかっているなら動作しない if xshade.scene().active_shape().local_to_world_matrix!=((1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0)): dousasuru=0 dialog=xshade.create_dialog() dialog.append_push_button('上位パートに変換がかかっているため') dialog.append_push_button('スクリプトが実行できません') dialog.ask('エラー') if dousasuru==1: xscene=xshade.scene() #ここに初期値 renzoku=1 idou1=0#6がXYZ座標移動 0がX座標のみ移動 1がY座標のみ移動 2がZ座標のみ 3がXY座標のみ 4がYZ座標のみ 5がXZ座標のみ移動 groupon=False groupsuu=3 while(renzoku==1): #ダイアログ表示 # dialog=xshade.create_dialog_with_uuid('0x51903F33') dialog=xshade.create_dialog() # dialog.append_default_button() # dialog.begin_group() idx1=dialog.append_selection('移動/X座標のみ移動/Y座標のみ移動/Z座標のみ移動/XY座標のみ移動/YZ座標のみ移動/XZ座標のみ移動/XYZすべて移動') idx2=dialog.append_bool('グループで移動') idx3=dialog.append_int('グループ数(3以上)') # dialog.end_group() # dialog.set_default_value(idx1,idou1) # dialog.set_default_value(idx2,tempatumi) # dialog.set_default_value(idx3,tempmuki) dialog.set_value(idx1,idou1) dialog.set_value(idx2,groupon) dialog.set_value(idx3,groupsuu) xshade.idle(120) xshade.scene().update_figure_window() kekka=dialog.ask('選択頂点の等間隔配置') if kekka==False: renzoku=0 if kekka==True: xshade.scene().inhibit_update() idou1=dialog.get_value(idx1) tempvec=[1,1,1] if idou1==0:tempvec=[1,0,0] if idou1==1:tempvec=[0,1,0] if idou1==2:tempvec=[0,0,1] if idou1==3:tempvec=[1,1,0] if idou1==4:tempvec=[0,1,1] if idou1==5:tempvec=[1,0,1] # print idou1 groupon=dialog.get_value(idx2) groupsuu=dialog.get_value(idx3) if groupsuu<=2: groupsuu=3 if selmode==2:groupsuu2=len(aplist) if selmode==1:groupsuu2=len(aelist) if(groupon==True):groupsuu2=groupsuu #元の形状をクリップボードにコピーしておく # if xshade.scene().is_modify_mode==True:ima=1 # else:ima=0 # xshade.scene().active_shape().copy() # if ima==1:xshade.scene().enter_modify_mode() #元の座標値をリストに格納しておく(今回はこっちを採用) motoposlist=[] if selmode==2: for i in aplist: motoposlist.append(ashape.vertex(i).position) if selmode==2: arrange_vertex(aplist,groupsuu2,tempvec,groupon) if selmode==1: arrange_edges(aelist,groupsuu2,tempvec,groupon) #元に戻すか聞く xshade.scene().allow_update() xshade.idle(120) xshade.scene().update_figure_window() dialog=xshade.create_dialog() idx3=dialog.append_push_button('処理を確定する場合はokを') idx4=dialog.append_push_button('取り消す場合はcancelを押してください') xshade.idle(120) xshade.scene().update_figure_window() kekka2=dialog.ask('選択頂点の等間隔配置') #キャンセルなら形状を削除してクリップボードの形状を元に戻す #さらに頂点の選択状態も元に戻す? if kekka2==False: # idou3=0 # if xshade.scene().active_shape().has_sis==True: # idou3=1 # xshade.scene().paste() # xshade.scene().select_sister(1) # xshade.scene().clear() # if idou3==1: # xshade.scene().select_brother() # if ima==1: # xshade.scene().enter_modify_mode() #元の座標に戻す if selmode==2: sts=0 for i in aplist: ashape.vertex(i).position=motoposlist[sts] sts+=1 xshade.idle(120) # for i in activepointlist: # xshade.scene().active_shape().vertex(i).active=True #選択番号が変更されているので、入れなおし # for i in range(len(activepointlist2)): # xshade.scene().active_shape().vertex(activepointlist2[i]).active_order=i+1 if kekka2==True: renzoku=0 #戻す終わり