2016-08-23 5 views
0

を動作していませんTEST_1_GRP、TEST_2_GRP、TEST_3_GRPなどの名前を持つグループを表示するのではなく、TEST_1_GRP、TEST_1_GRP1、TEST_1_GRP2を自分の結果として取得しています...カウンター私のタイトルはとにかく間違った印象はなく...</p> <p>を与える場合、私は2を持っているとき、私は、謝罪..私はそれに応じてインクリメントするようなカウンターの使用、でグループ化するいくつかを実行しようとしてい

(文の中/前のように)周りのカウンタ部分の行は、私はどこにもいません。

以下は私のコードです:

def fix_shapes(): 
    all_geos = cmds.ls(sl = True) 
    for geo in all_geos: 
     shapes = cmds.listRelatives(geo, fullPath=True, shapes=True) 

     if len(shapes) == 1: 
      continue 

     new_listing = [] 
     listing.append(shapes[:1]) 
     # pop out the first shape, since we don't have to fix it 
     multi_shapes = shapes[1:] 
     for multi_shape in multi_shapes: 
      new_transform = cmds.duplicate(multi_shape, parentOnly=True) 
      new_geos = cmds.parent(multi_shape, new_transform, addObject=True, shape=True) 
      listing.append(new_geos) 


      # remove the shape from its original transform 
      cmds.parent(multi_shape, removeObject=True, shape=True) 

     # counter to 'version' up new_geos group naming 
     counter = 0 
     new_group_name = cmds.group(em=True, name = 'TEST_' + str(counter + 1) + '_GRP') 

     for item in new_listing: 
      counter = counter + 1 
      new_geos_parent_name = cmds.listRelatives(item, parent = True) 
      cmds.parent(new_geos_parent_name, new_group_name) 
+0

直後に 'counter = 0'と' str(counter + 1) 'があります。あなたが期待していることは分かりませんが、変数を0に設定して値をチェックすると、常に0になります。 'str(counter + 1)'は ' 1 "がそこにある。 – melpomene

答えて

0

次のようにカウンターを移動します。最後のループでカウンターを使用していないので、カウンターを取り外します。これはあなたが欲しいものをチェックしますか?

def fix_shapes(): 
    all_geos = cmds.ls(sl = True) 
    counter = 0 
    for geo in all_geos: 
     shapes = cmds.listRelatives(geo, fullPath=True, shapes=True) 

     if len(shapes) == 1: 
      continue 

     new_listing = [] 
     listing.append(shapes[:1]) 
    # pop out the first shape, since we don't have to fix it 
     multi_shapes = shapes[1:] 
     for multi_shape in multi_shapes: 
      new_transform = cmds.duplicate(multi_shape, parentOnly=True) 
      new_geos = cmds.parent(multi_shape, new_transform, addObject=True, shape=True) 
      listing.append(new_geos) 


     # remove the shape from its original transform 
      cmds.parent(multi_shape, removeObject=True, shape=True) 

    # counter to 'version' up new_geos group naming 

     new_group_name = cmds.group(em=True, name = 'TEST_' + str(counter + 1) + '_GRP') 

     for item in new_listing: 
      new_geos_parent_name = cmds.listRelatives(item, parent = True) 
      cmds.parent(new_geos_parent_name, new_group_name) 
+0

こんにちは、それはまだ動作していません...私は1つ以上の項目を選択したときにまだ 'TEST_1_GRP1'を与えています..これが助けになるかどうかわかりませんが、これは私のmayaテストです[http] // www.mediafire.com/download/glhfon16dwi1pbh/test.ma)、 'ref_1_geo5'と' ref_1_geo6'を選択して、自分のコードを実行してみてください。 – dissidia

0

私はこれがあなたの問題を解決するかもしれないと信じています。最初にコードを実行すると、期待どおりに動作し、TEST_1_GRP TEST_2_GRPなどのグループが生成されます。ただし、名前が保存されていないか、チェックされていないため、TEST_1_GRP1 TEST_2_GRP1などという名前になります。この問題を回避するには、グローバル変数を格納するか、実行中に名前をチェックするか、またはシーンファイルまたは他の場所にカウントされた値を格納します。私はこれをあなたに任せます。

def fix_shapes(): 
    all_geos = cmds.ls(sl = True) 
    counter = 0 ### moved counter outside loop 
    for geo in all_geos: 
     shapes = cmds.listRelatives(geo, fullPath=True, shapes=True) 

     if len(shapes) == 1: 
      continue 

     listing = [] ### fixed naming, was new_listing, not coherent 
     listing.append(shapes[:1]) 
     # pop out the first shape, since we don't have to fix it 
     multi_shapes = shapes[1:] 
     for multi_shape in multi_shapes: 
      new_transform = cmds.duplicate(multi_shape, parentOnly=True) 
      new_geos = cmds.parent(multi_shape, new_transform, addObject=True, shape=True) 
      listing.append(new_geos) 


      # remove the shape from its original transform 
      cmds.parent(multi_shape, removeObject=True, shape=True) 

     # counter to 'version' up new_geos group naming 
     new_group_name = cmds.group(em=True, name = 'TEST_' + str(counter + 1) + '_GRP') 

     counter += 1 ### simpler way to increment instead of "counter = counter + 1" 

     for item in listing: ### fixed new_listing name here as well 
      new_geos_parent_name = cmds.listRelatives(item, parent = True) 
      cmds.parent(new_geos_parent_name, new_group_name) 

私はいくつかのコメントとともに###で変更をマークしました。あなたが最大の範囲カウンタのようなものを必要とする2回目の反復のための

0
def fix_shapes(): 
    all_geos = cmds.ls(sl = True) 
    counter = 0 
    for geo in all_geos: 
     shapes = cmds.listRelatives(geo, fullPath=True, shapes=True) 

     if len(shapes) == 1: 
      continue 

     new_listing = [] 
     new_listing.append(shapes[:1]) 
    # pop out the first shape, since we don't have to fix it 
     multi_shapes = shapes[1:] 
     for multi_shape in multi_shapes: 
      new_transform = cmds.duplicate(multi_shape, parentOnly=True) 
      new_geos = cmds.parent(multi_shape, new_transform, addObject=True, shape=True) 
      new_listing.append(new_geos) 


     # remove the shape from its original transform 
      cmds.parent(multi_shape, removeObject=True, shape=True) 

    # counter to 'version' up new_geos group naming 
     new_grp_id = "TEST_{0}_GRP".format(counter) 
     if not cmds.objExists(new_grp_id): 
      new_group_name = cmds.group(em=True, name = new_grp_id) 
      counter += 1 
     else: 
      for o in reversed(xrange(100)): 
       if cmds.objExists("TEST_{0}_GRP".format(o)): 
        counter = o + 1 
        break 
      new_group_name = cmds.group(em=True, name = "TEST_{0}_GRP".format(counter)) 
      counter += 1 

     for item in new_listing: 
      new_geos_parent_name = cmds.listRelatives(item, parent = True) 
      cmds.parent(new_geos_parent_name, new_group_name) 

、 ので、我々はいくつかのチェックを構築する必要があり....ので、今ではのGRPを作成しませんし、それにアイテムを追加します、次の反復でそれがわかります"TEST_n_GRP"の最大値とそれを増やすと、整数間ではなく、最大のintを見つけることができると思います。例えば、シーン:grp_1とgrp_3、次に大きい数字はgrp_4ですが、grp_2は見つかりません!あなたはその逆の演算子を削除することができます。 逆演算子を使用すると、intの間ではなく、最大/最後の整数が実際に速くなります。

関連する問題

 関連する問題