Photoshop CS Scripting Guide 57Scripting PhotoshopWorking with units 3The following example shows how to create 2 layers and then rename the first one inJavaScript.// set ruler units and create new documentoriginalRulerUnits = app.preferences.rulerUnitsapp.preferences.rulerUnits = Units.INCHES;app.documents.add(4,4,72,"My New Document");docRef = app.activeDocument;layer1Ref = docRef.artLayers.add();layer2Ref = docRef.artLayers.add();layer1Ref.name = "This layer was first";// restore unit settingapp.preferences.rulerUnits = originalRulerUnits;3.6 Working with unitsPhotoshop provides two rulers for use when working on a document — a graphics ruler usedfor most graphical layout measurements and a type ruler which is active when using the typetool. The unit types for these two rulers are set using the ruler units(RulerUnits/rulerUnits) and type units (TypeUnits/typeUnits), respectively.These settings correspond to those found in the Photoshop preference dialog under“Edit >Preferences > Units & Rulers.”The graphics ruler is used for most operations on a document where height, width, or positionare specified. The type ruler is used when operating on text items, such as when setting leadingor indent values. By changing the settings for each ruler you can work with documents in themeasurement system that make the most sense for the project at hand.3.6.1 Unit valuesPhotoshop uses unit values for certain properties and parameters. Scripting commentsconcerning Photoshop objects and properties note where unit values are used.Because of scripting language differences, the way you provide a unit value in a script dependson the language you are using. All languages support plain numbers for unit values. Thesevalues are treated as being of the type currently specified for the appropriate ruler.For example, if the ruler units are currently set to inches and the following Visual Basicstatement is executed:docRef.ResizeImage 3,3the document's image is resized to 3 inches by 3 inches. If the ruler units were set to pixels, theimage would be 3 pixels by 3 pixels, which is probably not what was intended. To ensure thatyour scripts produce the expected results you should check and set the ruler units to the type