// I am a Developer Of This JSX
// This File For Learn How Develop Extension Not Coded !
// Free USE ...!!!
// Have Fun
// ReGurd King USH !
// 2020 / 01 / 03 11:45

var SelectedLayer;

function Action1(Size) {
    try {
        indexLayer = app.project.activeItem.selectedLayers[0];
        SelectedLayer = app.project.activeItem.layers;
        if (indexLayer.name != "Zone") {

            if ((indexLayer instanceof TextLayer) || (indexLayer instanceof ShapeLayer) || (indexLayer.source instanceof CompItem && indexLayer.collapseTransformation) || (indexLayer.source instanceof CompItem && indexLayer.containingComp.width == indexLayer.width && indexLayer.containingComp.height == indexLayer.height && !indexLayer.collapseTransformation)) {
                app.beginUndoGroup("Zone Below");

                var Shape = SelectedLayer.addShape();
                Shape.name = "Zone";
                Shape.label = 2;
                Shape.property("ADBE Root Vectors Group").addProperty("ADBE Vector Group");
                Shape.property("ADBE Root Vectors Group").property(1).name = "Ellipse 1";
                Shape.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Shape - Ellipse");
                Shape.property("ADBE Root Vectors Group").property(1).property(2).property(1).name = "Ellipse Path 1";
                Shape.property("ADBE Root Vectors Group").property(1).property(2).property(1).property("ADBE Vector Ellipse Size").setValue([Size, Size]);
                Shape.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Graphic - Fill");
                Shape.property("ADBE Root Vectors Group").property(1).property(2).property(2).name = "Fill 1";
                Shape.property("ADBE Root Vectors Group").property(1).property(2).property(2).property("ADBE Vector Fill Color").setValue([1, 0.16078429876589, 0.16078429876589, 1]);
                Shape.property("ADBE Root Vectors Group").property(1).property(3).property("ADBE Vector Position").setValue([0, 0]);


                Shape.property("ADBE Effect Parade").addProperty("ADBE Set Matte3");
                Shape.property("ADBE Effect Parade").property(1).name = "Set Matte 1";
                Shape.property("ADBE Effect Parade").property(1).property("ADBE Set Matte3-0001").setValue(indexLayer.index);

                Shape.property("ADBE Effect Parade").addProperty("ADBE Set Matte3");
                Shape.property("ADBE Effect Parade").property(2).name = "Set Matte 2";
                Shape.property("ADBE Effect Parade").property(2).property("ADBE Set Matte3-0001").setValue(indexLayer.index);

                Shape.property("ADBE Effect Parade").addProperty("ADBE Compound Arithmetic");
                Shape.property("ADBE Effect Parade").property(3).property("ADBE Compound Arithmetic-0001").setValue(indexLayer.index);

                if (indexLayer.source instanceof CompItem && !indexLayer.collapseTransformation && indexLayer.containingComp.width == indexLayer.width && indexLayer.containingComp.height == indexLayer.height) {
                    Shape.property("ADBE Effect Parade").addProperty("ADBE Geometry2");
                    Shape.property("ADBE Effect Parade").property(4).name = "Transform";
                    Shape.property("ADBE Effect Parade").property(4).property("ADBE Geometry2-0001").expression = 'thisComp.layer(\"' + indexLayer.name + '\").transform.anchorPoint';
                    Shape.property("ADBE Effect Parade").property(4).property("ADBE Geometry2-0002").expression = 'thisComp.layer(\"' + indexLayer.name + '\").transform.position';
                    Shape.property("ADBE Effect Parade").property(4).property("ADBE Geometry2-0007").expression = 'thisComp.layer(\"' + indexLayer.name + '\").transform.rotation';
                }
                Update_One(indexLayer.name,Shape);
                app.endUndoGroup();
            }
            else if (indexLayer.source instanceof CompItem && (indexLayer.containingComp.width != indexLayer.width || indexLayer.containingComp.height != indexLayer.height)) {
                alert("The size of the selected composition and the current composition must be the same or enable 'Collapse Transformation'");
            }
            else if (indexLayer.source instanceof LightLayer || indexLayer.source instanceof CameraLayer)
                alert("Please select the correct layer");
            else
                alert("You need to Pre-compose the layer before applying it");
        }
        else
            alert("Please select the correct layer")

    } catch (er) {
        alert("Please select a layer (below layer)");
    }
}
function Action2(Size) {
    try {
        indexLayer = app.project.activeItem.selectedLayers[0];
        SelectedLayer = app.project.activeItem.layers;
        if (indexLayer.name != "Zone") {
            if ((indexLayer instanceof TextLayer) || (indexLayer instanceof ShapeLayer) || (indexLayer.source instanceof CompItem && indexLayer.collapseTransformation) || (indexLayer.source instanceof CompItem && indexLayer.containingComp.width == indexLayer.width && indexLayer.containingComp.height == indexLayer.height && !indexLayer.collapseTransformation)) {
                app.beginUndoGroup("Zone Below");

                var Shape = SelectedLayer.addShape();
                Shape.name = "Zone";
                Shape.label = 2;
                Shape.property("ADBE Root Vectors Group").addProperty("ADBE Vector Group");
                Shape.property("ADBE Root Vectors Group").property(1).name = "Rectangle 1";
                Shape.property("ADBE Root Vectors Group").property(1).index = 1;
                Shape.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Shape - Rect");
                Shape.property("ADBE Root Vectors Group").property(1).property(2).property(1).name = "Rectangle Path 1";
                Shape.property("ADBE Root Vectors Group").property(1).property(2).property(1).property("ADBE Vector Rect Size").setValue([Size, Size]);
                Shape.property("ADBE Root Vectors Group").property(1).property(2).addProperty("ADBE Vector Graphic - Fill");
                Shape.property("ADBE Root Vectors Group").property(1).property(2).property(2).name = "Fill 1";
                Shape.property("ADBE Root Vectors Group").property(1).property(2).property(2).property("ADBE Vector Fill Color").setValue([1, 0.16078429876589, 0.16078429876589, 1]);

                Shape.property("ADBE Effect Parade").addProperty("ADBE Set Matte3");
                Shape.property("ADBE Effect Parade").property(1).name = "Set Matte 1";
                Shape.property("ADBE Effect Parade").property(1).property("ADBE Set Matte3-0001").setValue(indexLayer.index);

                Shape.property("ADBE Effect Parade").addProperty("ADBE Set Matte3");
                Shape.property("ADBE Effect Parade").property(2).name = "Set Matte 2";
                Shape.property("ADBE Effect Parade").property(2).property("ADBE Set Matte3-0001").setValue(indexLayer.index);

                Shape.property("ADBE Effect Parade").addProperty("ADBE Compound Arithmetic");
                Shape.property("ADBE Effect Parade").property(3).property("ADBE Compound Arithmetic-0001").setValue(indexLayer.index);

                if (indexLayer.source instanceof CompItem && !indexLayer.collapseTransformation && indexLayer.containingComp.width == indexLayer.width && indexLayer.containingComp.height == indexLayer.height) {
                    Shape.property("ADBE Effect Parade").addProperty("ADBE Geometry2");
                    Shape.property("ADBE Effect Parade").property(4).name = "Transform";
                    Shape.property("ADBE Effect Parade").property(4).property("ADBE Geometry2-0001").expression = 'thisComp.layer(\"' + indexLayer.name + '\").transform.anchorPoint';
                    Shape.property("ADBE Effect Parade").property(4).property("ADBE Geometry2-0002").expression = 'thisComp.layer(\"' + indexLayer.name + '\").transform.position';
                    Shape.property("ADBE Effect Parade").property(4).property("ADBE Geometry2-0007").expression = 'thisComp.layer(\"' + indexLayer.name + '\").transform.rotation';
                }
                //app.project.item(1).layer(4).property("ADBE Transform Group").property("ADBE Anchor Point")anchorPoint

                Update_One(indexLayer.name,Shape);
                app.endUndoGroup();
            }
            else if (indexLayer.source instanceof CompItem && (indexLayer.containingComp.width != indexLayer.width || indexLayer.containingComp.height != indexLayer.height)) {
                alert("The size of the selected composition and the current composition must be the same or enable 'Collapse Transformation'");
            }
            else if (indexLayer.source instanceof LightLayer || indexLayer.source instanceof CameraLayer)
                alert("Please select the correct layer");
            else
                alert("You need to Pre-compose the layer before applying it");
        }
        else
            alert("Please select the correct layer")

    } catch (er) {
        alert("Please select a layer (below layer)");
    }
}

function Update_One(NameLayer, ObjLayer) {
    try {
        var null1_marker1 = new MarkerValue(">>> "+NameLayer);
        null1_marker1.eventCuePoint = true;
        var newMarkerParameters = {};
        null1_marker1.setParameters(newMarkerParameters);
        ObjLayer.property("ADBE Marker").setValueAtTime(0.2, null1_marker1);
    } catch (er) {
        alert(er);
    }
}
