6
$\begingroup$

I can get the default colors for one figure (Cuboid), and then color another figure (Sphere), as here:

Graphics3D[
 {Cuboid[],
  Red, Sphere[]}
 ]

enter image description here

However, if I create the figures in the reverse order (Cuboid first, Sphere second), I need to "cancel" the color specification (from the sphere) so that the Cuboid is in its default colors. I've tried FaceForm[Automatic] and variations, but these do not work.

Of course I could always specify the order of rendering to place the colors last, or explicitly place colored objects in Lists, but that is a bit tedious for many of my figures.

$\endgroup$
4
  • 2
    $\begingroup$ Why don't you group the colour with the object? {Cuboid[], {Red, Sphere[]}}. $\endgroup$
    – Szabolcs
    Sep 30, 2019 at 18:47
  • $\begingroup$ @Szabolcs: Yes, I can do that (+1), but I generate some figures algorithmically, and it gets a bit complicated to do this (though not impossible). Is there really no way to "cancel" a previous color specification? By analogy, one can "cancel" a Dashing specification with Dashing[None]. $\endgroup$ Sep 30, 2019 at 18:53
  • 2
    $\begingroup$ I believe the default is White. $\endgroup$
    – Szabolcs
    Sep 30, 2019 at 19:01
  • $\begingroup$ @Szabolcs: Ah yes... helpful. I didn't think the default was White given the rendered colors. But this appears to work. (You can post this as a quick solution and I'll accept it.) $\endgroup$ Sep 30, 2019 at 19:04

1 Answer 1

9
$\begingroup$

Graphics directives only persist inside the List that they are defined in`. So, use extra lists to control where the directives are active:

Graphics3D[{{Red, Sphere[]}, Cuboid[]}]

enter image description here

Another possibility is to use Style wrappers:

Graphics3D[{Style[Sphere[], Red], Cuboid[]}]

same picture

Another possibility that is similar to your Dashing example is to use a rule :

Graphics3D[{Red, Sphere[], FrontFaceColor->White, Cuboid[]}]

same picture

In this case you can also just change the color back to white without a rule, e.g., Graphics3D[{Red, Sphere[], White, Cuboid[]}], but knowing about the rule possibility is useful.

You can examine what other rule possibilities there are by evaluating:

CurrentValue[{StyleDefinitions, "Graphics3D"}]

{CellMargins -> {{4, Inherited}, {Inherited, Inherited}}, CellGroupingRules -> "GraphicsGrouping", StripStyleOnPaste -> False, PageBreakWithin -> False, GeneratedCell -> True, CellAutoOverwrite -> True, ShowCellLabel -> False, DefaultFormatType -> DefaultOutputFormatType, ContextMenu -> {MenuItem["Cu&t Graphics Selection", "Cut"], MenuItem["&Copy Graphics Selection", "Copy"], MenuItem["&Paste into Graphic", FrontEnd`Paste[After]], Delimiter, MenuItem["&Drawing Tools", FrontEndExecute[{FrontEnd`NotebookOpen[ FrontEnd`FindFileOnPath["DrawingTools.nb", "PrivatePathsSystemResources"]]}]], MenuItem["&Get Coordinates", FrontEndExecute[FrontEnd`Select2DTool["GetCoordinates"]]], Delimiter, MenuItem["G&roup", "Group"], MenuItem["&Ungroup", "Ungroup"], Delimiter, MenuItem["Move to &Front", "MoveToFront"], MenuItem["Move to &Back", "MoveToBack"], MenuItem["Move For&ward", "MoveForward"], MenuItem["Move Bac&kward", "MoveBackward"]}, "AutoStyleOptionsHighlightMisspelledWords" -> False, LanguageCategory -> "NaturalLanguage", FormatType -> StandardForm, ShowStringCharacters -> False, NumberMarks -> False, CounterIncrements -> "Graphics", ImageMargins -> {{43, Inherited}, {Inherited, 0}}, Arrowheads -> 0.04, Dashing -> None, CapForm -> "Round", JoinForm -> "Round", LineColor -> GrayLevel[0], LineOpacity -> 1, EdgeColor -> GrayLevel[0], EdgeOpacity -> 1, EdgeThickness -> Absolute[0.5], EdgeDashing -> None, EdgeCapForm -> "Round", EdgeJoinForm -> "Round", FrontFaceColor -> GrayLevel1, FrontFaceGlowColor -> GrayLevel[0], FrontFaceSpecularColor -> GrayLevel[0], FrontFaceSpecularExponent -> 1.5, BackFaceColor -> GrayLevel[1], BackFaceGlowColor -> GrayLevel[0], BackFaceSpecularColor -> GrayLevel[0], BackFaceSpecularExponent -> 1.5, FrontFaceOpacity -> 1, BackFaceOpacity -> 1, GraphicsColor -> GrayLevel[0], PointSize -> Absolute[3], Thickness -> Absolute[0.5], Opacity -> 1, DrawEdges -> True, DrawFrontFaces -> True, DrawBackFaces -> True, StyleMenuListing -> None, FontFamily -> "Arial", FontSize -> 10, FontWeight -> "Plain", FontColor -> GrayLevel[0], FontOpacity -> 1}

$\endgroup$
2
  • $\begingroup$ @CarlWolf: Yes, I can do that (+1), but I generate some figures algorithmically, and it gets a bit complicated to do this (though not impossible). Is there really no way to "cancel" a previous color specification? By analogy, one can "cancel" a Dashing specification with Dashing[None]. I believe one can "cancel" a previous EdgeForm with EdgeForm[Automatic]. $\endgroup$ Sep 30, 2019 at 18:54
  • 1
    $\begingroup$ @DavidG.Stork See update. $\endgroup$
    – Carl Woll
    Sep 30, 2019 at 19:04

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.