Message Boards Message Boards

0
|
2333 Views
|
5 Replies
|
8 Total Likes
View groups...
Share
Share this post:

How to reset symbol options to their defaults?

Posted 1 year ago

As an example I use Graphics3D:

Graphics3D[Cone[]]

enter image description here

If I set some options for following function calls:

SetOptions[Graphics3D, Axes -> True, AxesLabel -> {x, y, z}, FaceGrids -> All,
   Background -> Lighter[Gray, 0.9], ImageSize -> Small];
Graphics3D[Cone[]]

enter image description here

... How can I return to the default options later?

Do I really have to set every single option again, to its default value? Then I have to know all those defaults:

SetOptions[Graphics3D, Axes -> False, AxesLabel -> None, FaceGrids -> None, 
  Background -> None, ImageSize -> Automatic];
Graphics3D[Cone[]]

enter image description here

Or is there a way to reset all options to default values for each symbol? Of course, without knowing the default values.

POSTED BY: Werner Geiger
5 Replies
Posted 1 year ago

Thanks Hans, this methods seems even better than SetOptions since it doesn't affect all Graphics3D but only those where the sequence is explicitly used.

POSTED BY: Werner Geiger
Posted 1 year ago

Thanks Henrik & Eric, this solutions do exactly what I asked for.

POSTED BY: Werner Geiger
Posted 1 year ago

Another approach is to collect your custom option values in a named Sequence

myGraphics3DOptions=Sequence[
  Axes->True,AxesLabel->{x,y,z},FaceGrids->All,Background->Lighter[Gray,0.9],ImageSize->Small
];

Graphics3D[Cone[], myGraphics3DOptions]
POSTED BY: Hans Milton
Posted 1 year ago
DefaultValues[Graphics3D]

Will give you all default values, including options. You can just extract the default options, but a safer way might be like this:

Lookup[DefaultValues[Graphics3D], HoldPattern[Options[Graphics3D]]]

So, resetting to defaults could look something like this:

SetOptions[Graphics3D, Lookup[DefaultValues[Graphics3D], HoldPattern[Options[Graphics3D]]]]

You could also save the options in a variable before you set your own values, and then you'd reset them back to what you saved when you're done.

POSTED BY: Eric Rimbey

Werner,

I would simply save the respective original options at the beginning, i.e. doing it like so:

origGrOpts = AbsoluteOptions[Graphics3D[]];
Graphics3D[Cone[]]
SetOptions[Graphics3D, Axes -> True, AxesLabel -> {x, y, z}, FaceGrids -> All, Background -> Lighter[Gray, 0.9], ImageSize -> Small];
Graphics3D[Cone[]]
SetOptions[Graphics3D, origGrOpts];
Graphics3D[Cone[]]
POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract