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

Translating and placing one document into relative path position in second

Contributor ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Im trying to combine two documents

 

document 1 has a Path with a crop area drawn as a path rectangle, which is also available as guides, this is where the image (an overlay) with a window should be placed...

 

document 2 the overlay image is an image with a window (transparent area in it) which i can select via action manager. code see below. The selections are not always rectangular on document 2. 

 

N.B the maximum width and height of the window in document 2 exactly match the dimensions of the Path in document 1 (which originates from a capture one crop) 

 

How can I duplicate the Document 2 in document 1 centering the window to the path?? 

selectTransparent()

function selectTransparent(){
function c2t(s) {return charIDToTypeID(s)}
var d1 = new ActionDescriptor();  
var r1 = new ActionReference();  
r1.putProperty( c2t( "Chnl" ), c2t( "fsel" ) );  
d1.putReference( c2t( "null" ), r1 );  
var r2 = new ActionReference();  
r2.putEnumerated( c2t( "Chnl" ), c2t( "Chnl" ), c2t( "Trsp" ) );  
r2.putEnumerated( c2t( "Lyr " ), c2t( "Ordn" ), c2t( "Mrgd" ) );   
d1.putReference( c2t( "T   " ), r2 );  
executeAction( c2t( "setd" ), d1, DialogModes.NO );     
 app.activeDocument.selection.invert();  }
  

 

TOPICS
Actions and scripting

Views

2.0K

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

Contributor , Jun 06, 2021 Jun 06, 2021

In the end I found a solution using xtools stdlib and some of @Kukurykus code to access anchor points which i hadnt every looking into before. The xtools function calculations selecitonbounds of irregular selections. 

 

#include stdlib.js

doc = app.activeDocument
SB = Stdlib.computeSelectionBoundsPS7(doc)

(docs = documents)[1].activeLayer.duplicate(doc = docs[0])
activeDocument = doc,
pP = doc.pathItems[0].subPathItems[0].pathPoints



