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

Opacity

New Here ,
Apr 03, 2009 Apr 03, 2009

Copy link to clipboard

Copied

Hi All,

I am new to scripting and I am trying to get the logic to change the opacity of a layer. Here's what I have so far.

//This is just a test script
#target photoshop

//bring application forward for double-click event
app.bringToFront();

//ensure that at least one document is open
if (!documents.length){
alert ('There are no documents open');

//if no document is open it will automatically create a new document once the user clicks ok
app.preferences.rulerUnits = Units.PIXELS
var docCount=documents.length
if (docCount==00
documents.add(1920,1080)

//create a new art layer at the beginning of the current document
var layerRef = app.activeDocument.artLayers.add()
layerRef.name = "Background"
layerRef.blendMode = BlendMode.NORMAL

//Select all so we can apply a fill to the selection
app.activeDocument.selection.selectAll

//create a color to used with the fill command
var colorRef = new SolidColor
colorRef.rgb.red = 0
colorRef.rgb.green = 0
colorRef.rgb.blue = 0

//Now apply fill to current selection
app.activeDocument.selection.fill(colorRef)
function changeOpacity(Background,opacity){
var object = imageObject.Style
object.opacity = (opacity/50);
object.filter = "alpha (opacity = " + opacity + + "(";

I know this is simple but I can't seem to figure it out.

Thank You!
TOPICS
Actions and scripting

Views

1.2K

Translate

Translate

Report

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
Adobe
Valorous Hero ,
Apr 03, 2009 Apr 03, 2009

Copy link to clipboard

Copied

Something like this...


//This is just a test script

#target photoshop



//bring application forward for double-click event

app.bringToFront();

var current_units = preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS



documents.add(1920,1080)

//create a new art layer at the beginning of the current document

var layerRef = app.activeDocument.artLayers.add()

layerRef.name = "Background2"

layerRef.blendMode = BlendMode.NORMAL

//Set opacity of new layer

layerRef.opacity=60;

//Select all so we can apply a fill to the selection

app.activeDocument.selection.selectAll



//create a color to used with the fill command

var colorRef = new SolidColor

colorRef.rgb.red = 0

colorRef.rgb.green = 0

colorRef.rgb.blue = 0



//Now apply fill to current selection

app.activeDocument.selection.fill(colorRef);

app.activeDocument.selection.deselect();

preferences.rulerUnits = current_units;

Votes

Translate

Translate

Report

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
Participant ,
Apr 17, 2009 Apr 17, 2009

Copy link to clipboard

Copied

I wonder if there's an option that if there's no Document, it will just stop running the script.

Something like:

if (!documents.length) {

     alerts ("There are no Documents");

     Exit (); // A function that stops the script

}

Has anyone succeeded doing it?

Thanks.

Votes

Translate

Translate

Report

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
Advisor ,
Apr 18, 2009 Apr 18, 2009

Copy link to clipboard

Copied

function main()  {

  if (app.documents.length == 0) {

     return;

  }

  var doc = app.activeDocument;

  // insert code here

};

main()

Votes

Translate

Translate

Report

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
Advisor ,
Apr 18, 2009 Apr 18, 2009

Copy link to clipboard

Copied

LATEST

.

Message was edited by: xbytor2 dupe.

Votes

Translate

Translate

Report

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