Author Topic: Help with Max scripting  (Read 4415 times)

2023-10-12, 15:03:26

aaouviz

  • Active Users
  • **
  • Posts: 1009
    • View Profile
    • Another Angle 3D
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!

Code: [Select]
--Original script by: aaouviz
------

macroscript SaveAndExit
category: "AAScripts"
buttonText: "Save and Exit"
tooltip: "Save and Exit"
Icon:#("AAGen_01",1)


(
saveMaxFile
)
quitmax #noprompt
« Last Edit: 2023-10-12, 15:51:29 by maru »
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-10-12, 15:32:07
Reply #1

James Vella

  • Active Users
  • **
  • Posts: 682
    • View Profile
I assume you just want File > Save correct? Overwrite previous version?

Code: [Select]
--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
)

2023-10-12, 20:39:34
Reply #2

aaouviz

  • Active Users
  • **
  • Posts: 1009
    • View Profile
    • Another Angle 3D
Amazing, and perfect as always James.

Thanks a million!
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-10-12, 21:47:25
Reply #3

James Vella

  • Active Users
  • **
  • Posts: 682
    • View Profile
Glad to hear its working as expected :)

2024-01-11, 09:17:53
Reply #4

Frood

  • Active Users
  • **
  • Posts: 2001
    • View Profile
    • Rakete GmbH
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



Never underestimate the power of a well placed level one spell.

2024-01-11, 10:48:00
Reply #5

aaouviz

  • Active Users
  • **
  • Posts: 1009
    • View Profile
    • Another Angle 3D
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 :)
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2024-01-11, 13:21:42
Reply #6

Frood

  • Active Users
  • **
  • Posts: 2001
    • View Profile
    • Rakete GmbH
Yes, thanks for letting me steal that idea to use them for myself - which is my daily deed ;)


Good Luck



Never underestimate the power of a well placed level one spell.

2025-08-25, 17:50:26
Reply #7

aaouviz

  • Active Users
  • **
  • Posts: 1009
    • View Profile
    • Another Angle 3D
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!

Code: [Select]
/* ===========================================================
   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
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2025-08-26, 09:35:16
Reply #8

clemens_at

  • Active Users
  • **
  • Posts: 161
    • View Profile
try this:

Code: [Select]
    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:

Code: [Select]
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
)

2025-08-27, 19:58:53
Reply #9

aaouviz

  • Active Users
  • **
  • Posts: 1009
    • View Profile
    • Another Angle 3D
Hi clemens_at

That seems to have helped enormously! Thanks mate, really appreciate it :)
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2025-09-01, 17:00:06
Reply #10

aaouviz

  • Active Users
  • **
  • Posts: 1009
    • View Profile
    • Another Angle 3D
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 :)
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2025-09-01, 22:40:34
Reply #11

Aram Avetisyan

  • Corona Team
  • Active Users
  • ****
  • Posts: 987
    • View Profile
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:
Code: [Select]
maps = getClassInstances CoronaMultiMap
for map in maps do (map.seed = 42)
Aram Avetisyan | chaos-corona.com
Chaos Corona QA Specialist | contact us

2025-09-01, 23:27:48
Reply #12

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 9325
  • Let's move this topic, shall we?
    • View Profile
    • My Models
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.
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures