Copy link to clipboard
Copied
hi all,
I need some help with javascript for indesign.
How can get a specific rectangle with image? I would to copy a specific rectangle with inside image and to paste into the other document. I thinking to use label but i don't find method to get that object via javascript.
Thank,
Sergio
Try this code:
//////////////////////////////////////////////////////////////////////////////////
var currentDoc = app.documents[0];
var nextDoc = app.documents[1];
for(var l = 0; l < currentDoc.links.length; l++){
if(currentDoc.links[l].parent.parent.constructor.name.toString() == "Rectangle"){
if(currentDoc.links[l].parent.parent.parent.constructor.name.toString() == "Spread"){
app.select(currentDoc.links[l].parent.parent);
app.copy();
app.open(nextDoc.
Copy link to clipboard
Copied
Sergio,
If you are selecting and copying to the clipboard you could simply run the code snipet below in the other document.
doc = app.documents[0];
app.paste();
Regards,
Mike
Copy link to clipboard
Copied
You can get the containing frame if you know the image link name like so:
Copy link to clipboard
Copied
Hi all, and many thanks to Brian and Mike.
I am sorry but my english is not very good.
Follow I try to explain with an example. Immagine this:
Doc_a with some rectangles that crop images. Rect_a, Rect_b and Rect_c
I would copy Rect_b and paste in a new Doc_b.
I hope i was clear.
I wish happy new year to all community members.
Sergio
Copy link to clipboard
Copied
Hi all,
Finally I solved the problem myself.
I set Rectangle name throught layer palette, than I get it with follow code:
var MyRectangle = app.documents.item(0).pages.item(0).rectangles.item("Rectangle_01");
Copy link to clipboard
Copied
Hello Sergio,
To answer your question from this post:
"I am sorry but my english is not very good.
Follow I try to explain with an example. Immagine this:
Doc_a with some rectangles that crop images. Rect_a, Rect_b and Rect_c
I would copy Rect_b and paste in a new Doc_b.
I hope i was clear."
I came up with the code below, its works to your specifications with the images having applied labels. Be sure to only select one image at a time when running.........
Regards,
Mike
Copy link to clipboard
Copied
hi Sergio,
kindly Find below scrtipt to get a specific rectangles set some label in window/utilities/scriptLabel
var myDoc=app.documents[0]
var myPageFrame = myDoc.pages[0].rectangles;OR myDoc.pages[0].rectangles.allPageItems
for (var tx=0; myPageFrame.length>tx; tx++){
if(myPageFrame[tx].label == "Address"){
myPageFrame[tx].textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;
myPageFrame[tx].textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
myPageFrame[tx].fit(FitOptions.frameToContent);
}
}
u can add any page like pages[0] or 1,
if u don t know then add on loop for page also
Copy link to clipboard
Copied
Try this code:
//////////////////////////////////////////////////////////////////////////////////
var currentDoc = app.documents[0];
var nextDoc = app.documents[1];
for(var l = 0; l < currentDoc.links.length; l++){
if(currentDoc.links[l].parent.parent.constructor.name.toString() == "Rectangle"){
if(currentDoc.links[l].parent.parent.parent.constructor.name.toString() == "Spread"){
app.select(currentDoc.links[l].parent.parent);
app.copy();
app.open(nextDoc.filePath.fsName.replace(/\\/g,'/')+"/"+nextDoc.name);
app.pasteInPlace();
app.open(currentDoc.filePath.fsName.replace(/\\/g,'/')+"/"+currentDoc.name);
}
}
}
//////////////////////////////////////////////////////////////////////////////////
Best
Sunil
Copy link to clipboard
Copied
Hi Sergio,
note the following if you call items by name with e.g.:
item("Name")
itemByName("Name")
That will always return only one single item ( InDesign CS5 and above ).
Even if there are more items with the same name.
Most important: Verify that your item really exists with property isValid. E.g run the two lines below. You'll see that there will be no error message. And definitely there is no page item at all in the new document:
var myDoc = app.documents.add();
var myItem = myDoc.pageItems.itemByName( "MyName" );
InDesign will not resolve the identifier of the page item until you like to do something with it.
For example you want to apply a fill color:
myItem.fillColor = myDoc.colors.itemByName("Magenta");
The line above will throw an error. Why? myItem simply does not exist.
You could test with:
myItem.isValid // Would return false in this case
Regards,
Uwe Laubender
( ACP )
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more