Skip to main content
Gibson Editions
Inspiring
June 4, 2021
Answered

Translating and placing one document into relative path position in second

  • June 4, 2021
  • 2 replies
  • 3281 views

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();  }
  

 

This topic has been closed for replies.
Correct answer Gibson Editions

Not long later that day I posted other 'for guides' code I think you missed: Jun 04, 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(-SB[0], -SB[1])


  

2 replies

Kukurykus
Legend
June 4, 2021

 

(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))

 

Gibson Editions
Inspiring
June 4, 2021

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:

 

Kukurykus
Legend
June 4, 2021

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


 

(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))

 

Bojan Živković11378569
Community Expert
Community Expert
June 4, 2021

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.

Gibson Editions
Inspiring
June 4, 2021

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