Hallo zusammen,
ich hab' mich noch mal rangesetzt und eine Lösung für Transformationen wie Drehen und Scheren erarbeitet.
Diesmal gibt das Skript keine geometricBounds aus, sondern eine rechteckige Form, die dieselben Transformationen aufweist wie der Textrahmen der Tabelle.
Was nicht einberechnet ist, sind die Zellenkonturen.
Die erzeugte Form entspricht also der Form, die beim Erzeugen einer Grafikzelle entsteht, bereinigt in eine Rechteckfrom.
Weshalb ist eine Bereinigung notwendig?
Bei gedrehten und gescherten Textrahmen gibt es einen Bug mit der Konvertierung von Textzellen zu Grafikzellen.
Da wird nämlich ein seltsames Polygon erzeugt und kein Rechteckrahmen, der den Flächeninhalt der Zelle abbildet.
Hier nun der Code, getestet mit InDesign 2022 auf Windows 10:
/**
* @@@BUILDINFO@@@ 220801-1-Return-TRANSFORMED-ShapeOfCell-Function()-SELECTION.jsx !Version! Mon Aug 01 2022 11:36:43 GMT+0200
*/
/*
Code by Uwe Laubender
RETURN TRANSFORMED SHAPE OF CELL:
Returns
Polygon of shape of cell, could be transformed if table is transformed
POSSIBLE ISSUES:
A graphic cell contains a form field or a group object.
TESTED OK WITH:
InDesign 2022 on Windows 10
*/
/*
Discussed suggestion at HDS:
Koordinaten einer Tabellenzelle
Gerald Singelmann
23. Jul 2022, 09:47
https://www.hilfdirselbst.ch/gforum/gforum.cgi?post=583998#583998
FORMER ISSUES:
Table transformed: rotated, sheared, rotated & sheared.
Is resolved with this version.
STILL NOT SOLVED:
Stroke weights are not calculated.
Apecial issue with that: Adjacent cells with different stroke weights.
SOLUTION BASED ON THIS IDEA:
Do a duplicate of the object of a graphic cell.
Move it back to the original position.
Convert shape to rectangle.
*/
tableCell = app.selection[0];
var shapeObject = returnTRANSFORMEDShapeOfCell( tableCell );
shapeObject.properties =
{
strokeWeight : 0 ,
strokeColor : "None" ,
fillColor : "Yellow"
};
/*
returnTRANSFORMEDShapeOfCell( cell )
Returns polygon of shape of cell, could be transformed if table is transformed.
Does not return the exact shape, because the cell strokes are not calculated.
*/
function returnTRANSFORMEDShapeOfCell( cell )
{
var autoGrow = cell.autoGrow ;
cell.autoGrow = false ;
if( cell.cellType == CellTypeEnum.GRAPHIC_TYPE_CELL )
{
var originalPosition = cell.pageItems[0].paths[0].pathPoints[0].anchor;
var dup = cell.pageItems[0].duplicate();
var dupPosition = dup.paths[0].pathPoints[0].anchor;
dup.pageItems.everyItem().remove();
dup.move( undefined , [ ( originalPosition[0] - dupPosition[0] ) , ( originalPosition[1] - dupPosition[1] ) ] );
dup.convertShape( ConvertShapeOptions.CONVERT_TO_RECTANGLE );
cell.autoGrow = autoGrow;
return dup ;
};
if( cell.cellType == CellTypeEnum.TEXT_TYPE_CELL )
{
var tmpTextFrame = app.documents[0].textFrames.add();
cell.texts[0].move( LocationOptions.AT_BEGINNING , tmpTextFrame.parentStory );
cell.convertCellType( CellTypeEnum.GRAPHIC_TYPE_CELL );
cell.pageItems[0].convertShape( ConvertShapeOptions.CONVERT_TO_RECTANGLE );
var originalPosition = cell.pageItems[0].paths[0].pathPoints[0].anchor;
var dup = cell.pageItems[0].duplicate();
var dupPosition = dup.paths[0].pathPoints[0].anchor;
dup.move( undefined , [ ( originalPosition[0] - dupPosition[0] ) , ( originalPosition[1] - dupPosition[1] ) ] );
cell.convertCellType( CellTypeEnum.TEXT_TYPE_CELL );
tmpTextFrame.parentStory.texts[0].move( LocationOptions.AT_BEGINNING , cell.insertionPoints[0] );
cell.autoGrow = autoGrow ;
tmpTextFrame.remove();
return dup ;
}
}
Meine Testdatei ist diese hier:
https://www.dropbox.com/s/ku84998j6ptn4na/Get%20Shape%20of%20Cell-TestTable-2022.indd?dl=1
Mal sehen, vielleicht meldet sich auch
Marc Autret, der auf dieses Problem hier aufmerksam wurde.
Er hat sein Skript
TableCellBox.jsx auf Github eingestellt:
https://github.com/indiscripts/IdGoodies/blob/master/snip/TableCellBox.jsx
Danke, Marc!
Muss das gleich mal testen…