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:

  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.

| improve this question | | | | |
  • $\begingroup$ Opening in Mathematica just gives the graphics with controls and buttons and no cells to edit. Using Import[] gives the same what I see in the text editor. $\endgroup$ – sebqas Jun 2 '14 at 8:42
  • $\begingroup$ You should not open CDF in text editor. You can easily corrupt it. As Kuba said, the code should still be in the CDF. You might have a cell set as closed and it needs to be opened that is all. If you put the CDF file somewhere, someone might be able to help better. $\endgroup$ – Nasser Jun 2 '14 at 15:42
  • $\begingroup$ Open the .cdf in Mathematica. Then "save as" in the notebook .nb format. Now read it back into Mathematica. If it is not immediately visible, select all then enter and the cell will open as it executes. $\endgroup$ – bill s Jun 2 '14 at 17:13
  • $\begingroup$ I did it at first, but the notebook look the same like pure CDF and has no cells to edit or to convert to anything. $\endgroup$ – sebqas Jun 3 '14 at 10:23
  • $\begingroup$ @Kuba but I have NO output cell when I open CDF file (or the notebook (*.nb) obtained by "save as" on the CDF) $\endgroup$ – sebqas Jun 3 '14 at 10:32

Edit with a more compact code:

CellPrint @ Cell[
    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]

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

SelectionMove[EvaluationNotebook[], All, CellContents]

| improve this answer | | | | |
  • 1
    $\begingroup$ +1 Nice. It should give the OP at least some of the code. Code that evaluated (e.g., outside of Dynamic) might be irrecoverable. $\endgroup$ – Michael E2 Jun 3 '14 at 11:29
  • $\begingroup$ @MichaelE2 Thanks and I agree. :) $\endgroup$ – Kuba Jun 3 '14 at 11:32
  • $\begingroup$ You are great! I got exactly what I wanted. All parts are exactly the same like in my lost notebook. Many thanks /Dzięki/ $\endgroup$ – sebqas Jun 3 '14 at 12:32
  • $\begingroup$ The "new answer" with the "more compact code" works as advertised! Thanks $\endgroup$ – Laryx Decidua Sep 25 '19 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.