I managed to write a VB script that I am trying running on Photoshop CS4 Extended using the ExtendScript ToolKit. It opens an (all black) .png file and places a small line on it.
I said I managed because I sure am not a programmer, just by reading online about the subject, using some (very basic) knowledge of VBA from Microsoft Access, and copying pasting.
The code I am trying getting going:
//Save preferences2
var originalUnit=app.preferences.rulerUnits
preferences.rulerUnits=Units.PIXELS
var fileName = 1;// Typically this is just a number 1.
var fileNameSeries = "/D/" + fileName
//Open .png to imprint upon
var fileRef=new File(fileNameSeries + ".png")
var docRef = app.open(fileRef)
var lineArray1 = new PathPointInfo
lineArray1.Kind = 2 ;// for PsPointKind --> 2 (psCornerPoint)
lineArray1.Anchor = Array(100, 100)
lineArray1.LeftDirection = lineArray1.Anchor
lineArray1.RightDirection = lineArray1.Anchor
var lineArray2 = new PathPointInfo
lineArray2.Kind = 2
lineArray2.Anchor = Array(150, 200)
lineArray2.LeftDirection = lineArray2.Anchor
lineArray2.RightDirection = lineArray2.Anchor
//Next create a SubPathInfo object, which will hold the line array
//in its EntireSubPath property.
var lineSubPathArray = new SubPathInfo
lineSubPathArray.Operation = 2 ;// for PsShapeOperation --> 2 (psShapeXOR)
lineSubPathArray.Closed = false
lineSubPathArray.EntireSubPath = lineArray1
//create the PathItem object using Add. This method takes the SubPathInfo object
//and returns a PathItem object, which is added to the pathItems collection
//for the document.
//var myPathItem = new PathItem
myPathItem = docRef.PathItems.Add("A Line", lineSubPathArray)
// stroke it so we can see something
myPathItem.StrokePath(2) //'for PsToolType --> 2 (psBrush)
}
fileName++
fileNameSeries = "/D/ " + fileName
pngFile = new File(fileNameSeries)
pngSaveOptions = new PNGSaveOptions()
pngSaveOptions.interlaced = false
app.activeDocument.saveAs(pngFile, pngSaveOptions, true)
//dispose
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES)
//Retrieve original preferences
preferences.rulerUnits=originalUnit
I'm stuck on a syntax error. The line: myPathItem = docRef.PathItems.Add("A Line", lineSubPathArray) produces an "undefined is not an object".
Can anyone tell me what am I doing wrong.