Skip to content

Commit 5d11573

Browse files
committed
Added some checks in randomize(), removed debugging print statements.
1 parent 6662473 commit 5d11573

File tree

4 files changed

+113
-13
lines changed

4 files changed

+113
-13
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
11
# randomUV
22
A 3dsMax script that works with the UnwrapUVW modifier to randomize UV element transforms.
3+
4+
Install by copying the bakeAllAnim folder to your 3ds Max scripts directory.
5+
Run in 3ds Max using with the MaxScript snippet:
6+
`python.ExecuteFile @"C:\path\to\randomUV\randomUV.py"`
7+
8+
-----
9+
10+
This script makes use of the `Unwrap UVW` modifier to randomize UV island transforms, rotations, and scales.
11+
12+
To use, run the script and select some UV islands in an `Unwrap UVW` modifier. You can select sub-elements
13+
(they will be expanded to full islands by the script), including individual vertices or edges.
14+
15+
With some UV elements selected, press the `1 - Hold UV Selection` button.
16+
Depending on the number of elements selected, this may take some time.
17+
18+
Next, check which transforms you'd like to randomize and set the min/max amounts.
19+
Units for these are UV space for Translation, degrees for Rotation, and Percent for Scale.
20+
Optionally, you can also set Increment values for each transform.
21+
22+
With Channels selected and Min/Max/Increment values set, you can press `2 - Randomize UVs` to... randomize your UVs.
23+
This ***is*** undo-able.
24+
25+
-----
26+
27+
Important notes:
28+
- The `Unwrap UVW` modifier ***must*** be selected when you are Holding Selection
29+
and Randomizing UVs.
30+
- You need to have the same object selected when you Hold Selection and when you Randomize.
31+
- You ***should*** have the same `Unwrap UVW` modifier selected when you Hold Selection
32+
and when you Randomize UVs. The script won't enforce this, but it will likely behave weirdly or
33+
fail outright if you don't.

randomUV.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# --------------------------------
2-
# Bake All Anim v1.0.0 Release
2+
# UV Randomizer v1.0.0 Release
33
# --------------------------------
44

55
# Destroys instances of the dialog before recreating it
@@ -82,7 +82,7 @@ def __init__(self, ui_file, pymxs, parent=MaxPlus.GetQMaxMainWindow()):
8282

8383
# Titling
8484

85-
self._window_title = 'UV Randomizer DEV BUILD'
85+
self._window_title = 'UV Randomizer v1.0.0'
8686
self.setWindowTitle(self._window_title)
8787

8888
# ---------------------------------------------------
@@ -143,7 +143,8 @@ def __init__(self, ui_file, pymxs, parent=MaxPlus.GetQMaxMainWindow()):
143143
'%s The current modifier MUST be an Unwrap UVW with some elements selected!' % self._wrn,
144144
'%s Holding UV Selection...' % self._grn,
145145
'%s Randomizing UVs...' % self._grn,
146-
'%s See Max Listener for details' % self._err]
146+
'%s See Max Listener for details' % self._err,
147+
'%s The object has changed since Holding UV Selection!' % self._wrn]
147148
# Set initial status label
148149
self._lbl_status.setText(self._status[0])
149150

@@ -155,7 +156,6 @@ def __init__(self, ui_file, pymxs, parent=MaxPlus.GetQMaxMainWindow()):
155156
# ---------------------------------------------------
156157

157158
def _get_settings(self):
158-
print '_get_settings()'
159159

160160
self._settings['translate'] = self._chk_t.isChecked()
161161
self._settings['rotate'] = self._chk_r.isChecked()
@@ -261,11 +261,15 @@ def randomize(self):
261261
rt = self._rt
262262

263263
try:
264-
# Check that the current modifier is an Unwrap_UVW
264+
# Validate the current modifier, element list, and object.
265265
# We use rt.classOf() to get the actual MaxScript class
266266
uv = rt.modPanel.getCurrentObject()
267267
if rt.classOf(uv) != rt.Unwrap_UVW:
268268
self._lbl_status.setText(self._status[2])
269+
elif len(self._elements) == 0:
270+
self._lbl_status.setText(self._status[2])
271+
elif rt.getCurrentSelection()[0] != self._object:
272+
self._lbl_status.setText(self._status[6])
269273
else:
270274
self._lbl_status.setText(self._status[4])
271275

