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

Copy and paste whole path to new documents

Explorer ,
Feb 08, 2024 Feb 08, 2024

Hello, guys. I have asked question about path before and  got helped by this site so I came here with new problem that I faced.

 

so I got successed to making new paths by js code and found several paths on Paths tab.

and my goal is  copy the path and paste it on new document but I couldn't find relative reference on site so I wonder if anyone got the Idea with this problem?

 

thank you.

722
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 08, 2024 Feb 08, 2024

Please explain the intended process with screenshots. 

What dimensions and color mode is the new file supposed to have? 

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 08, 2024 Feb 08, 2024

 

Screenshot 2024-02-08 at 13.11.00.pngScreenshot 2024-02-08 at 13.11.39.png

// 2024, use it at your own risk;
if (app.documents.length > 0) {
var thePath = selectedPath2020 ();
if (thePath != undefined) {
// copy path;
try {
var desc4 = new ActionDescriptor();
desc4.putString( stringIDToTypeID( "copyHint" ), "path" );
executeAction( stringIDToTypeID( "copyEvent" ), desc4, DialogModes.NO );
// new document;
var newDoc = app.documents.add(UnitValue (1000, "px"), UnitValue (1000, "px"), 300, "new image", NewDocumentMode.RGB);
// paste;
executeAction( stringIDToTypeID( "paste" ), undefined, DialogModes.NO );
} catch (e) {};
};
};
////// determine selected path //////
function selectedPath2020 () {
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref);
var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Path"), theIndex); 
var pathDesc = executeActionGet(ref);
var theKind = pathDesc.getEnumerationValue(stringIDToTypeID("kind"));
var theName = pathDesc.getString(stringIDToTypeID("pathName"));
//
return [theIndex, theKind, theName];
}
catch (e) {return undefined}
};

 

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
Explorer ,
Feb 13, 2024 Feb 13, 2024

Thanks and sorry for replying very late.

 

It's very similar to my wanted solution, but have some questions.

 

Is there any way to get images inside of path? Like, if I made path on the flower picture, I want to take the path with the selected flower images.

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 13, 2024 Feb 13, 2024

Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, …) visible to clarify what you mean? 

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
Explorer ,
Feb 13, 2024 Feb 13, 2024

screenshot.png

 

It's just a example, but I want to do quite same as this picture, though want to adjust positions of path.

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
Explorer ,
Feb 13, 2024 Feb 13, 2024

screenshot 2.png

 

original path and document is just like this

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 14, 2024 Feb 14, 2024

So this is not about the Path at all but about pixels copied with a Selection based on the Path? 

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
Explorer ,
Feb 14, 2024 Feb 14, 2024

Sorry for confusing. I'm not familiar with photoshop.. so it would be related to Selections but I want to copy those selection based on the Path with the Path to new document..

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 14, 2024 Feb 14, 2024

This creates a Vector Mask on a copy of the image. 

If this does not work out for you please post meaningful screenshots inclusing all pertinent Panels to clarify what you want to achieve. 

// copy document and apply selected path as vector mask;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var thePath = selectedPath2020 ();
if (thePath != undefined) {
// copy document;
try {
var theCopy = myDocument.duplicate ("thecopy", true);
theCopy.layers[0].isBackgroundLayer = false;
applyVectorMask ()
} catch (e) {};
};
};
////// apply vector mask //////
function applyVectorMask () {
var idpath = stringIDToTypeID( "path" );
var desc8 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putClass( idpath );
desc8.putReference( stringIDToTypeID( "null" ), ref2 );
var ref3 = new ActionReference();
ref3.putEnumerated( idpath, idpath, stringIDToTypeID( "vectorMask" ) );
desc8.putReference( stringIDToTypeID( "at" ), ref3 );
var ref4 = new ActionReference();
ref4.putEnumerated( idpath, stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc8.putReference( stringIDToTypeID( "using" ), ref4 );
executeAction( stringIDToTypeID( "make" ), desc8, DialogModes.NO );
};
////// determine selected path //////
function selectedPath2020 () {
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref);
var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Path"), theIndex); 
var pathDesc = executeActionGet(ref);
var theKind = pathDesc.getEnumerationValue(stringIDToTypeID("kind"));
var theName = pathDesc.getString(stringIDToTypeID("pathName"));
//
return [theIndex, theKind, theName];
}
catch (e) {return undefined}
};

 

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 15, 2024 Feb 15, 2024

Can you provide a file and the resulting file/s you want to create? 

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
Explorer ,
Feb 15, 2024 Feb 15, 2024

manga_sample.jfif

 

So basically, I cut those boxes by script with path and selected them, make a new document and then put those path infos with cut images to new document while putting those images vertically.

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 15, 2024 Feb 15, 2024

I asked for an example image and the resulting image.  

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
Explorer ,
Feb 15, 2024 Feb 15, 2024

