Copy link to clipboard
Copied
Hi
does anybody know an expression/script to turn on/off the above mentioned properties.That would be quite useful.
cheers
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi
thank you very much,fantastic
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I would add that to each of the 4 functions?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
When you guys are done with this, please post it on AE Enhancers or AE Scripts!
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
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);
}
}
}
Copy link to clipboard
Copied
hm.....noting
Copy link to clipboard
Copied
The functions won't do anything unless you call them:
lightsOff();
Copy link to clipboard
Copied
ок, 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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 (((
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now