Forum Replies Created
-
AuthorPosts
-
August 28, 2010 at 12:20 pm in reply to: Define table row heights, column widths in styles somehow? #56862
Theunis De Jong
MemberA small addendum: the Name_Script stuff does not play nice with decimal points in your value. Change line #4 to this to solve it:
newHeight = app.activeScript.name.split('_')[2].split('.jsx')[0];
August 28, 2010 at 12:14 pm in reply to: Define table row heights, column widths in styles somehow? #56860Theunis De Jong
MemberThis is super-fancy if you need several variants. Save this script as “Resize_Cell Style Name_New Size.jsx”, and it'll pick up the variables from the script name :) (For instance, “Resize_Yellow Cells_10mm.jsx”.)
if (app.activeScript.name.match(/_/g).length == 2)
{
cellStyleName = app.activeScript.name.split('_')[1];
newHeight = app.activeScript.name.split('_')[2].split('.')[0];
if (app.activeDocument.cellStyles.item(cellStyleName).isValid)
app.doScript (sizeRows, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, “Undo Resize Height of “+cellStyleName);
else
alert ('There is no Cell Style named “'+cellStyleName+'”');
} else
alert ('The name “'+app.activeScript.name+'” should be in the format “Resize_CellStyleName_Height.jsx”!');
function sizeRows ()
{
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == cellStyleName)
cellarray[a].height = newHeight;
}August 28, 2010 at 12:03 pm in reply to: Define table row heights, column widths in styles somehow? #56859Theunis De Jong
Member(Achh! Reply was to previous replay ;))
Yes, I suspect writing it as one single AS command allows you to Undo it at once. However, Me ≠ AppleScript.
There is also a way to encapsulate an entire Javascript into one “undo” command — hold on while I look up how that was done.
(.. insert elevator muzak here ..)
There we go:
cellStyleName = “myCellStyle”;
newHeight = “12mm”;app.doScript (sizeRows, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, 'Undo Resize Height of “'+cellStyleName+'”');
function sizeRows ()
{
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == cellStyleName)
cellarray[a].height = newHeight;
}August 28, 2010 at 11:47 am in reply to: Define table row heights, column widths in styles somehow? #56857Theunis De Jong
MemberThat's strange — I can't get it not to work (locked story, locked layer, header rows …). There must be Something Unexpected™ in your tables.
Can you try this? It counts the number of changes made.
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
changed = 0;
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == “myCellStyle”) <- Cell Style Name
cellarray[a].height = “12mm”, changed++;
alert (changed+” change(s) made”);August 28, 2010 at 10:23 am in reply to: Define table row heights, column widths in styles somehow? #56855Theunis De Jong
MemberJavascript is missing a construct that is available in Applescript: the whose command. whose selects from an array only the elements that have a certain value. Since you don't want to apply your change to every cell, which is what everyItem selects, you'll have to get 'everything', then loop over the result, applying your height only to cells with the right name.
This seems to work (since it's no longer a single command, Undo undoes it one at a time):
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == “myCellStyle”) // <- Cell Style Name!
cellarray[a].height = “12mm”;August 28, 2010 at 8:57 am in reply to: Define table row heights, column widths in styles somehow? #52835Theunis De Jong
Member.. but but but .. I added the message there to warn there is no Cell Style named “myCellStyle” in your document!
You are supposed to use the correct cell style name in the script name. If you name the script “Resize_SomeTotallyRandomNameHere_5mm.jsx”, it'll try to use “SomeTotallyRandomNameHere” for a Cell Style name — and if you don't have that style, it'll warn you and don't do anything at all.
August 28, 2010 at 5:20 am in reply to: Define table row heights, column widths in styles somehow? #52833Theunis De Jong
MemberA small addendum: the Name_Script stuff does not play nice with decimal points in your value. Change line #4 to this to solve it:
newHeight = app.activeScript.name.split('_')[2].split('.jsx')[0];
August 28, 2010 at 5:14 am in reply to: Define table row heights, column widths in styles somehow? #52831Theunis De Jong
MemberThis is super-fancy if you need several variants. Save this script as “Resize_Cell Style Name_New Size.jsx”, and it'll pick up the variables from the script name :) (For instance, “Resize_Yellow Cells_10mm.jsx”.)
if (app.activeScript.name.match(/_/g).length == 2)
{
cellStyleName = app.activeScript.name.split('_')[1];
newHeight = app.activeScript.name.split('_')[2].split('.')[0];
if (app.activeDocument.cellStyles.item(cellStyleName).isValid)
app.doScript (sizeRows, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, “Undo Resize Height of “+cellStyleName);
else
alert ('There is no Cell Style named “'+cellStyleName+'”');
} else
alert ('The name “'+app.activeScript.name+'” should be in the format “Resize_CellStyleName_Height.jsx”!');
function sizeRows ()
{
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == cellStyleName)
cellarray[a].height = newHeight;
}August 28, 2010 at 5:03 am in reply to: Define table row heights, column widths in styles somehow? #52830Theunis De Jong
Member(Achh! Reply was to previous replay ;))
Yes, I suspect writing it as one single AS command allows you to Undo it at once. However, Me ≠ AppleScript.
There is also a way to encapsulate an entire Javascript into one “undo” command — hold on while I look up how that was done.
(.. insert elevator muzak here ..)
There we go:
cellStyleName = “myCellStyle”;
newHeight = “12mm”;app.doScript (sizeRows, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, 'Undo Resize Height of “'+cellStyleName+'”');
function sizeRows ()
{
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == cellStyleName)
cellarray[a].height = newHeight;
}August 28, 2010 at 4:47 am in reply to: Define table row heights, column widths in styles somehow? #52828Theunis De Jong
MemberThat's strange — I can't get it not to work (locked story, locked layer, header rows …). There must be Something Unexpected™ in your tables.
Can you try this? It counts the number of changes made.
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
changed = 0;
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == “myCellStyle”) <- Cell Style Name
cellarray[a].height = “12mm”, changed++;
alert (changed+” change(s) made”);August 28, 2010 at 3:23 am in reply to: Define table row heights, column widths in styles somehow? #52826Theunis De Jong
MemberJavascript is missing a construct that is available in Applescript: the whose command. whose selects from an array only the elements that have a certain value. Since you don't want to apply your change to every cell, which is what everyItem selects, you'll have to get 'everything', then loop over the result, applying your height only to cells with the right name.
This seems to work (since it's no longer a single command, Undo undoes it one at a time):
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == “myCellStyle”) // <- Cell Style Name!
cellarray[a].height = “12mm”;Theunis De Jong
MemberTables run onto the next frame (= page, usually) just like normal text does. So if you import a large number of rows and place it into one frame, you'll get the red “There Is More” plus marker at the bottom right of the frame, and you can add pages and have the text flow continue in the usual way.
Theunis De Jong
MemberI think you just described the difference between the Easy Way and the Right Way …
Theunis De Jong
MemberWouldn't it be easiest to add a new column in Excel and designate it a 'unique key' field? (I faintly remember something like that ought to be possible.)
Theunis De Jong
MemberIf you select just that character you can see its Unicode in the Info Panel.
I'm betting it's an U+FEFF, a reserved value according to Unicode, and so it was safe for Adobe's engineers to put it to other uses (since it's not allowed as a character code). The U+FEFF code is visible on screen, but since it's usually a very specialized marker for more data, you are usually not allowed to copy it.
If it is U+FEFF, you are not yet done :) Strangely, GREP does not allow you to search for it the usual way, using
x{ffef}— which ought to have worked! It's rather strange because you can find it just fine with regular Find Text, using the notation
<feff>A curiosity: this same code is used for XML tags and for Index Markers. You cannot replace XML tags (they simply won't budge), but removing Index Markers works fine.
(Another curiosity, proving the “special status” of this code: the special codes ^I (Text) and ~I (GREP) will find Index Markers but skip other occurrences of U+FEFF.)
-
AuthorPosts
