Change Table Selected Cells to Red font
@frameexpert - Appreciate you looking at this. I have about 1/3 of what I need, but I'm over my head and hopefully, there is a simpler way.
What I want to do is take - https://community.adobe.com/t5/framemaker-discussions/script-to-change-red-text-to-black/td-p/15293234/page/2 and expand it to work with a table selection.
I also saw: https://community.adobe.com/t5/framemaker-discussions/iterate-all-tables-in-framemaker/m-p/10338583
I found a couple of supposedly decent scripts from a google search - first:
// Get the active document
var doc = app.ActiveDoc;
// Check if a table is selected
if (doc.SelectedTbl.ObjectValid()) {
var oTable = doc.SelectedTbl;
// Get the row and column information of the selection
var topRow = oTable.TopRowSelection;
var bottomRow = oTable.BottomRowSelection;
var leftCol = oTable.LeftColNum;
var rightCol = oTable.RightColNum;
// Iterate through the selected rows and columns to access individual cells
var currentRow = topRow;
while (currentRow.ObjectValid() && currentRow.RowNum <= bottomRow.RowNum) {
var currentCol = leftCol;
while (currentCol <= rightCol) {
// Get the current cell object (using currentRow.Cell[currentCol] if needed to be more efficient, but let's stick to the current API)
var oCell = currentRow.Cell(currentCol);
// Do something with the cell (e.g., get its contents, format it)
Alert("Row: " + currentRow.RowNum + ", Column: " + currentCol + ", Cell Content: " + oCell.FirstPgf.GetText());
currentCol++;
}
currentRow = currentRow.NextRowInTable; // Move to the next row in the table
}
} else {
Alert("No table selected. Please select a table or cells within a table and run the script again.");
}
Gives me an error that currentRow.Cell is not a valid function.
and
#target framemaker
var doc = app.ActiveDoc; // Get the active FrameMaker document
if (doc) {
// var table = doc.Tables.First(); // Get the first table in the document (adjust as needed)
var table = doc.SelectedTbl;
if (table) {
var cell = table.Cells.Item(1, 1); // Get the cell at row 1, column 1 (adjust row and column)
if (cell) {
var textRange = cell.TextRanges.First(); // Get the first text range within the cell
if (textRange) {
var charProps = new PropVals(); // Create a new PropVals object for character properties
var propVal = new PropVal();
// Set the color property
propVal.propType = Constants.FP_CharColor;
propVal.propValType = Constants.FV_Color;
propVal.propVal = Constants.FV_ColorRed; // Set to red (you can use other color constants or define custom colors)
charProps.push(propVal);
// Apply the character properties to the text range
doc.SetTextPropVals(textRange.beg, textRange.end, charProps);
}
}
}
}
Gives me an error that table.Cells.item(1, 1) is undefined.
From the linked thread, I think I need to do something like (based on the first Google script):
...
var oCell = currentRow.FirstCellInRow
if (leftCol > 1){
For i = 1 to leftCol-1 { \\ If leftCol = 2, run the loop once
oCell = oCell.NextCellinRow
}
\\ Do something with current cell.
}
\\ *****
But I think I have the for loop syntax incorrect, and I'm not sure if this is an overcomplicated approach.
Thanks in advance!
