Get Time Zone

Hi

I’m trying to work out the best way to get the time zone from a file. There is the calculateTimeZone method which relies on sun settings. But the SunSettings.Current node sometime fails becuase presumably the user is in a view with no sun settings (not sure if this is possible but it does fail).

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variable.
sunSettings = IN[0]

timeZone = sunSettings.InternalElement.TimeZone
DST = sunSettings.InternalElement.UsesDST

#Assign your output to the OUT variable
OUT = timeZone, DST

The other way appears to be the TimeZone Property which is after a city. Is this a more robust way of obtaining the time zone and if so, what is the best way to get it?

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import python library
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
import shutil
import math
import collections
# Import math library
from math import *

#Import Data and Time
from datetime import datetime
now = datetime.now()

#Import System Library
import System
from System.Collections.Generic import *
from System.IO import Directory, Path

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

site = doc.SiteLocation
angleRatio = math.pi / 180;   

prompt = "Current project's Site location information:"
prompt += "\n\t" + "Latitude: " + str(site.Latitude / angleRatio) + "°"
prompt += "\n\t" + "Longitude: " + str(site.Longitude / angleRatio) + "°"
prompt += "\n\t" + "TimeZone: " + "(UTC%s)" % (str(site.TimeZone));

OUT = prompt


image
is this what you are looking for?

2 Likes

thanks. I end up simplifying as follows:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager


doc = DocumentManager.Instance.CurrentDBDocument
site = doc.SiteLocation.TimeZone

OUT = site
1 Like