Skip to main content

notebooks - How can I recover the source code from cdf file?


by a mistake I have deleted the nb file by which the CDF was generated.


All required definitions were in one cell. If I remember the code looked like this:


Grid[{{Button[..],..}, 
Dynamic[ ParametricPlot[..,Initialization:>{functions definitions}]]]


and later I selected the output cell and saved the selection by: File > CDF Export > Standalone.


I can open the CDF in a text editor but it is highly unreadable and is difficult to extract all the math commands.



Answer



Edit with a more compact code:


CellPrint @ Cell[
BoxData[
StringReplace["$CellContext`" -> ""] @ ToString[
ToExpression @ Get[pathToYourCDF][[1, 1, 1, 1]]
, InputForm
]

]
, "Input"
]

Old answer:


Open your cdf in Mathematica. Then open new Notebook and evaluate:


Select[Notebooks[], ("DocumentType" /. NotebookInformation[#]) =="CDF" &
][[ 1]] // NotebookGet // NotebookWrite[EvaluationNotebook[], #[[ 1]]] &

SelectionMove[EvaluationNotebook[], Previous, CellContents]


NotebookApply[EvaluationNotebook[],
RowBox[{"InputForm", "[", "\[SelectionPlaceholder]", "]"}]]

SelectionMove[EvaluationNotebook[], All, CellContents]

SelectionEvaluate[EvaluationNotebook[]]

Comments