Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Nov 10, 2024 Nov 10, 2024

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();
TOPICS
Scripting
344
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 10, 2024 Nov 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

 

Translate
Community Expert ,
Nov 10, 2024 Nov 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 10, 2024 Nov 10, 2024
LATEST

Thank you so much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines