Author Topic: Script code to toggle scatters?  (Read 994 times)

2023-08-11, 08:38:32

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Hi all,

I'm hoping some of you smart people can help me with a quick little bit of code to toggle on/off all of the scene scatters in 3dsmax.

Basically in the same way that it works in the scatter lister, but integrated in to my own existing "make things go faster" toolbar button script that I use.

I'm guessing this is possible, so how might it work?

Thanks in advance for any help!
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-08-11, 09:09:36
Reply #1

James Vella

  • Active Users
  • **
  • Posts: 540
    • View Profile
Not sure what on/off means exactly, but this will toggle the 'enable' button on and off for scatters. Edit: oh right the lister, yes this does that toggle all on/off. Actually this just flips the ones that are on off and the ones that are off on. Ill take another look later should be fairly simple.

Code: [Select]

-- Toggle Chaos Scatter on/off
for i in getClassInstances ChaosScatter target:rootNode do
(
if i.Enable == on then i.Enable = off else i.Enable = on
)

« Last Edit: 2023-08-11, 09:35:31 by James Vella »

2023-08-11, 09:58:05
Reply #2

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Thanks mate. It works well!

However, for the life of me (I often have issues a similar manner) I can't seems to integrate it into my existing script.

The current script looks something like this:

Code: [Select]
macroscript ToggleScattersOff
category: "AAScripts"
buttonText: "Sk Off"
tooltip: "ToggleScatters"
Icon:#("AAScatters",1)



for i = 0 to (layermanager.count - 1) do     -- loops through all the layers in the scene
(
x = layermanager.getlayer i              -- gets layer
test = x.name as string                  -- applies the name of layer to test
location = findString test "10_"         -- finds "ref" in layer name, output 1 if present
if location == 1 do                      -- if ref is present in the layer name at the begining, 1 then
(
if x.on == true then x.on = false  -- the layer x is on, then turn it off
                   -- the layer x is off, then turn it on. A toggle on/off really                     
)                                   -- end if
)                                            -- end loop


)

Where/how can I put you code?

Many, many thanks!
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-08-11, 10:23:46
Reply #3

James Vella

  • Active Users
  • **
  • Posts: 540
    • View Profile
This one does more of a similar job to toggle all on/off, the first one I posted just flips it. So this should be better to use:

Code: [Select]

-- Find if Scatter is on/off
for i in getClassInstances ChaosScatter target:rootNode do
(
if i.Enable == on then global cs_enabled = true else cs_enabled = false
)

-- Toggle Chaos Scatter on/off
for i in getClassInstances ChaosScatter target:rootNode do
(
if cs_enabled == true then i.enable = off else i.enable = on
)


Regarding your code, you have an open parenthesis at the bottom, so thats either a mistake or you missed something above. But it should look something like this:

Code: [Select]

macroscript ToggleScattersOff
category: "AAScripts"
buttonText: "Sk Off"
tooltip: "ToggleScatters"
Icon:#("AAScatters",1)
(
for i = 0 to (layermanager.count - 1) do     -- loops through all the layers in the scene
(
x = layermanager.getlayer i              -- gets layer
test = x.name as string                  -- applies the name of layer to test
location = findString test "10_"         -- finds "ref" in layer name, output 1 if present
if location == 1 do                      -- if ref is present in the layer name at the begining, 1 then
(
if x.on == true then x.on = false  -- the layer x is on, then turn it off
                   -- the layer x is off, then turn it on. A toggle on/off really                     
)                                   -- end if
) -- end loop

-- Find if Scatter is on/off
for i in getClassInstances ChaosScatter target:rootNode do
(
if i.Enable == on then global cs_enabled = true else cs_enabled = false
)

-- Toggle Chaos Scatter on/off
for i in getClassInstances ChaosScatter target:rootNode do
(
if cs_enabled == true then i.enable = off else i.enable = on
)
)


edit: sorry missed a bit, this should work

2023-08-11, 10:36:35
Reply #4

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Absolute champion!

Got it working

Thanks again mate :)
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-08-11, 10:46:15
Reply #5

James Vella

  • Active Users
  • **
  • Posts: 540
    • View Profile