Copy link to clipboard
Copied
I am rather new to ExtendScript, and working on a structured DITA FM document. In our tables, we use a background colour to highlight a specific type of information. Of course, this shading is contained only in the FM data, and is lost on roundtripping. For the <entry> elements of the cells that we want to be shaded, we have set the @outputclass=bgcolor.
Now, I am trying to use ExtendScript to locate the elements with the appropriate attribute, and then apply the custom shading. I can't figure out how to get the shading applied once I find the element. I am sure I am missing something really basic, but am completely stuck.
This is what I have so far...
// Remove existing shading modifications from cells…
var tbl = app.ActiveDoc.FirstTblInDoc
while (tbl.ObjectValid() ) {
var row, cell
row = tbl.FirstRowInTbl
while (row.ObjectValid() ) {
cell = row.FirstCellInRow
while (cell.ObjectValid() ) {
//changing the cell definition so that color properties are taken from table format }
cell.CellUseOverrideFill = false
cell.CellUseOverrideShading = false
cell = cell.NextCellInRow
}
row = row.NextRowInTbl
}
tbl = tbl.NextTblInDoc
};
// Get the document’s root element…
var elem = app.ActiveDoc.MainFlowInDoc.HighestLevelElement;
// Launch a function that walks the tree and shades the cell when appropriate…
walkTree(0, elem);
app.ActiveDoc.Redisplay ();
// A recursive function that walks the tree…
function walkTree(level, elem){
// Find elements where @outputclass has a value
var allAtts = elem.Attributes;
var AttVal = "";
var i = 0;
var attFound = false;
while( !attFound && i < allAtts.length ) {
if( allAtts.name == "outputclass" ) {
attFound = true;
if( allAtts.values.length > 0 ) {
AttVal = allAtts.values[0];
}
}
i++;
}
// For @outputclass=bgcolor, shade the cell
if AttVal == "bgcolor") { // THESE ARE THE FOUR LINES THAT DON'T WORK
this.cell.CellOverrideShading == app.ActiveDoc.GetNamedColor("Background");
this.cell.CellUseOverrideShading = true;
this.cell.CellOverrideFill = 100;
this.cell.CellUseOverrideFill = true;
}
level = level++;
var child = elem.FirstChildElement;
while (child.ObjectValid()) {
walkTree(level, child);
child = child.NextSiblingElement;
}
};
The script removes existing shading properly, but does not apply the new one. Does anyone have any suggestions?
...C
this.cell.CellOverrideShading == app.ActiveDoc.GetNamedColor("Background");
this.cell.CellUseOverrideShading = true;
this.cell.CellOverrideFill = 100;
this.cell.CellUseOverrideFill = true;
What does "this" refer to in the above code?
Instead of "this", try referring to the cells like this:
cell = elem.Object;
cell.CellOverrideShading = app.ActiveDoc.GetNamedColor("Background");
cell.CellUseOverrideShading = true;
cell.CellOverrideFill = 100;
cell.CellUseOverrideFi
...Copy link to clipboard
Copied
this.cell.CellOverrideShading == app.ActiveDoc.GetNamedColor("Background");
this.cell.CellUseOverrideShading = true;
this.cell.CellOverrideFill = 100;
this.cell.CellUseOverrideFill = true;
What does "this" refer to in the above code?
Instead of "this", try referring to the cells like this:
cell = elem.Object;
cell.CellOverrideShading = app.ActiveDoc.GetNamedColor("Background");
cell.CellUseOverrideShading = true;
cell.CellOverrideFill = 100;
cell.CellUseOverrideFill = true;
Also, the double equal sign is not correct on your first line.