aL.translate(pP[0].anchor[0], pP[0].anchor[1])
aL.translate(
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

I am not scripting guy, by the way. I can only give you idea. If you turn path into selection and paste object it will be centered, forced to center inside selection. Center of the pasted object should match center of selection.

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 ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Interesting, not sure it will work but ill try as the window is not always exactly in the centre of the layout.

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
LEGEND ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

 

(dcmnts = documents)[1].activeLayer.duplicate(dcmnt = dcmnts[0])
activeDocument = dcmnt, pP = dcmnt.pathItems[0].subPathItems[0].pathPoints

function anchr(v1, v2) {return pP[v1].anchor[v2]} function clcltn(v1, v2) {
	rslt = (anchr(v1, v2) + (anchr(v1 + 1 + v2, v2) - anchr(v1, v2)) / 2)
	- (bnds[v2] + (bnds[v2 + 2] - bnds[v2]) / 2).value; return rslt
}

bnds = (aL = dcmnt.activeLayer).bounds, aL.translate(clcltn(0, 0), clcltn(0, 1))

 

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 ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Oh that it exactly what im looking for,and nearly close to perfect.

@Kukurykus you're the man!  Its nearly perfect. 

 

I think it needs some sort of calc to find the largest dimension of the layout both horizontally and vertically 

any idea if thats fixable?

 

this is the current output:

 

Screenshot 2021-06-04 at 20.51.56.png

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
LEGEND ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

It looks only for first pathItem in document, you did not say there are more, are there?

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 ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

There is only 1 path item in the main document. 

 

but i can use the selectTransparency function to get a selection of he window of the layout document, which i guess could be translated to a work path,

 

And i guess would need somehow parse through all the path points to find the furthest to left and right and up and down

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
LEGEND ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

 

(dcmnts = documents)[1].activeLayer.duplicate(dcmnt = dcmnts[0])
gds = [].slice.call((activeDocument = dcmnt).guides); function vh(v) {
	return sc = shft.coordinate, !(v.length && sc) ? v.push(sc)
	: (v[0] > sc ? v.unshift(sc) : v.push(sc))
}

v = [], h = []; while(gds.length) {
	vh(unescape((shft = gds.shift()).direction)
	.split('Direction.')[1] == 'VERTICAL' ? v : h)
}

function clcltn(val) {
	return ((hv = val ? h : v)[0] + (hv[1] - hv[0]) / 2) -
	(bnds[val] + (bnds[val + 2] - bnds[val]) / 2).value
}

bnds = (aL = dcmnt.activeLayer).bounds, aL.translate(clcltn(0), clcltn(1))

 

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 ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

So i need to be able to compare the transparent selection (window of the layout)  to the path for positioning.

 

heres another example image, your script results in this...

Screenshot 2021-06-04 at 21.06.35.png

 

it should look like this:

 

Screenshot 2021-06-04 at 21.02.53.png

  

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
LEGEND ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

You did not answer. How many paths are there, and can't you put desired one as first?

You also did not mention if the path have more points than only 4, so corners, do they?

 

What I see from posted now images your original description doesn't fit the restul from script that is correct. Script sets duplicated layer in center point of the path, while now you show it shouldn't be ideally centered. The duplicated layer on your image is moved from center.

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 ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

This is what the 2 docs look like

 

 

main doc with path

Screenshot 2021-06-04 at 21.12.06.png

 

Layout doc with transparent window to be overlayed on main doc,

which can be used for selection and conversion to workpath if needed. 

Screenshot 2021-06-04 at 21.11.52.png

  

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 ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Sorry im not very good at explaining this problem..., 

 

Hopefully the images below explain. 

 

The main image

 path for example is 1500px x 1500px (this path is always rectangularr with 4 points as they come from a capture one crop)

 

The layout image

contains one pixel layer, with a transparent window, whose maximum horizontal opening is 1500px and maximum vertical opening is 1500px (however the window is rarely a perfect rectangle, nor centred in the canvas)

 

Does that make more sense??

 

 

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
Valorous Hero ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

Poorly understood, but I will suggest.
Create a smart object with the correct size and position.
Replace the content with the desired document.
 
Will this work for you?

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 ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

not sure it will but it's an interesting thought, I'm working on something based off @Kukurykus code, will show it once I've got it working. 

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
LEGEND ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

Not long later that day I posted other 'for guides' code I think you missed: Jun 04, 2021

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 ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

In the end I found a solution using xtools stdlib and some of @Kukurykus code to access anchor points which i hadnt every looking into before. The xtools function calculations selecitonbounds of irregular selections. 

 

#include stdlib.js

doc = app.activeDocument
SB = Stdlib.computeSelectionBoundsPS7(doc)

(docs = documents)[1].activeLayer.duplicate(doc = docs[0])
activeDocument = doc,
pP = doc.pathItems[0].subPathItems[0].pathPoints



aL.translate(pP[0].anchor[0], pP[0].anchor[1])
aL.translate(-SB[0], -SB[1])


  

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
LEGEND ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

Can you answer did you try the other code I made? And if not, then try it to see if that works?

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 ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

no didnt work thanks for your 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
LEGEND ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

Can you say then what was a result of that second script for you?

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 ,
Jun 07, 2021 Jun 07, 2021

Copy link to clipboard

Copied

Yes of course, here is the result of your second script.

Screenshot 2021-06-07 at 21.24.50.jpg

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
LEGEND ,
Jun 07, 2021 Jun 07, 2021

Copy link to clipboard

Copied

Due to your original description I did the second code that is based on guides, which like you said are in the same place the paths are. So if you used first script for same graphics it'd place the layer centrally to the center point of paths. With the second script the reference would be the the center point of guides.

 

The results for both scripts should be the same. On current screenshot that is little different than previous ones I guess the bottom part is hidden? If so all is okey. Then, in the other post you clarified what you exactly mean, but first I had to see result of second script on your side.

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 ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

LATEST

Apologies, i think it was a poor explaination of mine from the start, many thanks your help. The pathpoint anchor method was invaluable. 

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