Invalid key: 'DayOfYear'

I have code that works fine in SU 2025, but throws an error in SU 2026. Exact same sketchup model, same code. Has something changed?
(This is part of a script that batch exports scenes, activating various scenes with saved views & shadows before exporting an image file, then restoring at end.)

#<KeyError: Invalid key: 'DayOfYear'>
(my script):42:in `[]='
(my script)b:42:in `shadow_restore'

my code:

		def self.shadow_save
			model = Sketchup.active_model
			# save current shadow information for restore at end
			@orig_shadow_UseSunForAllShading  = model.shadow_info["UseSunForAllShading"]
			@orig_shadow_DisplayShadows = model.shadow_info["DisplayShadows"]
			@orig_shadow_dark = model.shadow_info["Dark"]
			@orig_shadow_light = model.shadow_info["Light"]
			@orig_shadow_DisplayOnGroundPlane  = model.shadow_info["DisplayOnGroundPlane"]
			@orig_shadow_DisplayOnAllFaces   = model.shadow_info["DisplayOnAllFaces"]
			@orig_shadow_ShadowTime = model.shadow_info["ShadowTime"]
			@orig_shadow_DayOfYear = model.shadow_info["DayOfYear"]
			@orig_shadow_TZOffset  = model.shadow_info["TZOffset"]
		end # def

		def self.shadow_restore
			model = Sketchup.active_model
			model.shadow_info["UseSunForAllShading"] = @orig_shadow_UseSunForAllShading
			model.shadow_info["DisplayShadows"] = @orig_shadow_DisplayShadows
			model.shadow_info["Dark"] = @orig_shadow_dark
			model.shadow_info["Light"] = @orig_shadow_light
			model.shadow_info["DisplayOnGroundPlane"] = @orig_shadow_DisplayOnGroundPlane
			model.shadow_info["DisplayOnAllFaces"] = @orig_shadow_DisplayOnAllFaces
			model.shadow_info["ShadowTime"] = @orig_shadow_ShadowTime
			model.shadow_info["DayOfYear"] = @orig_shadow_DayOfYear
			model.shadow_info["TZOffset"] = @orig_shadow_TZOffset
		end # def


Sketchup.active_model.shadow_info[“DayOfYear”]

works and returns an integer, BUT I assume it’s a “read only” key/value as when trying to set it with

Sketchup.active_model.shadow_info=("DayOfYear", 1)

fails with an error.

1 Like

Thanks, now I understand that ShadowTime saves the day so no need for DayOfYear

@orig_shadow_ShadowTime = Sketchup.active_model.shadow_info["ShadowTime"]
=> 2025-09-21 07:30:00 -0700
Sketchup.active_model.shadow_info["ShadowTime"] = @orig_shadow_ShadowTime
=> 2025-09-21 07:30:00 -0700

I guess error handling changed between SU 2025 & 2026 and previous calls to set DayOfYear were ignored.

Correct. See:

The API documentation should be revised to indicate which keys are read-only, IMO.


#<NoMethodError: undefined method `shadow_info=' for
 #<Sketchup::Model:0x000001672e9753b0>>

FYI, the API’s ShadowInfo class mixes in Ruby’s Enumerable module, which gives the API class a #to_h method producing a Ruby Hash object.

This can be leveraged to greatly simplify your saving and restoration methods.
Also using Ruby’s rescue keyword in modifier position can suppress any errors.

    # Save current shadow information to hash for restore at end.
    def self.shadow_save
      model = Sketchup.active_model
      @orig_shadow_info = model.shadow_info.to_h
    end # def

    # Restore shadow information from saved hash suppressing KeyErrors.
    def self.shadow_restore
      shadow_info = Sketchup.active_model.shadow_info
      @orig_shadow_info.each { |key, value|
        ( shadow_info[key]= value ) rescue nil
      }
    end # def
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.