import random #パスジョイント複製 #パスジョイントを使ってオブジェクトをパスに沿って向きを変えながら複製するスクリプトです #「初期位置」パラメーターを追加 (2010.0606) #バグ修正(2010.0610) #「複製ごとに回転」オプションを追加(2010.06.25) #掃引パスの始点のコントロールポイントが回転の中心 #動作条件 #選択形状がパスジョイント #パスジョイントの上(兄階層)にパスとなる線形状が存在する #パスジョイント内にオブジェクトが存在する #(複数のオブジェクトをまとめてコピーする場合はパートに入れてください) #パラメータ #複製回数 #ステップ #リンクを使う(チェックボックス) #初期位置・・・・デフォルトでは0の位置からスタート #「複製ごとに回転」ON・OFF #「回転角度」 #「回転の軸」X軸、Y軸、Z軸 # 「ランダムな回転を加える」 # 「最小値」 # 「最大値」 def count_num(): ashape3=xshade.scene().active_shape() imauuid=xshade.scene().active_shape().uuid count=1 while(1): xshade.scene().select_sister() if xshade.scene().active_shape().uuid==imauuid: break else: count+=1 imauuid=xshade.scene().active_shape().uuid ashape3.activate() return count xscene=xshade.scene() ashape=xshade.scene().active_shape() dousasuru=0 error=0 #動作条件確認 #if ashape.type==2 and ashape.part_type==7 and ashape.has_sis==True: # if ashape.sis.type==4: # if ashape.has_son==True: # if ashape.has_dad==True: # if ashape.dad.type==2: # if ashape.dad.number_of_sons==2: # dousasuru=1 # else:error=1 if ashape.type==2 and ashape.part_type==7 and ashape.has_sis==True: if ashape.sis.type==4: if ashape.has_son==True: dousasuru=1 if dousasuru==1: #ここにデフォルト値 renzoku=1 kaisuu=10 #複製回数 pstep=0.1 #ステップ linkok=0 #リンクを使うかどうか 0でOFF startp=0 #初期位置 kaiten=0#複製ごとに回転するかどうか angle1=90#複製ごとに回転する場合の回転の角度 axis1=0#複製ごとに回転する場合の回転の軸 0がX軸 1がY軸 2がZ軸 random1=0#回転角度に乱数を加えるか rmin=-30 rmax=30 while(renzoku==1): #ダイアログ開く dialog44=xshade.create_dialog() idx441=dialog44.append_int('複製回数') idx442=dialog44.append_float('ステップ(0より大)') idx443=dialog44.append_bool('リンクを使う') idx444=dialog44.append_float('初期位置') dialog44.begin_group() idx445=dialog44.append_bool('複製ごとに回転する') idx446=dialog44.append_float('回転角度') idx447=dialog44.append_radio_button('回転軸/X軸と平行/Y軸と平行/Z軸と平行') dialog44.begin_group('ランダム') idx448=dialog44.append_bool('各回転に乱数を加える') idx449=dialog44.append_int('乱数最小値(-360以上)') idx450=dialog44.append_int('乱数最大値(360以下)') dialog44.end_group() dialog44.end_group() dialog44.set_value(idx441,kaisuu) dialog44.set_value(idx442,pstep) dialog44.set_value(idx443,linkok) dialog44.set_value(idx444,startp) dialog44.set_value(idx445,kaiten) dialog44.set_value(idx446,angle1) dialog44.set_value(idx447,axis1) dialog44.set_value(idx448,random1) dialog44.set_value(idx449,rmin) dialog44.set_value(idx450,rmax) kekka4=dialog44.ask('パスジョイント複製') if kekka4==False:renzoku=0 if kekka4==True: kaisuu=dialog44.get_value(idx441) if kaisuu<=0:kaisuu=1 pstep=dialog44.get_value(idx442) if pstep<0:pstep=0 linkok=dialog44.get_value(idx443) startp=dialog44.get_value(idx444) if startp<0:startp=0 kaiten=dialog44.get_value(idx445) angle1=dialog44.get_value(idx446) axis1=dialog44.get_value(idx447) random1=dialog44.get_value(idx448) rmin=dialog44.get_value(idx449) rmax=dialog44.get_value(idx450) if rmin>rmax: tempa=rmin rmin=rmax rmax=tempa if rmin<-360:rmin=-360 if rmin>360:rmin=360 if rmax<-360:rmax=-360 if rmax>360:rmax=360 #まずはパスジョイントの値を0にする ashape.path_joint.path_position=0 #パスジョイントの序数確認 # ordi=xscene.active_shape().ordinal # ordi=2 ordi=count_num() #パスジョイントの位置を初期位置に ashape.path_joint.path_position=startp #掃引パスの最初のコントロールポイントの座標を取得 cpos=ashape.sis.control_point(0).position #パスジョイントの下に複製物を格納するフォルダ作成 xshade.scene().create_part('複製結果') xscene.select_sister() #最初の1個目をジョイント値0の位置に複製 if linkok==0: xscene.select_child() xscene.copy() xscene.paste() if linkok==1: xscene.select_child() xscene.link_object((0.0, 0.0, 0.0),None,None,None) #複製物を先ほど作成したパートに移動 # xscene.cut() # xscene.select_parent() # xscene.select_brother() # xscene.paste() # xscene.select_parent() # xscene.select_sister() xscene.active_shape().place_parent(1) xscene.active_shape().place_brother(ordi) xscene.active_shape().place_child(1) xscene.select_parent() xscene.select_sister() #回数分繰り返す # ordi=xscene.active_shape().ordinal # ordi=2 ordi=count_num() for i in range(kaisuu): ashape.path_joint.path_position=0 if linkok==0: xscene.select_child() xscene.copy() xscene.paste() if linkok==1: xscene.select_child() xscene.link_object((0.0, 0.0, 0.0),None,None,None) #回転ONの場合は掃引パスの始点を軸に回転 if kaiten==1: kakudo=angle1*(i+1) while(kakudo<0): kakudo+=360 while(kakudo>360): kakudo-=360 #回転角度に乱数を加える if random1==1: kakudo+=random.randint(rmin,rmax) # print kakudo # print cpos # dialogps=xshade.create_dialog() # dialogps.append_push_button('ppp') # dialogps.ask() if axis1==0: xscene.move_object([cpos[0],cpos[1],cpos[2]],[1,1,1],[kakudo,0,0],None) if axis1==1: xscene.move_object([cpos[0],cpos[1],cpos[2]],[1,1,1],[0,kakudo,0],None) if axis1==2: xscene.move_object([cpos[0],cpos[1],cpos[2]],[1,1,1],[0,0,kakudo],None) temppath=pstep*(i+1)+startp ashape.path_joint.path_position=temppath #複製物を先ほど作成したパートに移動 xscene.active_shape().place_parent(1) xscene.active_shape().place_brother(ordi) xscene.active_shape().place_child(1) xscene.active_shape().place_brother(i+1) xscene.select_parent() xscene.select_sister() #パスジョイントの値を0に戻す ashape.path_joint.path_position=0 #複製結果のパートをたたむ xscene.select_brother() xshade.scene().active_shape().undisclose_all() xscene.select_sister() #結果を確定するかどうか確認 dialog=xshade.create_dialog() dialog.append_push_button('結果を確定しますか?') kekka=dialog.ask('パスジョイント複製') if kekka==True:renzoku=0 if kekka==False: xscene.select_brother() xscene.clear() if error>0: #エラーメッセージ表示 dialogerr=xshade.create_dialog() if error==1: dialogerr.append_push_button('パートの中には') dialogerr.append_push_button('線形状と') dialogerr.append_push_button('パスジョイント') dialogerr.append_push_button('(とパスジョイントの中身)') dialogerr.append_push_button('の二つ以外は形状を') dialogerr.append_push_button('入れないでください') dialogerr.ask('エラー')