forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomiseFilePathByFolder
62 lines (37 loc) · 1.3 KB
/
randomiseFilePathByFolder
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# randomise selected jpg paths by contents of a folder:
import maya.cmds as cmds
import os
import random
# Save in this folder dialogue
dir = cmds.fileDialog2(fm=3, dialogStyle=2, cap='Select .jpg source location', okCaption='Select')
dir = dir[0]+"/"
items = os.listdir(dir)
numberOfStandins = 1
assList = []
for names in items:
if names.endswith(".jpg"):
assList.append(names)
print assList
# a randomiser that shuffles things (to reduce likelyhood of repetition)
import random
import math
def sean_shuffle(list_to_pick_from, number_of_picks_needed):
multiplier= int(math.ceil(number_of_picks_needed/ float(len(list_to_pick_from))))
shuffled_list= []
for i in range(multiplier):
random.shuffle(list_to_pick_from)
shuffled_list.extend(list_to_pick_from)
return shuffled_list[:number_of_picks_needed]
# construct random selection path and assign standin path
import pymel.core as pm
path = []
selection = cmds.ls( selection=True )
randomObject = sean_shuffle(assList, len(selection))
for i, j in enumerate(selection):
print i, j
path = dir+ randomObject[i]
print path
valueOld = pm.getAttr( '{}.fileTextureName'.format(j) )
valueNew = path
pm.setAttr( '{}.fileTextureName'.format(j), valueNew)
#end