Skip to main content
Participating Frequently
November 10, 2024
Answered

How to get the exact anchor point position of a layer when, a layer is parented to another layer?

  • November 10, 2024
  • 1 reply
  • 380 views

so I have the following code, it works when the layer is not parented , but when the layer is parented to another layer it fails.
I know this happens because the transform properties of the parented layer doesnt change when you move the parent layer, is there a workaround for it?

    app.beginUndoGroup("Add Guides to Anchor Points");
    
    // Get the active composition
    var comp = app.project.activeItem;

    // Check if a composition is selected
    if (!(comp instanceof CompItem)) {
        alert("Please select a composition.");
        return;
    }

    // Check if there are selected layers
    if (comp.selectedLayers.length === 0) {
        alert("Please select at least one layer.");
        return;
    }

    // If "autoclear" is enabled, clear all existing guides
    if (Autoclear.value) {
        app.executeCommand(2276); // Clear all guides
    }

    

    // Loop through each selected layer
    for (var i = 0; i < comp.selectedLayers.length; i++) {
        var layer = comp.selectedLayers[i];

        // Get the layer's anchor point and position
        var anchorPoint = layer.anchorPoint.value;
        var position = layer.position.value;

        // Calculate the composition space position by adding anchor point to position
        var guideX = position[0] ;
        var guideY = position[1] ;

        // Add guides at the calculated position
        comp.addGuide(1, guideX); // Vertical guide (X position)
        comp.addGuide(0, guideY); // Horizontal guide (Y position)
    }

    app.endUndoGroup();
This topic has been closed for replies.
Correct answer Mathias Moehl

AVLayers have a SourcePointToComp function to convert points from layer space to comp space:
https://ae-scripting.docsforadobe.dev/layers/avlayer.html#avlayer-sourcepointtocomp

 

1 reply

Mathias Moehl
Community Expert
Mathias MoehlCommunity ExpertCorrect answer
Community Expert
November 10, 2024

AVLayers have a SourcePointToComp function to convert points from layer space to comp space:
https://ae-scripting.docsforadobe.dev/layers/avlayer.html#avlayer-sourcepointtocomp

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Participating Frequently
November 10, 2024

Thank you so much.