Copy link to clipboard
Copied
Dear Experts,
is it possible to copy (with a script) the current X value from Info Panel so I will be able to paste it somewhere else?
MJ
Try this:
var sel = app.documents.item(0).selection[0];
var selp = sel.paragraphs[0];
var fli = selp.firstLineIndent;
var ho = sel.horizontalOffset;
var s = selp.parent.paragraphs;
var sa, so, np, li, fli;
for (var i = 0; i < s.length; i++){
if (s[i] == selp) {
//save the selected paragraph’s justification
sa = s[i].justification;
s[i].justification = Justification.LEFT_ALIGN;
so = selp.insertionPoints[0].horizontalOffset;
li = ho - so;
//
...
Right try this:
//insertion point
var sel = app.documents.item(0).selection[0];
//insertion point’s paragraph
var selp = sel.paragraphs[0];
//insertion point’s h offset
var ho = sel.horizontalOffset;
//get the selected paragraph’s starting x
var sa = selp.justification
var fli = selp.firstLineIndent;
var li = selp.leftIndent
selp.justification = Justification.LEFT_ALIGN;
selp.firstLineIndent = 0;
selp.leftIndent = 0
var so = selp.insertionPoints[0].horizontalOffset;
//the insertion point re
...
Copy link to clipboard
Copied
The horizontal position of the insertion point?
alert( app.selection[0].horizontalOffset - app.selection[0].parentTextFrames[0].geometricBounds[1] );
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thank you but I need the current position of a cursor in a text (paragraph). And I need this position to be copied to the clipboard. The vertical line on a picture in my first post is a position of a text cursor.
Copy link to clipboard
Copied
I’m not sure if there is an easy way to set the clipboard to a returned value with ExtendScript, but AppleScript has a clipboard object, so this might work if you are using OSX:
tell application id "com.adobe.indesign"
set px to item 2 of geometric bounds of item 1 of parent text frames of selection
set x to (horizontal offset of selection) - px
set the clipboard to {text:(x as string)}
end tell
You would have to watchout for a rotation or shear of the parent text frame—the x value in Info is realtive to the parent frame, but the horizontal offset of the selection is relative to the page, so the script would need to temporarily set the rotation and shear to 0.
Copy link to clipboard
Copied
Also a value for the exact position could be calculated where rotation or shear will be part of it.
What I wonder, sunny.sunny: Do you like to get the left-most position of the glyph right to the text insertion point?
Perhaps to align another object to that position?
That would be a position that is a tiny bit different to the position of the glyph insertion point, because the insertion point between two characters is exactly at the position where the left glyph's side bearing ends and the right side bearing of the next glyph starts.
Regards,
Uwe Laubender
( ACP )
// Sorry. Had to edit my post.
Copy link to clipboard
Copied
May be following will help.
1. Creating the temporary textframe
2. Set content of the temporary textframe with the selected X value
3. Select the content of the temporary textframe
4. Executing copy menu action. This will copy the content to the clipboard.
if (app.selection[0]) {
var value = app.selection[0].horizontalOffset - app.selection[0].parentTextFrames[0].geometricBounds[1];
var _tempTextFrame = app.activeDocument.textFrames.add();
_tempTextFrame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH_PROPORTIONALLY;
_tempTextFrame.contents = value.toString();
app.selection = null;
app.activeDocument.select(_tempTextFrame.paragraphs[0]);
app.menuActions.itemByID(270).invoke();
_tempTextFrame.remove();
}
Copy link to clipboard
Copied
@rob day Thank you very much for your answer but I'm using Windows 10 so I cannot test your solution.
@Laubender I thought it would be very easy to "extract" this value from the Info panel with just one script line but I see now it is quite complicated. That is why I didn't write that everything is in tables. Very sorry for that! In an attachment I've marked what needs to be done. I have 1000+ tables with similar alignments but the text isn't exactly the same in each table. I know it can be done with tabs or with manual alignment but either way I need to know the X value.
@Charu Rajput Your solution is very good and works great for text frames but I didn't mention that everything is in tables. Sorry! Is there a solution for that?
All I need is to tell InDesign to align the second line to the insertion point in the first line:
Copy link to clipboard
Copied
Try this—sets the fist line indent of the next paragraph to the cursor position:
var ip = app.documents.item(0).selection[0].paragraphs[0];
var fli = app.selection[0].horizontalOffset - ip.insertionPoints[0].horizontalOffset
var s = ip.parent.paragraphs
var np;
for (var i = 0; i < s.length; i++){
if (s[i] == ip) {
np = s[i+1]
}
};
np.firstLineIndent = fli;
Copy link to clipboard
Copied
Thank you, thank you, thank you! It works excellent.
Copy link to clipboard
Copied
@rob day I have to add that your solution works 100% (in my case is more than enough) when all text is aligned left as your script takes distance from the first glyph in line 1. Things are getting complicated when line 1 is centered, aligned right, or isn't exactly 0 mm from the left side of a text frame. Is there any simple solution for that?
Copy link to clipboard
Copied
Try this:
var sel = app.documents.item(0).selection[0];
var selp = sel.paragraphs[0];
var fli = selp.firstLineIndent;
var ho = sel.horizontalOffset;
var s = selp.parent.paragraphs;
var sa, so, np, li, fli;
for (var i = 0; i < s.length; i++){
if (s[i] == selp) {
//save the selected paragraph’s justification
sa = s[i].justification;
s[i].justification = Justification.LEFT_ALIGN;
so = selp.insertionPoints[0].horizontalOffset;
li = ho - so;
//reset
s[i].justification = sa;
np = s[i+1]
}
};
np.justification = Justification.LEFT_ALIGN
np.firstLineIndent = fli;
np.leftIndent = li + selp.leftIndent;
Copy link to clipboard
Copied
This is absolutely outstanding! Thanks a million.
Copy link to clipboard
Copied
So now I wonder if there is really no way to copy the horizontal position of the insertion point? Where is it stored when displayed in the Info panel? Maybe I can scan memory and write some simple app to get that value out of memory? Do you have any idea where to start?
Copy link to clipboard
Copied
With javaScript you would have to create a temporary text frame as @Charu Rajput suggested:
var sel = app.documents.item(0).selection[0];
var x = sel.horizontalOffset-sel.paragraphs[0].insertionPoints[0].horizontalOffset
var tf = app.activeDocument.textFrames.add();
tf.contents = x.toString();
app.select([tf.parentStory.texts[0]]);
app.copy();
tf.remove();
app.select(sel);
Copy link to clipboard
Copied
Thank you very much. Script by Charu Rajput doesn't work in tables. But your does!
Copy link to clipboard
Copied
I didn't check everything but thanks for your support.
For example, when text is centred, the value is measured from the first glyph, not from position 0 mm of a text frame. After running your script I get 28.8480614980062 but it should be 62.424 mm:
Copy link to clipboard
Copied
Right try this:
//insertion point
var sel = app.documents.item(0).selection[0];
//insertion point’s paragraph
var selp = sel.paragraphs[0];
//insertion point’s h offset
var ho = sel.horizontalOffset;
//get the selected paragraph’s starting x
var sa = selp.justification
var fli = selp.firstLineIndent;
var li = selp.leftIndent
selp.justification = Justification.LEFT_ALIGN;
selp.firstLineIndent = 0;
selp.leftIndent = 0
var so = selp.insertionPoints[0].horizontalOffset;
//the insertion point relative to the container (InDesign’s Info Panel X)
var x = ho-so;
//reset
selp.justification = sa;
selp.firstLineIndent = fli;
selp.leftIndent = li
//copy x to the clipboard
var tf = app.activeDocument.textFrames.add();
tf.contents = x.toString();
app.select([tf.parentStory.texts[0]]);
app.copy();
tf.remove();
app.select(sel);
Copy link to clipboard
Copied
Excellent, thank you very much!