11
$\begingroup$

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.

$\endgroup$
7
  • $\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
    Commented Jun 2, 2014 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
    Commented Jun 2, 2014 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
    Commented Jun 2, 2014 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
    Commented Jun 3, 2014 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
    Commented Jun 3, 2014 at 10:32

1 Answer 1

14
$\begingroup$

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[]]
$\endgroup$
4
  • 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
    Commented Jun 3, 2014 at 11:29
  • $\begingroup$ @MichaelE2 Thanks and I agree. :) $\endgroup$
    – Kuba
    Commented Jun 3, 2014 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
    Commented Jun 3, 2014 at 12:32
  • $\begingroup$ The "new answer" with the "more compact code" works as advertised! Thanks $\endgroup$ Commented Sep 25, 2019 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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