Hello all again,
I'm wondering if someone smarter than me can help figure this one out...
I'm trying to automate 'Unwrap UVW' to a default "Flatten: Custom" workflow. (See the picture)
I got a pretty good result with vibe coding (chatGPT) but it can't quite figure out the final, and most important component. It does everything right but doesn't get the right result (or at least not the same result as if I manually press that button).
Please see the code below and offer a suggestion if possible. Many, many thanks!
/* ===========================================================
HELPER – unwrap one object, set channel, run Pack-Custom
=========================================================== */
fn addUnwrapPackSingle obj mapChannel:2 =
(
local prevSel = selection as array
select obj
-- Add temporary Edit Poly modifier to force full poly selection
local epMod = Edit_Poly()
addModifier obj epMod
epMod.SetSelection #Face #{1..(getNumFaces obj)}
-- Add the unwrap modifier
local uMod = Unwrap_UVW()
addModifier obj uMod
uMod.unwrap.setMapChannel mapChannel
-- Ensure full polygon selection for Unwrap as well
uMod.unwrap.selectPolygons #{1..(uMod.unwrap.numberPolygons())}
-- Set current modifier to Unwrap
modPanel.setCurrentObject uMod
-- Run Pack ► Custom
if isProperty uMod #packNoParams then
(
uMod.packNoParams()
)
else if isProperty uMod.unwrap #packNoParams then
(
uMod.unwrap.packNoParams()
)
-- Optionally remove the Edit Poly modifier to clean up
-- deleteModifier obj epMod
-- Restore selection
select prevSel
)
/* ===========================================================
BATCH – loop through initial selection one-by-one
=========================================================== */
fn batchUnwrapPack mapChannel:2 =
(
local workList = for o in selection where isKindOf o GeometryClass collect o
if workList.count == 0 then
(
messageBox "Select one or more geometry objects first!"
return undefined
)
with undo off
(
for o in workList do
(
format ">> Unwrapping & packing : %\n" o.name
addUnwrapPackSingle o mapChannel:mapChannel
)
)
format "=== Finished : processed % objects ===\n" workList.count
)
/* ===========================================================
RUN (change the channel if you like)
=========================================================== */
batchUnwrapPack mapChannel:2