Skip to main content
dannyl8236560
Participating Frequently
January 14, 2024
Answered

Path Property Expression to offset the path

  • January 14, 2024
  • 2 replies
  • 1177 views

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

This topic has been closed for replies.
Correct answer Dan Ebberts

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);

2 replies

Mylenium
Legend
January 14, 2024

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

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
January 14, 2024

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);
dannyl8236560
Participating Frequently
January 14, 2024

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 😞