I get an error in the Ruby console when I call this def styleswitch.
Can you help me solve this problem ?
Error
Error: #<NoMethodError: undefined method `shadow_info=' for #<Sketchup::Model:0x0000015b40a09910>
Did you mean? shadow_info>
[...] in `styleswitch'
[...] in `block in <module:MyPlugin>'
extension.rb
module MyPlugin
module Data
require 'sketchup.rb'
end
def self.styleswitch
style_wip = File.expand_path("_style_wip.style", File.dirname(__FILE__))
style_final = File.expand_path("_style_final.style", File.dirname(__FILE__))
styles = Sketchup.active_model.styles
shadow_info = Sketchup.active_model.shadow_info
if @style_now == style_wip
styles.add_style(style_final, true)
@style_now = style_final
shadow_info["DisplayShadows"] = true
shadow_info["Light"] = 50
shadow_info["Dark"] = 75
shadow_info["UseSunForAllShading"] = false
shadow_info["DisplayOnAllFaces"] = true
shadow_info["DisplayOnGroundPlane"] = true
shadow_info["EdgesCastShadows"] = false
else
styles.add_style(style_wip, true)
@style_now = style_wip
shadow_info["DisplayShadows"] = false
end
Sketchup.active_model.shadow_info = shadow_info
end
end
end
menu.rb
style_submenu = mymenu_menu.add_item("Style(s)") do
MyPlugin::Data::styleswitch
end
The reason is that File::expand_path is stupid. It is basically a dumb concatenation method that can result in erroneous non-existent paths. Therefore, it’s use is fragile.