We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
SketchName? (Read 428 times)
SketchName?
Nov 6th, 2007, 8:42pm
 
I notice the convenience method sketchPath();

I'm currently using:

String[] tmp = null;
tmp = sketchPath.split("/");
sketchName = tmp[tmp.length-1];

Which is okay, but seems rather hacky, particularly as it breaks on export App .

I'm basically trying to create sketchName appended paths, so that I don't have to keep dipping the sourceCode to make modifications.

Any ideas?

Re: SketchName?
Reply #1 - Nov 6th, 2007, 10:17pm
 
I think you can get the sketch name a touch easier with a single command: this.getClass().getName();

Unfortunately, within processing this will be Temporary_####_#### but exported things should have the correct name.
Re: SketchName?
Reply #2 - Nov 6th, 2007, 11:05pm
 
Thanks John,

Yes that simplifes things a little, but as you say doesn't overcome the problem of a Temporary_####_#### class name when executing from within the processing environment.

I'd like to overcome this constraint if at all possible and have the best of both worlds. (I guess I'm becoming lazy).

Re: SketchName?
Reply #3 - Nov 7th, 2007, 9:51am
 
Here's a workaround that I've come up with that combines both mine and John's approaches to the problem. It makes me a little nervous as it relies upon "Temporary" as remaining consistent throughout further builds of Processing.

Perhaps there is still a much easier way of doing this?


String sketchName() {

 String className = this.getClass().getName();
 int pos = className.indexOf("Temporary");

 if(pos>=0) {
   String[] tmp = null;
   tmp = sketchPath.split("/");
   return tmp[tmp.length-1];
 } else return className;
}
Page Index Toggle Pages: 1