Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Accepts Lights+Shadows via expression or Script

Guest
Mar 18, 2010 Mar 18, 2010

Hi

does anybody know an expression/script to turn on/off the above mentioned properties.That would be quite useful.

cheers

TOPICS
Expressions
4.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 19, 2010 Mar 19, 2010

Something like this should get you headed in the right direction:

{

  function shadowsOn(){
    var myLayers = app.project.activeItem.selectedLayers;
    for (var i = 0; i < myLayers.length; i++){
      myLayers.acceptsShadows.setValue(true);
    }
  }

  function shadowsOff(){
    var myLayers = app.project.activeItem.selectedLayers;
    for (var i = 0; i < myLayers.length; i++){
      myLayers.acceptsShadows.setValue(false);
    }
  }

  function lightsOn(){
    var myLayers = app.project.activeItem.selectedLa

...
Translate
Community Expert ,
Mar 18, 2010 Mar 18, 2010

This simple example script turns off accept lights and shadows for selected layers (it assumes those properties haven't been keyframed):

{
  var myLayers = app.project.activeItem.selectedLayers;
  for (var i = 0; i < myLayers.length; i++){
    myLayers.acceptsShadows.setValue(false);
    myLayers.acceptsLights.setValue(false);
  }
}

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2010 Mar 19, 2010

Hi Dan

thx for that.

i'm trying to create a dockable panel for this script.

basically i'd like only 2 buttons=> accept shadows >option with on or off

                                                 accept lights>option with on or off

//that's what i have so far

function createUI(thisObj) {

var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Tools",

[100, 100, 300, 300]);

myPanel.add("button", [10, 10, 150, 30], "Accept Shadows on");

return myPanel; }

var myToolsPanel = createUI(this);

How can i add more buttons to this?

How can i make the buttons run the script?

cheers

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 19, 2010 Mar 19, 2010

Something like this should get you headed in the right direction:

{

  function shadowsOn(){
    var myLayers = app.project.activeItem.selectedLayers;
    for (var i = 0; i < myLayers.length; i++){
      myLayers.acceptsShadows.setValue(true);
    }
  }

  function shadowsOff(){
    var myLayers = app.project.activeItem.selectedLayers;
    for (var i = 0; i < myLayers.length; i++){
      myLayers.acceptsShadows.setValue(false);
    }
  }

  function lightsOn(){
    var myLayers = app.project.activeItem.selectedLayers;
    for (var i = 0; i < myLayers.length; i++){
      myLayers.acceptsLights.setValue(true);
    }
  }

  function lightsOff(){
    var myLayers = app.project.activeItem.selectedLayers;
    for (var i = 0; i < myLayers.length; i++){
      myLayers.acceptsLights.setValue(false);
    }

  }

  function createUI(thisObj) {
    var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Tools", [100, 100, 300, 300]);
    myPanel.shadowsOnBtn = myPanel.add("button", [10, 10, 150, 30], "Accept Shadows on");
    myPanel.shadowsOffBtn = myPanel.add("button", [10, 50, 150, 70], "Accept Shadows off");
    myPanel.lightsOnBtn = myPanel.add("button", [10, 90, 150, 110], "Accept Lights on");
    myPanel.lightsOffBtn = myPanel.add("button", [10, 130, 150, 150], "Accept Lights off");
    myPanel.shadowsOnBtn.onClick = shadowsOn;
    myPanel.shadowsOffBtn.onClick = shadowsOff;
    myPanel.lightsOnBtn.onClick = lightsOn;
    myPanel.lightsOffBtn.onClick = lightsOff;
    return myPanel;
  }

  var myToolsPanel = createUI(this);
  myToolsPanel.show();

}

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 20, 2010 Mar 20, 2010

Hi

thank you very much,fantastic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 26, 2014 Aug 26, 2014

Using this in CC2014 and it seems to not work if I select too many layers or if I have non-3D layers or lights selected.

Can someone take a look at it and tune it up for the current version? Have it ignore objects that are irrelevant (Lights, Cameras, 2D layers, etc)

Maybe have it report how many layers it successfully modified?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 26, 2014 Aug 26, 2014

You could make it more robust by modifying the functions to do some validation, like this:

  function shadowsOn(){

    var myLayers = app.project.activeItem.selectedLayers;

    for (var i = 0; i < myLayers.length; i++){

      if (myLayers instanceof AVLayer && myLayers.threeDLayer)

        myLayers.acceptsShadows.setValue(1);

    }

  }

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 26, 2014 Aug 26, 2014

I would add that to each of the 4 functions?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 26, 2014 Aug 26, 2014

No, you would modify each of the 4 functions in a similar way, but use setValue(0) for the properties being turned off, and use the correct property name.

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 27, 2014 Aug 27, 2014

Alrighty... Lights Off now works great when non-3d objects are selected. However, Lights On doesn't work right. I still have to individually select just the 3D layer(s) that use lights.

Here's the code I'm using based on your input:

function LightsOn(){

    var myLayers = app.project.activeItem.selectedLayers;

    for (var i = 0; i < myLayers.length; i++){

      if (myLayers instanceof AVLayer && myLayers.threeDLayer)

      myLayers.acceptsLights.setValue(true);

    }

  }

  function lightsOff(){

     var myLayers = app.project.activeItem.selectedLayers;

    for (var i = 0; i < myLayers.length; i++){

      if (myLayers instanceof AVLayer && myLayers.threeDLayer)

      myLayers.acceptsLights.setValue(false);

    }

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2014 Aug 27, 2014

I do see one problem. apparently 3D Text and Shape layers don't get detected as AVLayers, so you need to expand the if logic to something like this:

if (((myLayers instanceof AVLayer) || (myLayers instanceof TextLayer) || (myLayers instanceof ShapeLayer)) && myLayers.threeDLayer)

When I do that, your lightsOn() code seems to work for me.

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 25, 2010 Mar 25, 2010

When you guys are done with this, please post it on AE Enhancers or AE Scripts!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2023 Feb 21, 2023

Don't work in AE 2023 

or am I doing something wrong? create notepad file .jsx

 

function LightsOn(){

    var myLayers = app.project.activeItem.selectedLayers;

    for (var i = 0; i < myLayers.length; i++){

      if (myLayers instanceof AVLayer && myLayers.threeDLayer)

      myLayers.acceptsLights.setValue(true);

    }

  }

 

 

 

  function lightsOff(){

     var myLayers = app.project.activeItem.selectedLayers;

    for (var i = 0; i < myLayers.length; i++){

      if (myLayers instanceof AVLayer && myLayers.threeDLayer)

      myLayers.acceptsLights.setValue(false);

    }

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2023 Feb 21, 2023

They just need a little tidying up:

function lightsOn(){
  var myLayers = app.project.activeItem.selectedLayers;
  for (var i = 0; i < myLayers.length; i++){
    if (myLayers[i] instanceof AVLayer && myLayers[i].threeDLayer){
      myLayers[i].acceptsLights.setValue(true);
    }
  }
}

function lightsOff(){
  var myLayers = app.project.activeItem.selectedLayers;
  for (var i = 0; i < myLayers.length; i++){
    if (myLayers[i] instanceof AVLayer && myLayers[i].threeDLayer){
      myLayers[i].acceptsLights.setValue(false);
    }
  }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2023 Feb 21, 2023

hm.....noting
aaaa.JPG

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2023 Feb 21, 2023

The functions won't do anything unless you call them:

lightsOff();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2023 Feb 21, 2023

ок, and how then to correctly write an expression for turning off and on the parameter - Accepts Light. In the previous posts, I understood that they decided this and it should work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2023 Feb 22, 2023

Well now I'm confused. This thread has been about scripting, not expressions (even though the OP did ask about an expression/script) and the image you posted includes the script editor, so I'm not sure what you're after exactly. There wouldn't be any way to do it with an expression.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2023 Feb 22, 2023

I was wrong, I'm sorry. I meant that if you make a file with the .jsx extension from this and run it in AE via "File-> Run script file", then this does not work (((

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2023 Feb 22, 2023
LATEST

You could write a script that turns all the lights on, like this:

 

 

 

function lightsOn(){
  var myLayers = app.project.activeItem.selectedLayers;
  for (var i = 0; i < myLayers.length; i++){
    if (myLayers[i] instanceof AVLayer && myLayers[i].threeDLayer){
      myLayers[i].acceptsLights.setValue(true);
    }
  }
}
lightsOn();

But if you want one that turns the lights on or off, I think you'd need to add a UI and a couple of buttons, which would be a whole different thing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines