To Acquire the Date and Time, as of now I need to hit the button to show the time, is it possible to have the time run live so I don’t need to hit the button to update?
If you didn’t get what you really need by then, ask me on Tuesday here (when I’m back at my office)
I’ve got a small c# component that does just that and refreshes on its own.
I think you want to call expire solution with a time step…
reference code here
It was something like this :
private void RunScript(ref object D, ref object Y, ref object M, ref object D, ref object h, ref object m, ref object s)
{
now = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
String[] dateList = now.Split((char) 32);
string YMD = dateList[0];
string hms = dateList[1];
String[] YMDList = YMD.Split((char) 47);
String[] hmsList = hms.Split((char) 58);
Date = now;
Y = YMDList[2];
M = YMDList[0];
D = YMDList[1];
h = hmsList[0];
m = hmsList[1];
s = hmsList[2];
GrasshopperDocument.ScheduleSolution(1000, ScheduleSolutionCallback);
}
// <Custom additional code>
string now;
public void ScheduleSolutionCallback(GH_Document doc)
{
this.Component.ExpireSolution(false);
}
// </Custom additional code>
}
date_NOW.gh (5.7 KB)
Keep in mind that every second, Grasshopper thinks you’ve modified the definition.
You’ll pretty much have the small " * " on the top left, next to the name of your file
I use a small Python script for that. It’s literally one line and you can output any format you like:
Just go to the cheat sheet for the strftime function for Python and you can assemble any date you like.
Then you either leave it without a trigger and it will update on every recompute (good for example for automatic file names) or you attach a trigger.
date-with-format.gh (5.1 KB)
Interesting !
Here would be a version without the trigger
I’ve also added a “expire” input in case you want to stop the refresh (default is True)
from datetime import datetime
def schedule_solution_callback(doc):
ghenv.Component.ExpireSolution(False)
if e == None:
e = True
doc = ghenv.Component.OnPingDocument()
d = datetime.now().strftime(f)
if e:
doc.ScheduleSolution(1000, schedule_solution_callback)
date-with-format.gh (5.7 KB)
Awesome thanks. I’ll replace it in my growing collection of user objects with this updated version
I didn’t knew you can format in the tostring method. Nice!