Copy link to clipboard
Copied
Is there any easy way to get the distance from the start of a paragraph or character to the edge of a cell?
HorizontalOffset gives you to the page edge, but I've been unable to find anything to I can get, or even calculate the distance to the cell's edge.
Thanks!
"Is there any easy way to get the distance from the start of a paragraph or character to the edge of a cell?"
Hi Ken,
not directly.
One could temporarily convert the cell to a graphic cell and work with the geometric bounds of the graphic frame inside the graphic frame. Or you could change the justification of the paragraph to left justified and work with the horizontal offset of the first insertion point, the cell's inset and any of the indents of the paragraph to evaluate the thing.
Here s
...Copy link to clipboard
Copied
You can adjust the cell inset with the table panel (but there are other ways to do it)
Copy link to clipboard
Copied
Is cell.width - cell.leftInset insufficient?
Copy link to clipboard
Copied
"Is there any easy way to get the distance from the start of a paragraph or character to the edge of a cell?"
Hi Ken,
not directly.
One could temporarily convert the cell to a graphic cell and work with the geometric bounds of the graphic frame inside the graphic frame. Or you could change the justification of the paragraph to left justified and work with the horizontal offset of the first insertion point, the cell's inset and any of the indents of the paragraph to evaluate the thing.
Here some code for my first idea where an insertion point is selected in a text cell:
// Insertion point selected inside a text cell:
var horizontalOffset = app.selection[0].horizontalOffset;
var cell = app.selection[0].parent;
cell.convertCellType( CellTypeEnum.GRAPHIC_TYPE_CELL );
var leftPosition = cell.pageItems[0].getElements()[0].geometricBounds[1];
var distance = horizontalOffset - leftPosition;
// One undo necessary:
app.documents[0].undo();
$.writeln( distance );
alert( distance );
Some notes:
The distance that is calculated is the distance from the edge of the left stroke of the cell to the insertion point selected.
So if you want to know the distance to the edge of the cell you have to calculate half of the cell's left stroke as well.
And of course other things apply if the text frame holding the cell is rotated or skewed. Also if the text in the text cell is rotated. Check cell.rotationAngle for that.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Uwe, I'd thought of the similar solution of anchoring a frame at the start of the cell and using it's position. I'm a little embarrassed to say I'd never come across the convertCellType or even known there was a such a thing as a graphic cell. Pretty cool, thanks!
I was looking to enhance a script we've been using for quite a while now that allows the user to modify a cell and run the script, which then runs through the rest of the column setting things to align with the cell they modified. Inserting the frame (and Uwe's brilliant conversion idea), though, would make the script run too slow for larger tables.
The script currently resets things and assumes a zero "starting position" which is only problematic for us in a handful of situations. But I think is still the best solution, at least for now.
Thanks again everyone!
Copy link to clipboard
Copied
Hi Ken,
let me also note that the value of horizontalOffset is not very precise if you want to get the position of the edge of a glyph. For that you need to convert a duplicate of the glyph to paths and check the path's properties like geometricBounds or visibleBounds.
character.createOutlines( false ) // Returns array of page items
Argument false does not remove the original character.
All in all there is no fast way, because what's missing from the DOM is something like the geometricBounds of a table cell. No idea, if this is available with C++ for example…
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Yes, exactaly, I first went looking for geometricBounds of a cell but didn't find it, so I can confirm it's not available in VB.
I thought I noticed that acuracy (or lack there-of) thing with the horizontalOffset, thanks for confirming I'm not seeing things. When I get back to it I'll likely try your conversion idea to get a more acurate indent number.
I can't simply look at the "model" cell's indent because one of the key aspects of the script is that the user can override and center a particular cell on the column. The script looks at the style and determines whether things are aligning left, right or decimal, then calculates what is necessary to align it with the "model" cell.
Thanks yet again!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now