Chaos Corona Forum
General Category => General CG Discussion => Topic started by: aaouviz on 2023-10-12, 15:03:26
-
Man, I suck at maxscript...
I want to make a simple "Save and then Exit" script (via toolbar button).
This is what I have, but I can't quite get it to work as intended. Any helpers out there? Many thanks!
--Original script by: aaouviz
------
macroscript SaveAndExit
category: "AAScripts"
buttonText: "Save and Exit"
tooltip: "Save and Exit"
Icon:#("AAGen_01",1)
(
saveMaxFile
)
quitmax #noprompt
-
I assume you just want File > Save correct? Overwrite previous version?
--Original script by: aaouviz
------
macroscript SaveAndExit
category: "AAScripts"
buttonText: "Save and Exit"
tooltip: "Save and Exit"
Icon:#("AAGen_01",1)
(
max file save
quitmax #noprompt
)
-
Amazing, and perfect as always James.
Thanks a million!
-
Glad to hear its working as expected :)
-
Hi,
picked up the idea but implemented it as file menu item. Additionally, saving only happens if a save is required (no changed made to scene, relying on getSaveRequired()). Script goes to any autostart folder (usually scripts\startup). Sharing it as an alternate option.
Good Luck
-
Excellent!
The 'saving only happens if a save is required' seemed a bit beyond my capabilities, so I didn't bother. But this is clever of you, and I feel pleased to have I've influenced you, Frood :)
-
Yes, thanks for letting me steal that idea to use them for myself - which is my daily deed ;)
Good Luck
-
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
-
try this:
if isProperty uMod #packNoParams then
(
uMod.flattenMapNoParams()
)
else if isProperty uMod.unwrap #packNoParams then
(
uMod.unwrap.flattenMapNoParams()
also, I don't think you need the edit poly and force selection - so the simplified function:
fn addUnwrapPackSingle obj mapChannel:2 =
(
local prevSel = selection as array
select obj
-- Add the unwrap modifier
local uMod = Unwrap_UVW()
addModifier obj uMod
uMod.unwrap.setMapChannel mapChannel
-- Set current modifier to Unwrap
modPanel.setCurrentObject uMod
-- Run Pack ► Flatten
if isProperty uMod #packNoParams then
(
uMod.flattenMapNoParams()
)
else if isProperty uMod.unwrap #packNoParams then
(
uMod.unwrap.flattenMapNoParams()
)
-- Restore selection
select prevSel
)
-
Hi clemens_at
That seems to have helped enormously! Thanks mate, really appreciate it :)
-
Any idea how I can change the "randomSeed" value of a CoronaMultiMap (or any node) with a script?
Ideally I can +1 the existing value, or toggle between 0/1.
Any help MUCH appreciated :)
-
Any idea how I can change the "randomSeed" value of a CoronaMultiMap (or any node) with a script?
Ideally I can +1 the existing value, or toggle between 0/1.
Any help MUCH appreciated :)
Hi,
I would give slightly off-topic advice - do not try to "automate" everything through script, or at least see if it is worth it.
Changing multimap's seed depends on how exactly the map is going to be found - it is not a straight forwards thing, unfortunately. You either need to get/select an object, then find the corresponding multimap (can be many) and then change the seed. On the other hand, you can open material editor, locate the multimap visually and change the seed. Or you can use a controller (e.g. bezier float) to quickly change it, if opening material settings is an extra click for you. The same controller workflow would apply also for multiple CoronaMultiMaps for multiple objects and materials.
Ironically, if you want to change the seed parameter for all CoronaMultiMaps, that is a rather easy and quick line of code:
maps = getClassInstances CoronaMultiMap
for map in maps do (map.seed = 42)
-
Another option is to use parameter wiring. I linked the seed ta a custom slider in my example, but you can wire it to almost anything in Max - height of a cube primitive, movement of teapot, etc. Any parameters that has numeric values can be "wired" together. Don't know how robust this method is, e.g. if you'll make significant changes in your material, the wiring might brake, but it takes only few seconds to rewire everything again.
-
Any idea how I can change the "randomSeed" value of a CoronaMultiMap (or any node) with a script?
Ideally I can +1 the existing value, or toggle between 0/1.
Any help MUCH appreciated :)
Hi,
I would give slightly off-topic advice - do not try to "automate" everything through script, or at least see if it is worth it.
Changing multimap's seed depends on how exactly the map is going to be found - it is not a straight forwards thing, unfortunately. You either need to get/select an object, then find the corresponding multimap (can be many) and then change the seed. On the other hand, you can open material editor, locate the multimap visually and change the seed. Or you can use a controller (e.g. bezier float) to quickly change it, if opening material settings is an extra click for you. The same controller workflow would apply also for multiple CoronaMultiMaps for multiple objects and materials.
Ironically, if you want to change the seed parameter for all CoronaMultiMaps, that is a rather easy and quick line of code:
maps = getClassInstances CoronaMultiMap
for map in maps do (map.seed = 42)
Thanks. What if the texture node/material name is known and hard-coded in? Does that help?
Are there any API/docs available for this sort of scripting in Corona? I found general settings but nothing specific to materials and textures.
-
Another option is to use parameter wiring. I linked the seed ta a custom slider in my example, but you can wire it to almost anything in Max - height of a cube primitive, movement of teapot, etc. Any parameters that has numeric values can be "wired" together. Don't know how robust this method is, e.g. if you'll make significant changes in your material, the wiring might brake, but it takes only few seconds to rewire everything again.
Damn, that's amazing! And pretty helpful.
A quick search gave me limited help - any idea where I might be able to find good tutorials on how best to use this feature?
Does it work in reverse? So for instance; I have a slider; I change it and the geometry z scale changes). But if I manually change the z-scale of the same object, the slider responds?
Such a cool feature, wish I had more time to play around with it...
-
Damn, that's amazing! And pretty helpful.
A quick search gave me limited help - any idea where I might be able to find good tutorials on how best to use this feature?
Parameter wiring is pretty straightforward thing in 3ds Max and pretty useful too. It's also easy to learn, i think i've read Max help on it, did a couple practice wirings and that's it. You probably can find some tutorials on YT if you want more streamlined experience. One evening should be plenty enough to learn it.
Does it work in reverse? So for instance; I have a slider; I change it and the geometry z scale changes). But if I manually change the z-scale of the same object, the slider responds?
Yes, it can work in one way, or another, or in both, you have an option to set up parameters relation to each other in parameters wiring window.