What am I doing wrong

In the following code the scenes do not get the right date and time they always return the date the model shadow information has for date and time when running the script.

E.g. the model says 2020-10-01 12:30:00 +0200 then this time is always return for ShadowTime.

Some help would be very nice

# Get the model
model = Sketchup.active_model

# Get the pages for the active model
pages = model.pages

# Loop over the existing pages
while (pages.length > 0)

# Define the days per month
days_in_month = [31,28,31,30,31,30,31,31,30,31,30,31]

# Create the scenes - One for every day at noon
for month in 1..1
    for day in 1..days_in_month[month-1]
        date = DateTime.new(2020,month,day,14,00,00,"UTC+2")
        page = pages.add date.strftime("%Y-%m-%d %H:%M:%S %z")
        page.use_shadow_info = false
        page.shadow_info["ShadowTime"] = date
        page.shadow_info["DisplayShadows"] = true
        page.use_shadow_info = true
        puts page.shadow_info["ShadowTime"] , date.strftime("%Y-%m-%d %H:%M:%S %z")

I have found it :slight_smile:

Instead of DateTime I should have used Time.

1 Like

You likely need …

for month in 1..12

And it may be good to update each scene page after setting the new shadow info at the end of the loop …


If you really must delete all the pages …

pages.to_a.each {|page| pages.erase(page) }

… might be safer than a while loop.

But even the while can be used in modifier position to make a one-liner …

pages.erase(pages[0]) while pages.length > 0

P.S. - In Ruby parenthesis are not traditionally used around conditional expressions unless the order of evaluation must be controlled.

You are right, however that was for reasons of shortening the runtime for my trials. Anyways, I have solved the problem.