Author Topic: CoronaSelect - Maxscript  (Read 895 times)

2024-08-21, 23:11:48

Alex Abarca

  • Active Users
  • **
  • Posts: 459
  • Corona Certified Instructor
    • View Profile
    • Instagram
Hi All,

Does anyone have a script that looks in the scene's material for CoronaSelect nodes and the toggles the CoronaSelect from 0 to 1?

I have decals that needs to switch from ON and OFF in the scene.

Thank you!


2024-08-22, 11:43:40
Reply #1

James Vella

  • Active Users
  • **
  • Posts: 670
    • View Profile
You could do something like this:

Code: [Select]
(
    -- Collect Corona Materials from Slate Material Editor selection
    local selected_materials = #() 
    if (sme.getview sme.activeView) != undefined then 
    ( 
        selected_nodes = (sme.getview sme.activeView).GetSelectedNodes()   
        if selected_nodes.count != 0 then 
        ( 
            for node in selected_nodes do 
            ( 
                if (superclassof node.reference == material) then 
                ( 
                    if classof node.reference == CoronaPhysicalMtl or
                       classof node.reference == CoronaLegacyMtl then
                    (
                        append selected_materials node.reference 
                    )
                ) 
            ) 
        )
    )

    -- Toggle Corona Select 0 or 1 (does not support more than 0 or 1)
    for i in selected_materials do
    (
        for cSelect in (getClassInstances CoronaSelect target:i) do 
        ( 
           if cSelect.selected == 0 then
           (
                cSelect.selected = 1
           )
           else
           (
                cSelect.selected = 0
           )
        )
    )
)

Notes:
- Supports 0 or 1, if you need additional "map count" then you would have to change the script.
- Works on selected material in Slate Editor (not selected objects or child nodes in the Slate Editor).
- If you have 2 materials sharing the one Corona Select node only pick one of the materials (in your screenshot for example).

2024-08-22, 11:51:57
Reply #2

James Vella

  • Active Users
  • **
  • Posts: 670
    • View Profile
Also if you just want to do it scene wide without having to select materials you could use this instead:

Code: [Select]
for cSelect in getClassInstances CoronaSelect do
(
    if cSelect.selected == 0 then
    (
        cSelect.selected = 1
    )
    else
    (
        cSelect.selected = 0
    )
)

« Last Edit: 2024-08-22, 11:58:07 by James Vella »

2024-08-22, 20:41:28
Reply #3

Alex Abarca

  • Active Users
  • **
  • Posts: 459
  • Corona Certified Instructor
    • View Profile
    • Instagram
Thanks, James! I have to say, both scripts are pretty nifty, and I can see the use cases for each. However, in my case, I need to remove logos from library objects that are scattered across the scene, and this is something I have to deal with regularly. Given my situation, I prefer the second script. Appreciate the help!

2024-08-22, 21:43:16
Reply #4

James Vella

  • Active Users
  • **
  • Posts: 670
    • View Profile
You're welcome! Yes feel free to use which is best for your situation. I figured someone might also want the first script so I kept both here in case.

It wouldn't be hard to a toggle for one with 100+ "map count"(s) either but I only spent 30 seconds on each so that will do for now lol.

Also just be aware its just a toggle, so this is assuming you keep your workflow consistent, if you somewhere along the line decide to flip 0 with 1 in your CoronaSelect then you will encounter unexpected results.
« Last Edit: 2024-08-22, 21:55:27 by James Vella »