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

Copying to a specific group.

Contributor ,
Mar 15, 2011 Mar 15, 2011

Copy link to clipboard

Copied

I'm working with some scripting I modified from work to copy multiple textures into a single document for editing.  The textures remain the same, and the group name I need to copy them to remains the same, but the number and order of groups sometimes changes.  I currently use a combination of scripts and actions, but the issue with actions is, I can't seem to move layers and groups based on naming, only ordering, so they sometimes end up in the wrong group.  Anyway, here's the current lines of code I use to bring the texture into my file:


var originalDoc = app.documents.getByName("original.psd");
var tileDoc = app.documents.getByName("tiles.jpg");

var theTileLayer = tileDoc.layers.getByName("Background")
theTileLayer.duplicate(originalDoc, ElementPlacement.PLACEATBEGINNING);

The .psd and .jpg files are opened through actions, which are fine.  What I would like to change/add to this script is the ability to place the texture into a specific group and to also position the texture so that the upper left corner of the texture is in the upper left corner of the document (0,0 coordinates) regardless of the resolution of the document, as it sometimes changes.

Thanks for any help!

DGolberg

TOPICS
Actions and scripting

Views

827

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

correct answers 1 Correct answer

Community Expert , Mar 16, 2011 Mar 16, 2011

Sorry, possibly oversight on my part.

Does this work better?

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

var originalDoc = app.documents.getByName("original.psd");

var tileDoc = app.documents.getByName("tile.jpg");

var theTileLayer = tileDoc.layers.getByName("Background");

var theCopiedTile = theTileLayer.duplicate(originalDoc.layerSets.getByName("flooring"), ElementPlacement.PLACEATBEGINNING);

app.activeDocument = originalDoc;

theCopiedTile.name = "t

...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 15, 2011 Mar 15, 2011

Copy link to clipboard

Copied

var theTileLayer = tileDoc.layers.getByName("Background");

var theCopiedPattern = theTileLayer.duplicate(originalDoc, ElementPlacement.PLACEATBEGINNING);

app.activeDocument = originalDoc;

var theBounds = theCopiedPattern.bounds;

theCopiedPattern.translate(theBounds[0]*(-1), theBounds[1]*(-1));

As for the LayerSet you want the Layer moved to:

Do you want to set that up in the Script or do you want to create a dialog for that?

In the first case and if the LayerSet is top-level this may suffice (replace "aaa" with the proper name):

var theCopiedPattern = theTileLayer.duplicate(originalDoc.layerSets.getByName("aaa"), ElementPlacement.PLACEATBEGINNING);

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
Contributor ,
Mar 16, 2011 Mar 16, 2011

Copy link to clipboard

Copied

Well, I got it partially working.  There seems to be an issue with the positioning of the texture though.  When it runs the script to position the texture, the texture disappears, though the layer remains (the icon in the layer palette shows transparency background).  Beyond that it works perfectly.  I did modify it a little to clean up some redundant code (an error on my part).

Anyway, here's what I have now, and it runs fine, no errors; I just lose the texture, as mentioned, when it runs the bounds section of the script:

var originalDoc = app.documents.getByName("original.psd");
var tileDoc = app.documents.getByName("tile.jpg");


var theTileLayer = tileDoc.layers.getByName("Background");
var theCopiedTile = theTileLayer.duplicate(originalDoc.layerSets.getByName("flooring"), ElementPlacement.PLACEATBEGINNING);
app.activeDocument = originalDoc;
theCopiedTile.name = "tile";

var theBounds = theCopiedTile.bounds;
theCopiedTile.translate(theBounds[0]*(-1), theBounds[1]*(-1));

Thanks for the help!

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
Community Expert ,
Mar 16, 2011 Mar 16, 2011

Copy link to clipboard

Copied

Sorry, possibly oversight on my part.

Does this work better?

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

var originalDoc = app.documents.getByName("original.psd");

var tileDoc = app.documents.getByName("tile.jpg");

var theTileLayer = tileDoc.layers.getByName("Background");

var theCopiedTile = theTileLayer.duplicate(originalDoc.layerSets.getByName("flooring"), ElementPlacement.PLACEATBEGINNING);

app.activeDocument = originalDoc;

theCopiedTile.name = "tile";

var theBounds = theCopiedTile.bounds;

theCopiedTile.translate(theBounds[0]*(-1), theBounds[1]*(-1));

app.preferences.rulerUnits = originalRulerUnits;

This would probably take longer but you could also use

originalDoc.selection.selectAll();

originalDoc.activeLayer = theCopiedTile;

// Layer-TopEdges,Layer/TopEdges,Top Edges,Layer > Align > Top Edges,Align the top edges of the selected layers,

var id853 = charIDToTypeID( "Algn" );

var desc167 = new ActionDescriptor();

var id854 = charIDToTypeID( "null" );

var ref126 = new ActionReference();

var id855 = charIDToTypeID( "Lyr " );

var id856 = charIDToTypeID( "Ordn" );

var id857 = charIDToTypeID( "Trgt" );

ref126.putEnumerated( id855, id856, id857 );

desc167.putReference( id854, ref126 );

var id858 = charIDToTypeID( "Usng" );

var id859 = charIDToTypeID( "ADSt" );

var id860 = charIDToTypeID( "AdTp" );

desc167.putEnumerated( id858, id859, id860 );

executeAction( id853, desc167, DialogModes.ALL );

// Layer-LeftEdges,Layer/LeftEdges,Left Edges,Layer > Align > Left Edges,Align the left edges of the selected layers,

var id877 = charIDToTypeID( "Algn" );

var desc170 = new ActionDescriptor();

var id878 = charIDToTypeID( "null" );

var ref129 = new ActionReference();

var id879 = charIDToTypeID( "Lyr " );

var id880 = charIDToTypeID( "Ordn" );

var id881 = charIDToTypeID( "Trgt" );

ref129.putEnumerated( id879, id880, id881 );

desc170.putReference( id878, ref129 );

var id882 = charIDToTypeID( "Usng" );

var id883 = charIDToTypeID( "ADSt" );

var id884 = charIDToTypeID( "AdLf" );

desc170.putEnumerated( id882, id883, id884 );

executeAction( id877, desc170, DialogModes.ALL );

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
Contributor ,
Mar 17, 2011 Mar 17, 2011

Copy link to clipboard

Copied

The first one did the trick.  Thanks again for the help!

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
Community Expert ,
Mar 17, 2011 Mar 17, 2011

Copy link to clipboard

Copied

LATEST

You’re welcome.

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