wernergg
(Werner Geiger)
January 16, 2023, 2:09pm
1
As an example I use Graphics3D:
Graphics3D[Cone[]]
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[]]
… 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[]]
Or is there a way to reset all options to default values for each symbol ? Of course, without knowing the default values.
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[]]
eric3
(Eric Rimbey)
January 16, 2023, 5:12pm
3
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.
hansmilton
(Hans Milton)
January 16, 2023, 5:35pm
4
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]
wernergg
(Werner Geiger)
January 16, 2023, 6:49pm
5
Thanks Henrik & Eric,
this solutions do exactly what I asked for.
wernergg
(Werner Geiger)
January 16, 2023, 6:51pm
6
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.