Hi all,
I'm trying to create a Path object with PhotoShop CS4.
This following .jsx script is OK :
Code: Select all//PSD creation.
var docRef = app.documents.add(1300, 500, 72, "PathTest.psd")
//Points creation.
var curveArray = new Array()
//C1 : (0,0)(30,50)(60,0)(100,50)
curveArray[0] = new PathPointInfo
curveArray[0].kind = PointKind.SMOOTHPOINT
curveArray[0].anchor = Array(0, 0)
curveArray[0].leftDirection = Array(30, 50)
curveArray[0].rightDirection = curveArray[0].anchor
curveArray[1] = new PathPointInfo
curveArray[1].kind = PointKind.SMOOTHPOINT
curveArray[1].anchor = Array(100, 50)
curveArray[1].leftDirection = curveArray[1].anchor
curveArray[1].rightDirection = Array(60, 0)
//Setting SubPath.
var curveSubPathArray = new Array()
curveSubPathArray[0] = new SubPathInfo()
curveSubPathArray[0].operation = ShapeOperation.SHAPEXOR
curveSubPathArray[0].closed = false
curveSubPathArray[0].entireSubPath = curveArray
//Adding new Path to document.
var myPathItem = docRef.pathItems.add("Path example", curveSubPathArray);
But, when I try to write it in Java 5 (with Jacob.jar v.1.15 M3) it doesn't wok :
Code: Select all//In the whole code :
//"this.psInstance" is the current active .psd document.
//"Dot" is a point with x and y coordinates. It is similar to Point2D.
private ActiveXComponent newPathPoint(Dot point){
ActiveXComponent actionDescriptor6 = new ActiveXComponent("Photoshop.ActionDescriptor");
Dispatch.call(actionDescriptor6, "PutUnitDouble",
Dispatch.call(this.psInstance, "charIDToTypeID", "Hrzn"),
Dispatch.call(this.psInstance, "charIDToTypeID", "#Pxl"), point.getX());
Dispatch.call(actionDescriptor6, "PutUnitDouble",
Dispatch.call(this.psInstance, "charIDToTypeID", "Vrtc"),
Dispatch.call(this.psInstance, "charIDToTypeID", "#Pxl"), point.getY());
return actionDescriptor6;
}
private ActiveXComponent newPathPointInfo(Dot p1, boolean left, Dot p2){
ActiveXComponent actionDescriptor5 = new ActiveXComponent("Photoshop.ActionDescriptor");
ActiveXComponent actionDescriptor6 = newPathPoint(p1); //anchor
ActiveXComponent actionReference = new ActiveXComponent("Photoshop.ActionReference");
Dispatch.call(actionReference, "PutClass",
Dispatch.call(this.psInstance, "stringIDToTypeID", "PathPointInfo"));
Dispatch.call(actionDescriptor5, "PutReference",
Dispatch.call(this.psInstance, "charIDToTypeID", "null"), actionReference);
Dispatch.call(actionDescriptor5, "PutString",
Dispatch.call(this.psInstance, "stringIDToTypeID", "kind"),
"SMOOTHPOINT");
Dispatch.call(actionDescriptor5, "PutObject",
Dispatch.call(this.psInstance, "charIDToTypeID", "T "),
Dispatch.call(this.psInstance, "stringIDToTypeID", "anchor"),
actionDescriptor6);
//Setting left & right direction.
ActiveXComponent actionDescriptor7 = newPathPoint(p2);
if (left){
Dispatch.call(actionDescriptor5, "PutObject",
Dispatch.call(this.psInstance, "charIDToTypeID", "T "),
Dispatch.call(this.psInstance, "stringIDToTypeID", "leftDirection"),
actionDescriptor7);
Dispatch.call(actionDescriptor5, "PutObject",
Dispatch.call(this.psInstance, "charIDToTypeID", "T "),
Dispatch.call(this.psInstance, "stringIDToTypeID", "rightDirection"),
actionDescriptor6);
} else {
Dispatch.call(actionDescriptor5, "PutObject",
Dispatch.call(this.psInstance, "charIDToTypeID", "T "),
Dispatch.call(this.psInstance, "stringIDToTypeID", "rightDirection"),
actionDescriptor7);
Dispatch.call(actionDescriptor5, "PutObject",
Dispatch.call(this.psInstance, "charIDToTypeID", "T "),
Dispatch.call(this.psInstance, "stringIDToTypeID", "leftDirection"),
actionDescriptor6);
}
return actionDescriptor5;
}
//Let points = (0,0)(30,50)(60,0)(100,50)
private ActiveXComponent createSubPathInfo(ArrayList<Dot> points){
ActiveXComponent actionDescriptor3 = new ActiveXComponent("Photoshop.ActionDescriptor");
ActiveXComponent actionList1 = new ActiveXComponent("Photoshop.ActionList");
//Adding (0,0) anchor with (30,50) as leftDirection.
Dispatch.call(actionList1, "PutObject", 0, newPathPointInfo(points.get(0), true, points.get(1)));
//Adding (100,50) anchor whith (60,0) as rightDirection.
Dispatch.call(actionList1, "PutObject", 1, newPathPointInfo(points.get(3), false, points.get(2)));
ActiveXComponent actionReference = new ActiveXComponent("Photoshop.ActionReference");
Dispatch.call(actionReference, "PutClass",
Dispatch.call(this.psInstance, "stringIDToTypeID", "SubPathInfo"));
Dispatch.call(actionDescriptor3, "PutReference",
Dispatch.call(this.psInstance, "charIDToTypeID", "null"), actionReference);
Dispatch.call(actionDescriptor3, "PutBoolean",
Dispatch.call(this.psInstance, "stringIDToTypeID", "closed"),
false);
Dispatch.call(actionDescriptor3, "PutString",
Dispatch.call(this.psInstance, "stringIDToTypeID", "operation"),
"SHAPEXOR");
Dispatch.call(actionDescriptor3, "PutList",
Dispatch.call(this.psInstance, "stringIDToTypeID", "entireSubPath"),
actionList1);
return actionDescriptor3;
}
public void createPath(String pathName, ArrayList<Dot> pathPoints){
ActiveXComponent actionDescriptor1 = new ActiveXComponent("Photoshop.ActionDescriptor");
ActiveXComponent actionDescriptor2 = new ActiveXComponent("Photoshop.ActionDescriptor");
ActiveXComponent actionReference1 = new ActiveXComponent("Photoshop.ActionReference");
ActiveXComponent actionReference2 = new ActiveXComponent("Photoshop.ActionReference");
ActiveXComponent actionList3 = new ActiveXComponent("Photoshop.ActionList");
Dispatch.call(actionReference1, "PutClass",
Dispatch.call(this.psInstance, "charIDToTypeID", "Path"));
Dispatch.call(actionDescriptor1, "PutReference",
Dispatch.call(this.psInstance, "charIDToTypeID", "null"), actionReference1);
Dispatch.call(actionDescriptor1, "PutString",
Dispatch.call(this.psInstance, "charIDToTypeID", "Nm "), pathName);
Dispatch.call(actionList3, "PutObject", 0, createSubPathInfo(pathPoints));
Dispatch.call(actionDescriptor2, "PutList",
Dispatch.call(this.psInstance, "stringIDToTypeID", "subPathItems"),
actionList3);
Dispatch.call(actionReference2, "PutClass",
Dispatch.call(this.psInstance, "stringIDToTypeID", "PathItem"));
Dispatch.call(actionDescriptor2, "PutReference",
Dispatch.call(this.psInstance, "charIDToTypeID", "null"), actionReference2);
Dispatch.call(actionDescriptor2, "PutString",
Dispatch.call(this.psInstance, "charIDToTypeID", "Nm "), pathName);
Dispatch.call(actionDescriptor1, "PutObject",
Dispatch.call(this.psInstance, "charIDToTypeID", "T "),
Dispatch.call(this.psInstance, "stringIDToTypeID", "pathItems"),
actionDescriptor2);
Dispatch.call(this.psInstance, "ExecuteAction",
Dispatch.call(this.psInstance, "charIDToTypeID", "Mk "), actionDescriptor1, PsdFileManager.DIALOG_MODE);
}
It creates a Path "layer" but with no curve and no error.
What am I doing wrong ?? Can anyone help me with this ?