Copy link to clipboard
Copied
Hi,
I need help, I'm a novice in javascript, but I like to automate my query is after pasting the object into the text line, it is possible to move the same height of the object down and after apply textwrap
in this way
Thanks for your help
Not too sure what you mean by "selection"; hopefully you mean the last-placed image.
The following places images from an array below the first paragraph of the page. They will be placed 200px from the left and left aligned with 8 pts gap (space) between:
var placedItem, imageRef, rectRef, gBounds, yPos, x0;
var yOffset = 36; //gap below first paragraph
var yGap = 8; //gap between images
var x0=200;
var myFiles = getFile ("Choose files", "*.png", true);
var myPage = app.documents[0].pages[0];
app.script
...Copy link to clipboard
Copied
Rectangle that holds placed image has a number of properties that are part of the anchoredObjectSettings. The following snippet may help. This where placedRef is a reference to the placed object and ancSettings is the anchored settings property record. You will need to set other properties to control the horizontal settings.
var yOffset = "10pts";
var placedRef = insRef.place(myFile);
var imageRef = placedRef[0];
var rectRef = imageRef.parent;
var ancSettings = {anchoredPosition:AnchorPosition.ANCHORED,
anchorPoint:AnchorPoint.TOP_LEFT_ANCHOR,
verticalReferencePoint:VerticallyRelativeTo.LINE_BASELINE,
verticalAlignment:VerticalAlignment.TOP_ALIGN,
anchorYoffset:yOffset};
rectRef.anchoredObjectSettings.properties=ancSettings;
Hope this helps
Copy link to clipboard
Copied
Hi S Hopkins thanks for your help,the script is great but I would like the image to be kept within the text line and not as an anchored object.
Copy link to clipboard
Copied
Oops, that's what we get for assuming. Maybe the following will help:
To move a page item relative use the move method with undefined:
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
rectRef.move(undefined, [0, 72]); //moves item vertically 72 points
To move a page item given a specific measurement use move without undefined.
To calculate the position of the item relative to the last line of a paragraph, use the line's baseline property
var yOffset = 36;
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var bLine = myPage.textFrames[0].paragraphs[0].lines[-1].baseline;
//Baseline includes the top margin, so you need to subtract that:
var marTop = myPage.marginPreferences.top;
bLine = bLine - marTop;
var x0 = rectRef.geometricBounds[0];
var yPosition = bLine + yOffset;
rectRef.move([x0,yPosition]); //moves item to page position 36 points below referenced paragraph
Copy link to clipboard
Copied
I appreciate your help but only position the first image correctly, and how to make the yOffset variable capture the value of the height of the selected object, something like yOffset=app.selection [0].height
var yOffset = 123.405;
var rectRef=app.selection[0]
var myPage=app.activeWindow.activePage;
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var bLine = myPage.textFrames[0].paragraphs[0].lines[-1].baseline;
//Baseline includes the top margin, so you need to subtract that:
var marTop = myPage.marginPreferences.top;
bLine = bLine - marTop;
var x0 = rectRef.geometricBounds[0];
var yPosition = bLine + yOffset;
rectRef.move([x0,yPosition]); //moves item to page position 36 points below referenced paragraph
rectRef.textWrapPreferences.textWrapMode =TextWrapModes.JUMP_OBJECT_TEXT_WRAP;
Copy link to clipboard
Copied
Not too sure what you mean by "selection"; hopefully you mean the last-placed image.
The following places images from an array below the first paragraph of the page. They will be placed 200px from the left and left aligned with 8 pts gap (space) between:
var placedItem, imageRef, rectRef, gBounds, yPos, x0;
var yOffset = 36; //gap below first paragraph
var yGap = 8; //gap between images
var x0=200;
var myFiles = getFile ("Choose files", "*.png", true);
var myPage = app.documents[0].pages[0];
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var bLine = myPage.textFrames[0].paragraphs[0].lines[-1].baseline;
var marTop = myPage.marginPreferences.top;
yPos = (bLine + marTop) + yOffset;
for (i=0; i<myFiles.length; i++){
placedItem = myPage.place(myFiles);
imageRef = placedItem [0];
rectRef = imageRef.parent;
gBounds = rectRef.geometricBounds;
rectRef.move([x0,yPos]);
rectRef.textWrapPreferences.textWrapMode =TextWrapModes.JUMP_OBJECT_TEXT_WRAP;
yPos = yPos + (gBounds[2]-gBounds[0] + yGap);
}
function getFile (filePrompt, typeFilter, useMultiple) {
var fileRef = File.openDialog(filePrompt, typeFilter, useMultiple);
if (fileRef==null) {
throw ("User cancelled");
} else {
return fileRef;
}
}
This should give you something to play with.
Copy link to clipboard
Copied
thanks, I was able to solve what I wanted
Copy link to clipboard
Copied
Hi Franz,
var AncFrame = app.documents[0].pages[0].textFrames.add();
AncFrame.place("ImagePath+ImageName");
AncFrame.textWrapPreferences.textWrapMode =TextWrapModes.jumpObjectTextWrap;