Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a docked cell in a stylesheet (with shortcuts for editing the notebook). Is there an option I can set so that this cell is not displayed in CDF?

Edit Based on answer by @MikeHoneychurch and the reference provided, here is the code I ended up using. Note this code deploys a notebook to a CDF removing any docked cells and cells tagged with "delete me". It will also ensure that styles embedded in the notebook are copied over to the CDF. Further changes may be required if the notebook inherits a stylesheet (refer to answer and link provided by @MikeHoneychurch).

Button["Save as CDF",
 (*Get the directory/name of the current notebook and change the .nb to .cdf; use this as the default path for the deployed CDF*)
 tmp = EvaluationNotebook[];
 cdfDefaultName = NotebookFileName[EvaluationNotebook[]];
 cdfDefaultName = StringReplace[cdfDefaultName, ".nb" -> ".cdf"];
 cdfFileName = 
  SystemDialogInput["FileSave", {cdfDefaultName, {"CDF Files" -> {"*.cdf"}}}];
 (*Get a copy of the private stylesheet a.k.a child and delete the docked cell*)
 child = Options[tmp, StyleDefinitions];
 childstyles = Cases[child, Cell[StyleData[_, ___], __], \[Infinity]];
 modchildstyles = DeleteCases[childstyles, Rule[DockedCells, _], \[Infinity]];
 (*Remove specified cells from the notebook *)
 tmp1 = First@NotebookGet[EvaluationNotebook[]];
 tmp1 = tmp1 /. CellGroupData[{Cell[_, "Input", ___, CellTags -> "delete me", ___], ___}, ___] :> Sequence[];
 (*Deploy the CDF*)
 CDFDeploy[cdfFileName, Notebook[tmp1, StyleDefinitions -> 
    Notebook[modchildstyles, StyleDefinitions -> "PrivateStylesheetFormatting.nb"]]], 
 ImageSize -> 100, Method -> "Queued"]
share|improve this question
add comment

2 Answers

There are probably several ways of doing this but here is one way:

Button["Save as CDF",
 tmp = First@NotebookGet[EvaluationNotebook[]];
 tmp = tmp /. {Rule[DockedCells, _] :> Sequence[]};
 CDFDeploy["new.cdf", 
   Notebook[tmp],
   Method -> "Standalone",
   WindowSize -> All],
 ImageSize -> 100,
 Method -> "Queued"]

Run that button from within your notebook and you can save a CDF without the docked cell.

Edit

You probably want to remove this button from the resulting CDF too. A few ways to do this but on the fly I would just tag the cell and then remove that tagged cell from the stuff that gets saved to CDF:

Button["Save as CDF",
 tmp = First@NotebookGet[EvaluationNotebook[]];
 tmp = tmp /. {Rule[DockedCells, _] :> Sequence[]};
 tmp = tmp /. 
   CellGroupData[{Cell[_, "Input", ___, 
       CellTags -> "delete me", ___], ___}, ___] :> Sequence[];
 CDFDeploy["new.cdf", 
  Notebook[tmp], 
  Method -> "Standalone", 
  WindowSize -> All], 
ImageSize -> 100, 
Method -> "Queued"]

or

Button["Save as CDF",
 tmp = First@NotebookGet[EvaluationNotebook[]];
 tmp = tmp /. {Rule[DockedCells, _] :> Sequence[]};
 tmp = DeleteCases[tmp, 
   CellGroupData[{Cell[_, "Input", ___, 
      CellTags -> "delete me", ___], ___}, ___], \[Infinity]];
 CDFDeploy["new.cdf", 
  Notebook[tmp], 
  Method -> "Standalone", 
  WindowSize -> All], 
ImageSize -> 100, 
Method -> "Queued"]

etc.

Edit #2 (in response to your comment)

ref: here

Button["Save as CDF",
 tmp1 = First@NotebookGet[EvaluationNotebook[]];
 tmp1 = tmp1 /. 
   CellGroupData[{Cell[_, "Input", ___, 
       CellTags -> "delete me", ___], ___}, ___] :> Sequence[];
 stylesheet = 
  "/Applications/Mathematica.app/SystemFiles/FrontEnd/StyleSheets/\
Creative/NaturalColor.nb";
 nb = NotebookOpen[stylesheet, Visible -> False];
 tmp = NotebookGet[nb];
 NotebookClose[nb];
 tmp = DeleteCases[tmp, Rule[DockedCells, _], \[Infinity]];
 styles = Cases[tmp, Cell[StyleData[x_, y___], z__], \[Infinity]];
 CDFDeploy["new.cdf", 
  Notebook[tmp1, 
   StyleDefinitions -> 
    Notebook[styles, 
     StyleDefinitions -> "PrivateStylesheetFormatting.nb"]], 
  Method -> "Standalone", WindowSize -> All], ImageSize -> 100,
 Method -> "Queued"]

Here I have added some additional steps:

  1. Rather than algorithmically finding the stylesheet I have manually entered the path to the stylesheet you are using in your notebook.

  2. The docked cells are removed from those styles.

  3. The styles, sans docked cells, are added back to the notebook.

There are other things you can add, such as preserving other notebook options, but what is above seems to solve your specific problem.

share|improve this answer
    
Thank-you for help. For some reason, however, the styles in the stylesheet are not applied to the CDF "new.cdf" using the method you outlined. If instead I do: CDFDeploy["new.cdf", EvaluationNotebook[], Method -> "Standalone", WindowSize -> All]; the styles are applied to the CDF. Do you have any further ideas? –  MLD Sep 24 '12 at 1:20
    
Thanks again. I ended up using a combination of the code you provided and that in the link in order to use the embedded stylesheet. –  MLD Sep 24 '12 at 21:33
add comment

An alternative method (I just realised) is to define the docked cell for the Working Screen Environment only

Cell[StyleData["Notebook", "Working"],DockedCells->{cells}]

Change the screen environment to Presentation, Slideshow, Condensed or Printout using Format->Screen Environment and then deploy / save as CDF via menu. This method however will keep the docked cell in the CDF if the Working environment is deployed to CDF.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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