I’m really giving my best here, but stuck (and suck ) at the math part. Could you give me a hint?
Usually when you crop a subcomp it gets moved in the main comp and you need to reposition manually.
I would like to crop the sub and reposition in all the comps where this sub is used.
Edit: Ah, and I dont want to touch the anchor points (if that’s your idea) bc obviously I want to reposition them manually in the main comp(s).
Thx in advance!
I muted the lines that are giving me a hard time here. Also, probably way too many variables (?) =>
Smart Crop.zip (2.8 KB)
Apologies for the delay in responding. I’ve looked into the issue you’re facing with composition resizing and anchor point adjustments.
Here’s what I found:
When you alter the size of a sub-composition (precomp), the anchor points of theese precomps layers within the main comp are adjusted relative to the new size.
For instance, if your original composition is 100 pixels wide with an anchor point x at 10 pixels, doubling the composition’s width to 200 pixels will also double the anchor point’s position to 20 pixels.
Conversely, if you reduce the composition’s width to 50 pixels, the anchor point adjusts to half its original position, moving to 5 pixels.
This automatic adjustment is based on the percentage change in the composition’s size. If your goal is to keep the layers stationary relative to the composition’s frame despite resizing, you’ll need to recalibrate the anchor points.
Here’s a formula that can help:
- Save the original width of the composition and the initial X-coordinate of the anchor point.
- After resizing the precomp, calculate the difference between the original and new width, then halve this value to find the offset
offset = (original precomp width - new precomp width) / 2.
- Adjust the anchor point by subtracting this offset from the original Y-coordinate.
new anchor point x = original anchor point x - offset
final formula -
original anchor point x - (original precomp width - new precomp width) / 2.
also do the same thing to the height as well.
Applying this formula will reposition the layers as if their anchor points were centered, regardless of the composition’s new size. This should address the repositioning issue without manually adjusting each anchor point in your main composition.
Download this automation to check if it works for you -
Crop by 50%.json (35.1 KB)
I hope this helps! Let me know if you need further clarification.
thx for your reply, sry I’ve been busy recently (YOU are the quick responder as usual )
I just checked it briefly - working to get it to 50% but I will see if I can get it to crop to an individual region of interest. Will post it here if I can hopefully make it, following your instructions.
@thepetercoin Sure, take your time, and when the time comes I am here to help if you need it
I got it! Not for all cases, but =>
This one will crop the precomp and reposition it when found as child in another Comp.
BUT it just works if both MainComp and Precomp have the same dimensions. Tricky as usual for a non-math guy.
I want to move the position not the anchor bc. i want to be able to scale from the center.
Do you have any advice?
Smart Crop.zip (2.9 KB)
You’ve successfully identified the necessary offset for the inner pre-comp by calculating the margin plus half of the pre-comp’s new dimensions. This approach effectively determines the new position of the cropped area relative to the original composition dimensions.
To make this work with varying composition sizes, it’s important to also calculate the offset relative to the containing compositions for each pre-comp before cropping. This can be done by saving the original width and height, then subtracting half of these dimensions from the current position of the pre-comp. This method will pinpoint the top-left corner of the layer before cropping, allowing you to add the previously calculated offset.
Regarding the new version, here are the key changes I’ve made:
- Removed the right and bottom margin variables, as they are unnecessary. We can directly use the pre-comp width & height, which effectively does the same job.
- Saved the original width and height of the pre-comp dimensions to facilitate later offset calculations.
- Changed the method of searching for the precomp from using the ‘name’ property to the ‘source’ property, to avoid bugs caused by multiple pre-comps sharing the same name.
- Added lines to calculate the top-left x and y positions, which will be combined with the inner pre-comp offset you’ve already calculated.
You can download the updated version here:
Smart Crop v2.zip (3.1 KB)
Please note that this automation assumes all layers in other comps have their anchor points centered and scaled to 100%. While it’s possible to adjust this to accommodate different scenarios, I’ve kept it simple and in line with your original automation framework.
If you have any questions, feel free to ask.
This is my christmas.
Perfect! Thanks a lot and in case you celebrate christmas, merry christmas and in any case all the best for the new year!