화면 캡처 2024-02-16 165134.png화면 캡처 2024-02-16 165147.png

Do you mean these images?? Sorry for misunderstanding;;

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
Explorer ,
Feb 15, 2024 Feb 15, 2024

But I guess this is not I want...

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 16, 2024 Feb 16, 2024

Again: Can you provide a file and the resulting file/s you want to create? 

 

Not the result from the Script, the result as you want to get it? 

And not screenshots, but the actual files? (Feel free to use a mock-up or black out sensitive content.)

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
Explorer ,
Feb 22, 2024 Feb 22, 2024

Sorry for being late... I couldn't give further information but I have some questions so came back..

If I wanted to move those images which successfully duplicated by script seperately, is that possible? Maybe putting them into different layers would be work.. But keep making errors..

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, 2024 Feb 22, 2024

I don’t understand what you mean; please post meaningful screenshots (including all pertinent Panels) to illustrate what you mean – the image you start with and the result you want to achieve.  

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
Explorer ,
Feb 22, 2024 Feb 22, 2024

화면 캡처 2024-02-22 202859.png

So this image is the original image that I want to deal with. Applying your script to this one,

화면 캡처 2024-02-22 202928.png

It would be done like this. But now, I can't touch each images because they are in one layer? So what I want is..

화면 캡처 2024-02-22 203230.png

Deal with those images seperately while copy with script to new document. Trying to find a way, but only making one new layer and then over...

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, 2024 Feb 22, 2024

Are you sure you mean »new document« and not just »new Layer«? 

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
Explorer ,
Feb 22, 2024 Feb 22, 2024

yeah not just new layers, need to be new document..

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, 2024 Feb 22, 2024

If this does not work out for you do not bother trying to describe the issue, but provide the files (the original and the resulting file/s you want to create). 

Screenshot 2024-02-22 at 12.59.52.pngScreenshot 2024-02-22 at 13.03.47.png

// 2024, use at your own risk;
if (app.documents.length > 0) {
var myDocument = activeDocument.duplicate("thecopy", true);
var theCount = myDocument.pathItems.length;
myDocument.artLayers.add();
for (var m = 0; m < theCount; m++) {
mergVisibleToNewLayer();
myDocument.activeLayer.name = myDocument.pathItems[m].name;
myDocument.pathItems[m].select();
applyVectorMask ()
}
};
////////////////////////////////////
////// layer via copy //////
function mergVisibleToNewLayer (){
var desc23 = new ActionDescriptor();
desc23.putBoolean( stringIDToTypeID( "duplicate" ), true );
executeAction( stringIDToTypeID( "mergeVisible" ), desc23, DialogModes.NO );
};
////// apply vector mask //////
function applyVectorMask () {
var idpath = stringIDToTypeID( "path" );
var desc8 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putClass( idpath );
desc8.putReference( stringIDToTypeID( "null" ), ref2 );
var ref3 = new ActionReference();
ref3.putEnumerated( idpath, idpath, stringIDToTypeID( "vectorMask" ) );
desc8.putReference( stringIDToTypeID( "at" ), ref3 );
var ref4 = new ActionReference();
ref4.putEnumerated( idpath, stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc8.putReference( stringIDToTypeID( "using" ), ref4 );
executeAction( stringIDToTypeID( "make" ), desc8, DialogModes.NO );
};

 

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
Explorer ,
Feb 22, 2024 Feb 22, 2024

The result is quite great for me. Is there any script to help me to translate those layers by my own? Thank you!!

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, 2024 Feb 22, 2024

I do not understand what you mean, please provide actual examples (source image and intended resulting file/s). 

Feel free to black out all the text and illustrations. 

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
Explorer ,
Feb 23, 2024 Feb 23, 2024
LATEST

Hello I probably need some help with your smart things. Now, we have separate layers that hold each images in new document. I want to sort them with these code

화면 캡처 2024-02-23 183016.png

 

async function sortLayers() {
  let app = require("photoshop").app;
  let core = require("photoshop").core;
  let constants = require("photoshop").constants;

  let doc = app.activeDocument;
  let defaultBound = 0;

  for (let i = 0; i < doc.layers.length; i++) {
    const layer = doc.activeLayers[i];

    await core.executeAsModal(async () => {
      let bound = layer.bounds;
      let imgWidth = bound.width;

      let deltaX = doc.width / 2 - imgWidth / 2 - bound.left;
      let deltaY = -bound.top + defaultBound;

      await layer.translate(deltaX, deltaY);
      defaultBound += bound.height;
    });
  }
}

module.exports.sortLayers = sortLayers;
 
while when I chose all layers, the bounds is the size of whole selected layers so always move not I intended. 
화면 캡처 2024-02-23 183346.png
This is the result image that I want to make
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