Template.pde variables?

Are there any date/time variables available to use in a sketch.pde template so new files will have the current date inside them when a new sketch is created?

I’m referring to the idea of creating a template as shown in https://github.com/processing/processing/wiki/Templates

1 Like

What do you mean? Something like this :

//***Date:10/10/19***//
//SketchName:“NewSketch“//
//Template:“SimpleTemplate“//

void setup() {

}

void draw() {

}

For that you‘d need to have a way to convert a part of the text into a variable text… which i don‘t think is possible, or even really feasable, since that should only be a Text file, and nothing more…

But there is a way! You just need to override the way a template is inserted! Or in other words, look for the class that takes care of the initialization of the TextArea in a new Sketch. Now find the method that looks for available templates!

Now add in a method that reads the template and looks for a text that starts with what you decide to be a marker, like „<%variable„ and read that until it ends with „%variable/>“.

So the Template would look like this :

//The current Date is : <%variable String date = str(month())+str(day())+str(year());%variable/> //
//SketchName : //
//TemplateName : //

Now, how you get this String, i have no idea, but i‘ll take a look at that later on… Anyway, once you got that String, you just interfere in the template text, and replace the <%var…%var…/> with the result of your codesnippet, in this case the current date…

Note that this is not really worth the effort… Also, there might actually be a simpler way, but i don‘t know of it, so that‘s the best i could do to help you.

Edit :
Since you only want to get the Date, you can probably get away with adding this where the template is added into the TextArea :

TextArea.append(„\//Date: „ + str(month()) + str(day()) + str(year()) + „\//„);

Although that only works if the template isn‘t added with a .set method… then you‘ll need to insert the Date text.

1 Like

Interesting… I agree though, probably not worth the effort

I’ve never seen a quote mark on the floor like this, is that a thing these days? :thinking:

No, technically it would be this „Hello“, but since i used spaces the last quote went down too :sweat_smile: It‘s just a normal Quote written on the IPhone.