11

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.

Kuba
  • 136,707
  • 13
  • 279
  • 740
sebqas
  • 605
  • 4
  • 15
  • 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. – sebqas Jun 02 '14 at 08:42
  • 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. – Nasser Jun 02 '14 at 15:42
  • 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. – bill s Jun 02 '14 at 17:13
  • 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. – sebqas Jun 03 '14 at 10:23
  • @Kuba but I have NO output cell when I open CDF file (or the notebook (*.nb) obtained by "save as" on the CDF) – sebqas Jun 03 '14 at 10:32
  • @Kuba what you mean by a cell? the content I see is note editable (was an option: Deployed->True) not selectable, not copyable and I can do nothing about it. – sebqas Jun 03 '14 at 10:43
  • @sebqas You're right it's more complicated than I've thought. – Kuba Jun 03 '14 at 10:46

1 Answers1

14

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[]]
Kuba
  • 136,707
  • 13
  • 279
  • 740