forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathassetRandomiser
More file actions
87 lines (60 loc) · 2.39 KB
/
Copy pathassetRandomiser
File metadata and controls
87 lines (60 loc) · 2.39 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# randomise selected standin 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 .ass source location', okCaption='Select')
dir = dir[0]+"/"
items = os.listdir(dir)
numberOfStandins = 1
assList = []
for names in items:
if names.endswith(".ass"):
assList.append(names)
print assList
# a randomiser that shuffles things (to reduce likelyhood of repetition)
import random
import math
randY = False
randomRotation = cmds.confirmDialog( title='randY', message='Randomise Y rotation?', button=['Yes','No'], defaultButton='Yes', cancelButton='No', dismissString='No' )
if randomRotation == "Yes":
randY = True
print "Randomising Y axis"
def sean_shuffle(list_to_pick_from, number_of_picks_needed):
#Sean Danischevsky 2017
#shuffles a list, then reshuffles as many times as needed to fulfil the number of picks needed.
#returns a shuffled list.
#e.g. sean_shuffle(range(3), 30)
#will return 5 blocks of [0,1,2], shuffled each time
#[2, 0, 1, 2, 1, 0, 1, 2, 0, 1, 0, 2, 2, 1, 0, 2, 1, 0, 2, 0, 1, 2, 0, 1, 0, 1, 2, 0, 2, 1]
#ensures that you get maximum use from all your elements.
#i.e. they are all used, equally (or very nearly)
#and minimises probability of 2 elements repeating next to each other.
#you could further shuffle the result if needed, i.e.
# newlist= sean_shuffle(range(3), 30)
# print newlist
# random.shuffle(newlist)
# print newlist
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( '{}.dso'.format(j) )
valueNew = path
pm.setAttr( '{}.dso'.format(j), valueNew)
#randomises y axis if True
if randY == True:
rotateBy = random.random()*360
cmds.setAttr(j+'.rotate', 0, rotateBy, 0, type="double3")
#end