Path Vertex Position Info Script help
So i'm working on a script with AI help and i managed to make this script work as a dockable ui panel.
What this script does it retrieves the path points and its tangents position value in comp space and layer space.
You select the path, select an option from the checkboxes which value you want to get and you hit the "Get Path" button. After this you see all the position values for all points from the path in the text boxes.
That the script only recognise the Layer Transform control changes and it calculates it to the comp space where the path point is. thats good.
But Issue is its not calculates the Shape Group Transforms position, scale, rotation and skew when they are changed.
And i cant figure it out with AI tools.
(function (aGbl) {
function mCreateUI(aObj) {
var mPorW = (aObj instanceof Panel) ? aObj : new Window("palette", "Get Path", undefined, { resizeable: true });
mPorW.orientation = "column";
mPorW.alignChildren = ["fill", "fill"];
mPorW.spacing = 7;
mPorW.margins = [7, 7, 7, 7];
var controlPanel = mPorW.add("group");
controlPanel.alignment = ["fill", "top"];
controlPanel.margins = 0;
controlPanel.orientation = "row";
controlPanel.spacing = 5;
mPorW.compSpaceCheckbox = controlPanel.add("checkbox", undefined, "Comp Space");
mPorW.layerSpaceCheckbox = controlPanel.add("checkbox", undefined, "Layer Space");
mPorW.inTangentsCheckbox = controlPanel.add("checkbox", undefined, "InTangents");
mPorW.outTangentsCheckbox = controlPanel.add("checkbox", undefined, "OutTangents");
mPorW.compSpaceCheckbox.alignment = ["left", "center"];
mPorW.layerSpaceCheckbox.alignment = ["left", "center"];
mPorW.inTangentsCheckbox.alignment = ["left", "center"];
mPorW.outTangentsCheckbox.alignment = ["left", "center"];
var buttonPanel = controlPanel.add("group");
buttonPanel.alignment = ["fill", "top"];
buttonPanel.margins = 0;
mPorW.mBtGet = buttonPanel.add("button", undefined, "Get Path");
mPorW.mBtGet.preferredSize.height = 30;
mPorW.mBtGet.alignment = ["fill", "fill"];
mPorW.mBtGet.graphics.allMargins = [0, 0, 0, 0];
var textAreaGroup = mPorW.add("group");
textAreaGroup.orientation = "row";
textAreaGroup.alignment = ["fill", "fill"];
textAreaGroup.spacing = 5;
mPorW.mPointNumbers = textAreaGroup.add("edittext", undefined, "", { multiline: true, scrolling: true, wantReturn: true });
mPorW.mPointNumbers.alignment = ["left", "fill"];
mPorW.mPointNumbers.preferredSize.width = 43;
mPorW.mTextArea = textAreaGroup.add("edittext", undefined, "", { multiline: true, scrolling: true, wantReturn: true });
mPorW.mTextArea.alignment = ["fill", "fill"];
mPorW.onResizing = mPorW.onResize = function () {
this.layout.resize();
};
mPorW.layout.layout(true);
return mPorW;
}
var mPnl = mCreateUI(aGbl);
if (mPnl instanceof Window) {
mPnl.center();
mPnl.show();
}
mPnl.mBtGet.onClick = function () {
mPnl.mTextArea.text = "";
mPnl.mPointNumbers.text = "";
var mAi = app.project.activeItem;
if (mAi && mAi instanceof CompItem) {
var selectedLayers = mAi.selectedLayers;
for (var l = 0; l < selectedLayers.length; l++) {
var mSl = selectedLayers[l];
var selectedProperties = mSl.selectedProperties;
for (var p = 0; p < selectedProperties.length; p++) {
var mSp = selectedProperties[p];
if (mSp && mSp.matchName === "ADBE Vector Shape - Group") {
var mPathVal = mSp.property("ADBE Vector Shape").value;
if (mPathVal) {
var mVtxs = mPathVal.vertices;
var mIns = mPathVal.inTangents;
var mOuts = mPathVal.outTangents;
var layerPos = mSl.property("Transform").property("Position").value;
var anchorPos = mSl.property("Transform").property("Anchor Point").value;
var layerScale = mSl.property("Transform").property("Scale").value / 100; // Scale is in percentage
var layerRotation = mSl.property("Transform").property("Rotation").value;
var compWidth = mAi.width;
var compHeight = mAi.height;
var showCompSpace = mPnl.compSpaceCheckbox.value;
var showLayerSpace = mPnl.layerSpaceCheckbox.value;
var showInTangents = mPnl.inTangentsCheckbox.value;
var showOutTangents = mPnl.outTangentsCheckbox.value;
// Convert rotation to radians
var rad = layerRotation * Math.PI / 180;
for (var i = 0; i < mVtxs.length; i++) {
var pointsInfo = "";
if ((showCompSpace || showLayerSpace || showInTangents || showOutTangents)) {
// Calculate distance from anchor point to vertex
var distX = mVtxs[i][0] - anchorPos[0];
var distY = mVtxs[i][1] - anchorPos[1];
// Apply rotation
var rotatedX = distX * Math.cos(rad) - distY * Math.sin(rad);
var rotatedY = distX * Math.sin(rad) + distY * Math.cos(rad);
// Adjust for scale
var scaledX = distX * layerScale[0];
var scaledY = distY * layerScale[1];
var rotatedX = scaledX * Math.cos(rad) - scaledY * Math.sin(rad);
var rotatedY = scaledX * Math.sin(rad) + scaledY * Math.cos(rad);
// Adjust for position
var compX = layerPos[0] + rotatedX;
var compY = layerPos[1] + rotatedY;
var infoPrefix = i + "";
if (showCompSpace) {
pointsInfo += "" + compX.toFixed(2) + ", " + compY.toFixed(2);
if (showLayerSpace || showInTangents || showOutTangents) pointsInfo += " | ";
}
if (showLayerSpace) {
pointsInfo += "" + mVtxs[i][0].toFixed(2) + ", " + mVtxs[i][1].toFixed(2);
if (showInTangents || showOutTangents) pointsInfo += " | ";
}
if (showInTangents) {
pointsInfo += "" + mIns[i][0].toFixed(2) + ", " + mIns[i][1].toFixed(2);
if (showOutTangents) pointsInfo += " | ";
}
if (showOutTangents) {
pointsInfo += "" + mOuts[i][0].toFixed(2) + ", " + mOuts[i][1].toFixed(2);
}
mPnl.mTextArea.text += pointsInfo + "\n";
mPnl.mPointNumbers.text += infoPrefix + "\n";
}
}
}
}
}
}
}
};
})(this);
maybe someone can help thx
