serzhj
(Serzhj)
November 14, 2019, 9:03am
1
I want to get the current time stamp constantly so that I can use it as suffix of a file name.
I added the following script in GhPython component, and it freezes once I click OK.
There is no such issue if I just run it as a normal Python script.
May I ask if this is related to the Python used in Grasshopper, and how to solve this issue?
import datetime
now = datetime.datetime.now()
while True:
…output = now.strftime(“%Y-%m-%d_%H-%M”)
Er … P is not my game but you are using a while loop (with no break/exit clause) meaning that you are trapped into a rabbit hole.
Hello,
Does your script work if you just assign the output without the while loop?
I believe you’ll need to avoid the loop and trigger the Python component somehow, such as connecting anything that changes when the model changes (instead of the Button below):
I’d start with this?
[date_time]
Oh, wait… Time is fixed to the moment you first put it on the canvas and doesn’t change. Kind of useless, isn’t it.
Here’s a Python thing; every time you push the button (or otherwise trigger the ‘x’ input?), the date/time updates:
import datetime
now = datetime.datetime.now()
Y = now.year
M = now.month
D = now.day
h = now.hour
m = now.minute
s = now.second
[date_time]
time_date_2019Jul8a.gh (5.5 KB)
time_date_2019Jul8a.gh
import datetime
now = datetime.datetime.now()
Y = now.year
M = now.month
D = now.day
h = now.hour
m = now.minute
s = now.second
1 Like
serzhj
(Serzhj)
November 15, 2019, 3:23am
5
Thank you, @Joseph_Oster .
Seems there is a little bit of manual work that is unavoidable…
Well, as I said, if you connect all the right outputs of the GH model to the Python input, the time will be updated any time it changes. For example:
loft_height_2019Nov15a.gh (28.4 KB)