@@ -294,7 +298,6 @@ def randomize(self):
294298
tv = tv - (tv % t_range[2])
295299
t_uvw = rt.Point3(tu, tv, 0)
296300
uv.moveSelected(t_uvw)
297-
print 'Translate %s' % t_uvw
298301

299302
if self._settings['rotate']:
300303
# Shorthand var
@@ -307,7 +310,6 @@ def randomize(self):
307310
# rotateSelectedCenter expects radians
308311
angle = radians(angle)
309312
uv.rotateSelectedCenter(angle)
310-
print 'Rotate %sdeg' % angle
311313

312314
if self._settings['scale']:
313315
# Shorthand var
@@ -320,7 +322,8 @@ def randomize(self):
320322
# scaleSelectedCenter 0-1 == 0-100 percent, so scale these values accordingly
321323
scale = scale / 100
322324
uv.scaleSelectedCenter(scale, 0)
323-
print 'Scale %s' % scale
325+
326+
self._lbl_status.setText(self._status[1])
324327

325328

326329
except Exception as e:
@@ -341,4 +344,4 @@ def randomize(self):
341344
ui.show()
342345

343346
# DEBUG
344-
print "\rTest Version 35"
347+
# print "\rTest Version 39"

randomUV.ui

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>336</width>
9+
<width>366</width>
1010
<height>220</height>
1111
</rect>
1212
</property>
@@ -199,6 +199,28 @@
199199
</property>
200200
</widget>
201201
</item>
202+
<item>
203+
<widget class="QLabel" name="label">
204+
<property name="sizePolicy">
205+
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
206+
<horstretch>0</horstretch>
207+
<verstretch>0</verstretch>
208+
</sizepolicy>
209+
</property>
210+
<property name="minimumSize">
211+
<size>
212+
<width>25</width>
213+
<height>0</height>
214+
</size>
215+
</property>
216+
<property name="text">
217+
<string>UV</string>
218+
</property>
219+
<property name="alignment">
220+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
221+
</property>
222+
</widget>
223+
</item>
202224
</layout>
203225
</item>
204226
<item>
@@ -266,6 +288,28 @@
266288
</property>
267289
</widget>
268290
</item>
291+
<item>
292+
<widget class="QLabel" name="label_2">
293+
<property name="sizePolicy">
294+
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
295+
<horstretch>0</horstretch>
296+
<verstretch>0</verstretch>
297+
</sizepolicy>
298+
</property>
299+
<property name="minimumSize">
300+
<size>
301+
<width>25</width>
302+
<height>0</height>
303+
</size>
304+
</property>
305+
<property name="text">
306+
<string>deg</string>
307+
</property>
308+
<property name="alignment">
309+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
310+
</property>
311+
</widget>
312+
</item>
269313
</layout>
270314
</item>
271315
<item>
@@ -333,6 +377,28 @@
333377
</property>
334378
</widget>
335379
</item>
380+
<item>
381+
<widget class="QLabel" name="label_3">
382+
<property name="sizePolicy">
383+
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
384+
<horstretch>0</horstretch>
385+
<verstretch>0</verstretch>
386+
</sizepolicy>
387+
</property>
388+
<property name="minimumSize">
389+
<size>
390+
<width>25</width>
391+
<height>0</height>
392+
</size>
393+
</property>
394+
<property name="text">
395+
<string>%</string>
396+
</property>
397+
<property name="alignment">
398+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
399+
</property>
400+
</widget>
401+
</item>
336402
</layout>
337403
</item>
338404
</layout>

runRandomUV.ms

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
macroScript randomUV_v01
1+
macroScript randomUV
22
category:"jScripts"
3-
toolTip:"Random UV v01"
3+
toolTip:"UV Randomizer v1.0"
44
(
5-
python.ExecuteFile @"D:\dump\_BDF\python\workshop\randomUV\randomUV.py"
5+
python.ExecuteFile @"C:\PATH\TO\randomUV\randomUV.py"
66
)

0 commit comments

Comments
 (0)