Copy link to clipboard
Copied
So i have this expression for the Path property in a Shape Group.
// Get the path from the first shape layer in the composition
var shapeLayer = thisComp.layer("Shape Layer Name");
var shapeGroup = shapeLayer.content("Shape Group Name");
var path = shapeGroup.content("Path Name").path;
// Get path properties
var pts = path.points();
var inTans = path.inTangents();
var outTans = path.outTangents();
var closed = path.isClosed();
// Move the path vertices 500 pixels to the right
for (var i = 0; i < pts.length; i++) {
pts[i][0] += 500; // Add 500 to the x-coordinate
}
// Create a new path with modified vertices
createPath(pts, inTans, outTans, closed);
It moves the path 500 pixel to the right. Only the path itself without touching the transform controls (postion etc..)
My issue is that i have to manually type the Shape Layer, Shape Group and Path name to make it work.
I can't figure it out how to make this expression work in a way to automatically recognise this hierarchy within the Shape Layer.
its something like ADBE Root Vectors Group, ADBE Vectors Group, ADBE Vector Shape.
Can anyone help? thx
It's not exactlly clear to me what you're trying to do. Where is the expression relative to the path data it's using? If the expression will be applied to the path where it's getting the data, it would just be like this:
var pts = points();
var inTans = inTangents();
var outTans = outTangents();
var closed = isClosed();
// Move the path vertices 500 pixels to the right
for (var i = 0; i < pts.length; i++) {
pts[i][0] += 500; // Add 500 to the x-coordinate
}
// Create a new path with modifi...
Copy link to clipboard
Copied
It's not exactlly clear to me what you're trying to do. Where is the expression relative to the path data it's using? If the expression will be applied to the path where it's getting the data, it would just be like this:
var pts = points();
var inTans = inTangents();
var outTans = outTangents();
var closed = isClosed();
// Move the path vertices 500 pixels to the right
for (var i = 0; i < pts.length; i++) {
pts[i][0] += 500; // Add 500 to the x-coordinate
}
// Create a new path with modified vertices
createPath(pts, inTans, outTans, closed);
Copy link to clipboard
Copied
i was so lost in the codes im just learning this sorry and i forget to test this way.
thank you for the answer its working now. nooby mistakes 😞
Copy link to clipboard
Copied
Dear Dan,
If you don't mind i don't want to open another discussion, because its the same code improved.
So this improved code now calculate the offset values by adding the anchor and position values together and moves the path accordingly. Its an Additon + now and the code works the path moves.
// Get the transform property of the shape group
var shapeGroupTransform = thisLayer.transform;
// Extract the anchor and position values
var anchorX = shapeGroupTransform.anchorPoint[0];
var anchorY = shapeGroupTransform.anchorPoint[1];
var positionX = shapeGroupTransform.position[0];
var positionY = shapeGroupTransform.position[1];
// Offset values
var offsetX = positionX + anchorX; // Adjust as needed
var offsetY = positionY + anchorY; // Adjust as needed
// Retrieve the path properties
var pts = points();
var inTans = inTangents();
var outTans = outTangents();
var closed = isClosed();
// Apply the offset to each point
for (var i = 0; i < pts.length; i++) {
pts[i][0] += offsetX; // Update x coordinate
pts[i][1] += offsetY; // Update y coordinate
}
// Create the modified path
createPath(pts, inTans, outTans, closed);
But what i need is that the path should move only to the difference value.
For example in my case the shape group transform postion values are 1920 / 1080 the anchor values are 4112 / 2160 so the difference is 2192 / 1080. So the path should move only + 2192 / 1080 pixel
Reason behind this when i zero out the position and anchor in the transform properties, the path stays at place and i don't have to manually grab all the path points with the selection tool and move it to place, because i got hundreds of shapes where i need to do this.
This way works what i want, but it needs to happen automatically.
// Offset values
var offsetX = 2192;
var offsetY = 1080;
thx again
Danny
Copy link to clipboard
Copied
Again, I'm not sure exactly what you're doing (or why), but it will probably be close to this:
// Retrieve the path properties
var pts = points();
var inTans = inTangents();
var outTans = outTangents();
var closed = isClosed();
var offset = anchorPoint - position;
// Apply the offset to each point
for (var i = 0; i < pts.length; i++) {
pts[i] += offset;
}
// Create the modified path
createPath(pts, inTans, outTans, closed);
Copy link to clipboard
Copied
Thx for the replies Dan.
My english is bad i know... Here is a video for you about what im trying to do.
The reason why i want to reset position and anchor to zero, because im importing the shapes from Illustrator to AE and if i don't reset the values the path points are not snapping to guides.
your method is to use Substraction -, but the path is not moving that way.
Copy link to clipboard
Copied
Property groups work by addressing their indices relative to the property they're applied to if you don't want to use explicit property names. So you basically end up with content(-1).content(-1).content(-1) etc. strung together to walk up the hierarchy and then positive indices to walk down again. The only real caveat is figuring out how far you have to go since you have no visual feedback and typically this throws a ton of nonsense errors before you get it right. It's also in the docs somewhere, so check out that property group thing. Otherwise Dan's answer is spot on. Changing a property directly does not require any explicit references.
Mylenium
Find more inspiration, events, and resources on the new Adobe Community
Explore Now