distance from first vertex expressed in 0-100%?
I'm trying to make a script that gets the vertex on a path and determines their distance in % from the first vertex, so I can create a trim path per vertex/segment with that percentage number (so it would be like splitting the curve at its vertex and having all the segments separated but on a non destructive way)*
Do you know how to get the percentage of a vertex along the path from the first vertex?
like, v is 23%, etc?
Any idea will be great!
*having this illustrator script adapted for after effects would be absolutely awesome: cut at selected anchors
Do you want it to measure curves, or just straight line sections? Curves are going to require more work, but it is possible to approximate the distance (measuring bezier curves is basically splitting the curve into lots of little bits and measuring between those as straight lines).
So, I figured it out, but it cannot be calculated from a single expression, and because of how after effects' "createPath" function works it requires a minimum number of additional path layers in a sub folder equal to or greater than the number of vertices in the target path.
In short, it's a pain, but here's how you do it:
make a shape layer with a bunch of paths inside the same isolated folder, and into all of those put this expression:
Then, after that, place this code into whatever property you want to return the percentage, and make sure you property link the location of the master path, and the location of the sub-paths.
use r to set the resolution (higher means more accurate, but more calculations), while n will target the index you desire to grab.
wow! thank you very much for your effort and expanation!
my idea is creating a basic script with 3 buttons, each one will divide the path on different ways: N parts with random length each (whose sum is the total length), N parts all equal, and N parts, given by the vertex points.
I was using this snippet from Paul Conigliaro to get the total path length and then starting with the 3 approaches.
I did first the random sub lengths with the sum of the total length, and I changed the approach when I realized using the Trim Paths Offset parameter was giving me the 360º as a total length and it could point me to something. My scripting knowledge is pretty basic, so I love to explore different approaches which most of the times goes to dead ends, but I also love to get lost on those.
So, for this part ("the vertex and segment division"s button), I was just starting to doodle how to approach. I was starting to convert the array of vertex from cartesian coordinates to polar and then see if that could lead me to something, but before going further on that direction I wanted to ask because something was telling me it was not going to be the right direction.
So, I love your approach, even if it relays on the expression side (the script I have in mind is just using the code to set the amount of path duplicates and needed values in the trim paths offset or end, and having a couple lines for the path dependencies with the master path).
I couldn't make the second expression part you wrote work (the code going into whatever property I want to return the percentage), it says Index out of range. But for now its ok, because on this case, applying a simple trim paths below all the subpaths splitted with the expression you wrote, does the work.
Now I'm going to see how to add via script the amount of shape path copies equal to the amount of vertex (considering these as not variable over the timeline) and then appply the expression on each. It's more effective than the multiple shapes+trim paths with clamped range I was doing since the beginning.
Thank you again for your time and knowledge!
Which part of the 2nd script is getting the index out of range? The only thing I can think is the group with the nested paths inside; IIRC that's the only index measuring. Shape layers can be tricky, there's the group and then the content nested seperately, so make sure you're linking it similar to how I have it written.
Yes this would be easier to do in a script than expressions; you could simply store the selected path data as a variable, cycle through modifying the selected path down to its individual segments and measuring their length, put the final path back in,
then compare the different path path lengths relative to their positions in the total length and then get a percentage.
Paul's awesome, glad to see his stuff is being put to use;. looks like he's pulled in a more advanced measuring method than I would use (or could ever begin to think of).
oh, I just reapplied the 2nd script the exact way than the last time and now it works, so thats great! thanks!
Yes, shape layers are always tricky with the hierarchy!
As for the script, I've done the split at vertex part simply cycling into the n vertices, creating the n number of shape copies and applying each path your expression, and it works great.
It made me rethink the way I did the option to add the number of splits. Now it works adding a trim to each path split's subgroup(but the path length doesn't vary, only the way the trim reveals it) , but I love the way your expression cuts the path. Even considering baking the expression to have real splits.
I guess I'd have to work on the P = L.points(); line, (on the expresison side and the script side) so it reads only the array of segments the user enters on the script UI