View Full Version : Hello World :)


Lasse
12-13-2004, 07:38 AM
im reading the adobe photoshop scripting guide right now. Just made the hello world test, the first example and discovered that java is case sensive!! im going to use plent of hours correcting case letters i think :lmao:

But on to the question:

This is what i wrote: var originaiUnit = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.INCHES;

var docRef = app.documents.add( 4, 2, 72, "Hello, World!");

var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;

var textItemRef = artLayerRef.textItem;
textItemRef.contents = "Hello, World!";

docRef = null;
artLayerRef = null;
textItemRef = null;

app.preferences.rulerUnits = originalUnit; and then it tells me the last lines originalunit is undefined..? dosent it say that when the casething is wrong or is just an error message for dont know what your writing there :)?

v.bampton
12-13-2004, 08:02 AM
I know nothing, but it looks to me like a spelling mistake on the first line - original has got an i instead of an l.

byRo
12-13-2004, 08:19 AM
as v.bampton said...
You declared one variable and used another, so originalUnit is undefined.

Also,as you observed, Java is very case sensitive - you can lose a lot of time fixing these errors. Best to define a personal "standard" for the different type of object etc.. and stick to it.

Alternatives....
- 1st letter lower case, 2nd word first letter upper case (Java's ugly standard);
- All lower;
- All upper;
- 1st letter upper case, 2nd word first letter upper case;
- Underline between words
etc...
etc...

If you have a standard it'll be much easier to get it right than having to remember how you declared each variable.

byRo

Lasse
12-13-2004, 09:22 AM
ohh so i can just keep everything a lowercase? think you mentioned it but thhis would make ti that much easyer.

Ofcause to look over a very compleks script a system might help but if it gets out of hand ill come up with one.

Thanks, Lasse

byRo
12-14-2004, 04:39 AM
You can keep anything that you define in lower case, without any problem.
For all the other, pre-defined , words you have to use them exactly as defined.

byRo

MBChamberlain
12-14-2004, 06:37 AM
Another common convention for programming is called Hungarian Notation...if works like this:

You use a two or three letter combination to indicate the type of variable,

bl = boolean
int = integer
obj = object
str = string
sng = single
dbl = double
lng = long
etc, etc...

then you add your variable name with the first letter of each word capitalized.

Your variable for a person's first name would look like this: strFirstName

I usually program in C and Perl so I don't know if you have to define a variable type in Java, but it is a good idea anyway. The big advantage is you can read "strFirstName" easier than "strfirstname" and you know what kind of data is in it when you start performing mathematical operations or concatination.

Again, you can do it anyway you want as long as it is identical to both the declaration and call, but a good naming convention makes things easier for you, and especially for anyone else who reads through your code, in the long run.

Take care,

Michael

byRo
12-14-2004, 03:45 PM
Thanks, Michael, good idea. I'll be using this next time.
Java in Photoshop can be pretty confusing when you are trying to remember whether your variable / object is a color, or a layer, or a point etc... etc...

Probably have to start up a whole new naming convention:

rgb = RGB color (rgbViolet) ;
lyr = layer (lyrHP50);
pt = point (ptCenter).

byRo