Hi, every body.
I have been trying to produce shadow of an entity with Ruby API.
But, I noticed that sunrise time got with Ruby script is a little different from Sketchup application.
For example, with the same sketchup entity, I got sunrise is 6:59 in the interface of Sketchup application and 7:00 by script based Ruby API.
Would somebody do me a favor?
Thanks.
The follows are the code:
#get model representing the Sketchup file
model = Sketchup.active_model
#get view the user are facing
view = model.active_view
#get shadow information
shadow =model.shadow_info
#City of the model
puts "My city is: " + shadow[“City”].to_s
#shadows ON
shadow[“DisplayShadows”] = true
#shadows on Faces are ON
shadow[“DisplayOnAllFaces”] = true
#shadows on Ground are ON
shadow[“DisplayOnGroundPlane”] = true
#first day to produce images is initialized with 5th Apr 2016 as a sample
firstDay = Date.new(2016,4,5)
#last day to produce images is initialized with 15th Apr 2016 as a sample
lastDay = Date.new(2016,4,15)
#get the timeZone(measured by second) to eliminate the effect by the local time
timeZoneOffsetInSecond = firstDay.to_time.utc_offset
#this showTime is just to calculate the time of sunrise instead of producing the shadow image
#this time is adjusted by the time zone(timeZoneOffsetInSecond)
shadowTimeForSunrise = Time.new(currentDay.year,currentDay.month,currentDay.day,0,0,0)
+ timeZoneOffsetInSecond
#set the shadow time
shadow[“ShadowTime”] = shadowTimeForSunrise
#get the sun rise time
sunRise = shadow[‘SunRise’] - timeZoneOffsetInSecond
#get the sun set time
sunSet = shadow[‘SunSet’] - timeZoneOffsetInSecond
sunRiseHour = sunRise.hour
sunRiseMin = sunRise.min
sunSetHour = sunSet.hour
sunSetMin = sunSet.min
puts “sunRiseHour=#{sunRise.hour},min=#{sunRiseMin},sunSetHour=#{sunSet.hour},sunSetMin=#{sunSetMin}”
`