Notifications
Clear all

[Closed] Script a UVW Unwarp

Hi there, this my first post here waves

I have a folder containing several hundred .obj models for each one i currently have to

  1. import it
  2. apply a Unwarp UVW modifier
  3. select faces > select edit > select Flatten Mapping, set spacing to 0.02 and apply
  4. Export as .obj file

Doing this constantly is really labourious, i wonder if someone here might be able to help me write a script to automate this ?

Many thanks for any advice!

David

8 Replies
1 Reply
(@lucpet)
Joined: 11 months ago

Posts: 0

Hi David here is some code that will start you off. I have to go out for the day otherwise it would be a more thorough.

un = (Unwrap_UVW ()) ui:on
for i in selection do addModifier i un -- this will loop over the objects adding the uvw unwrap
--------------------------------------------------------------------------------------
-- this block of code I adapted from my rockmaker script so it needs customising to your 
-- needs but will start you off
modPanel.setCurrentObject $.modifiers[#Unwrap_UVW]
SubObjectlevel = 1 
$.modifiers[#unwrap_uvw].unwrap2.setIgnoreBackFaceCull off
$.modifiers[#unwrap_uvw].unwrap6.selectVerticesByNode #{1..730} $
$.modifiers[#unwrap_uvw].unwrap2.fitRelax 50 0.1
$.modifiers[#unwrap_uvw].unwrap2.packNoParams()
$.modifiers[#unwrap_uvw].unwrap6.selectVerticesByNode #{1..730} $
$.modifiers[#unwrap_UVW].unwrap2.scaleSelectedCenter 0.98 0

If no one else come to your aid I’ll be able to spend some time on this tomorrow

Thanks Luke,

I’m afraid i’m new to scripting in 3dsmax and will work through http://vimeo.com/album/1514565 over the coming week.

hopefully when i’ve gone through the tutorials i’ll know what to do with the script snippet

if you do have a chance to expand the script a little i’d much appreciate it

Many thanks

David

GreyCloud I’ve got some time today I’ll see what I can come up with for you. In the mean time have a good look at scriptspot.com there’s probably something there that will do the job.

Thanks lucpet, i’ve had a look through scriptspot but i cant find anything to do this task, all the uvw related scripts seems to do really complex things :-/

ok, I’ve had a shot at writing a script as follows:

utility UnwrapAll “UnwrapAll”
(
– FUNCTION DECLARATIONS
– A function used to modify file names containing ‘’ to “\”
fn replaceChar str oChar rChar =
(
tStr = “”
for i=1 to str.count do
(
if str[i] == oChar then tStr += rChar
else tStr += str[i]
)
tStr
)

– USER INTERFACE ITEMS
button btnTargetDir “Where to save Unwrapped files”
button btnSourceDir “Where are the Original files” enabled:false
on btnTargetDir pressed do
(
target = getSavePath caption:“Select directory for Unwrapped files:”
if target == undefined do return false
btnTargetDir.text = (target)
btnSourceDir.enabled = true
)
on btnSourceDir pressed do
(
local dir = getSavePath caption:“Select which directory
holds the Original files:”
if dir == undefined do return false
files = getFiles ( (replaceChar (dir as string) “\” “\\”) + “[\*.obj](file://*.obj)” )
for f in files do (
resetMaxFile #noPrompt
importFile f #noPrompt
max views redraw
select objects
for i in selection do (
un = Unwrap_UVW ()
un.setApplyToWholeObject(true)
un.setIgnoreBackFaceCull(false)
addModifier i un
un.setTVSubObjectMode(3) –faces
un.setFlattenSpacing(0.002)
un.flattenMapNoParams()
–collapseStack i
)
destinationFile = btnTargetDir.text + “\” + getFilenameFile f + “.obj”
exportfile (destinationFile) #noPrompt
)
btnSourceDir.text = (“Source =” + dir)
)
)

HOWEVER it doesn’t work – i end up logging like this:
Surface Area 0.000000 bounds area 1.#INF00 per used 0.000000
Edge Height 0.000000 Edge Width 0.000000
Initial Clusters 0 finalClusters 0
Surface Area 0.000000 bounds area 1.#INF00 per used 0.000000
Edge Height 0.000000 Edge Width 0.000000
Initial Clusters 0 finalClusters 0
Surface Area 0.000000 bounds area 1.#INF00 per used 0.000000
Edge Height 0.000000 Edge Width 0.000000
Initial Clusters 0 finalClusters 0

which shows that the unwrap didnt work. If however i import the file manually and then run this bit of code (same as part above) it works fine and i get output indicating it works…

max views redraw
select objects
for i in selection do (
un = Unwrap_UVW ()
un.setApplyToWholeObject(true)
un.setIgnoreBackFaceCull(false)
addModifier i un
un.setTVSubObjectMode(3) –faces
un.setFlattenSpacing(0.002)
un.flattenMapNoParams()
–collapseStack i
)

any idea?!

I dont know how to attach files but i have a few obj files…

ok fixed it…

needed a

max modify mode

after the

max views redraw

not entirely sure way max doesnt put it in modify mode straight after the import…

Well done! you obviously didn’t need my help, If fact I’m going to ask you for help in the future lol I’m guessing you come from another language? (if not then I give up lol it took me ages to get to where I am :banghead: )

I hadn’t realised max 2012 had updated the uvunwrap to include the ability to easily select all faces, while this will restrict you to 2012 and no backward compatibility, I guess it doesn’t mater if it’s for your own use.

lol that took the best part of 6 hours to put together with your code being a good starting point. Yep i code a lot in other languages but know very very little of 3dsmax and found its scripting language very strange. Still a lot of googling got me a few things i could throw together

Thanks & good luck in the future