In my quest to a custom "Save as HTML" (please see context here) I am now able to iterate through the notebook, grab Input cells decorated with a CellTag that, by convention, is going to be a file name of a CDF file. The CDF needs to come from the corresponding Output cell if that Input cell. For simplicity, I am assuming it is the next one. So, I am trying to SelectionMove[nb, Next, Cell] (* 1 *) but my debugging in (* 2 *) doesn't work and the actual export in (* 3 *) fails. See below
PaletteNotebook[
Button[Style["Blog it", 12, FontFamily -> "Times"],
Block[{
nb = InputNotebook[],
out = NotebookCreate[],
fpath = NotebookDirectory[InputNotebook[]],
generateCDF,
generateCDFs,
exportHTML
},
generateCDF[nb_, name_] := Module[{sel},
sel = SelectionMove[nb, Next, Cell]; (* 1 *)
Message[generateCDF::info, name];
NotebookWrite[out, CurrentValue[{sel, Cell}]]; (* 2 *)
Export[
FileNameJoin[{fpath, name}],
CurrentValue[sel, Cell],
"CDF"]; (* 3 *)
SelectionMove[nb, "Input", Next, CellStyle]
];
generateCDF::info = "Generating CDF `1`";
generateCDFs[nb_] := Module[{sel, curID},
SelectionMove[nb, Before, Notebook];
sel = NotebookFind[nb, "Input", Next, CellStyle];
While[ MatchQ[sel, _NotebookSelection],
curID = CurrentValue[sel, CellID];
sel = Switch[CurrentValue[sel, CellTags],
_String, generateCDF[nb, CurrentValue[sel, CellTags]],
_, NotebookFind[nb, "Input", Next, CellStyle]
];
];
];
exportHTML[nb_] := False; (* yet to be done, ignore for now *)
generateCDFs[nb];
exportHTML[nb];
],
Appearance -> "Palette"]
]
The Message is printing properly in the message window.
