我創建了這個 python 腳本來替換 psd 檔案中的影像,但我覺得我在重復相同的代碼并希望簡化它,因為我有更多的“組”實體,我只是在此處粘貼了 2 以使其更短。這是ps檔案截圖。

唯一的區別是:

這可以很容易地存盤在兩個變數中,我們稱它們為texture_name和ending_name。兩者都將是一個字串。
因此,這是我將如何重構您的代碼:
for grp in allLayerSets:
#[ ... ]
texture_name = ""
ending_name = ""
if grp.name.startswith('Group 1'):
texture_name = "Wall_v2_height.exr"
ending_name = "_x_n_y"
elif grp.name.startswith('Group 2'):
texture_name = "Wall_v3_height.exr"
ending_name = "_both"
else:
print("Deal with this problem")
# Now the code will be just one.
# [ ... ]
newTexture = "C:/CG_CONTENT/TEXTURES/" texture_name
# [ ... ]
elif baseLayer.name.endswith(ending_name):
看看我們是如何在您的大量代碼中使用變數的?但是我們只寫一次!
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/478853.html
下一篇:如何按降序排列陣列
