Skip to main content
Known Participant
June 23, 2022
Answered

AE scripting Grid to Guides

  • June 23, 2022
  • 1 reply
  • 1971 views

I am trying to create a simple script where Guides will be generated from the Grid. I know all of this is pretty basic, but I am having a problem accessing "Anchor" in the "Grid" effect. As you can see I am trying to test it just by accessing the name but even that doesn't work. I do not have a problem accessing for example property(4) which is "Width" and I can access the value of the same but with Anchor, I can not. Also, I would like to access each of the Anchor values [x,y] individually. Another question is the guides on/off visibility. I have used the line from "AE scripting guide 2022" but I am obviously missing something basic.

So to summarize:

1) how do I access Anchor in the Grid effect?

2) how do I access Anchor each [x,y] value individually?

3) what and I missing to enable/disable guides visibility with click on the "Visibility" button?

 

I am working in Visual Studio Code and this is what I wrote so far. Thank you in advance.

 

var window = new Window("palette", "Grid To Guides", undefined);
var startButton = window.add("button", undefined, "RUN");
var guidesVisButton = window.add("button", undefined, "VISIBILITY");


startButton.onClick = function(){
var comp = app.project.activeItem;
var layGrid = comp.selectedLayers[0];
var effX = layGrid.property("Effects").property("Grid").property(1);
var xGuideStart = comp.addGuide(1, effX.value);

alert(effX.name);
 
}
guidesVisButton.onClick = function(){
app.activeViewer.views[0].options.guidesVisibility;
}

 

 

 

 

Correct answer Mathias Moehl

you need to set the guides visibility to true to enable it:

app.activeViewer.views[0].options.guidesVisibility = true;

Or if you want to toggle it you can use

app.activeViewer.views[0].options.guidesVisibility = !app.activeViewer.views[0].options.guidesVisibility = true;

which sets it to true if it has been false before and vice versa.

 

1 reply

Mathias Moehl
Community Expert
Community Expert
June 23, 2022

Maybe my tool GridGuide is already a solution for what you need, such that you don't need to implement anything yourself? If is not using the Grid effect, but shape layers:

https://aescripts.com/gridguide-for-after-effects/

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Known Participant
June 23, 2022

Thank you, Mathias,

I have definitely seen your great tool/tools but what I am trying to do here is the following. I already have a grid automatically created by expressions based on text using Webdings square symbol. I am creating automated boxes with different numbers of rows/columns. The grid is resizing with the creation of boxes but as the grid is not snappable I wanted to create guides based on the grid so I can snap the text to the middle of each box. So far  I have figured out a few questions I asked above with the following:

 

button1.onClick = function(){
var comp = app.project.activeItem;
var layGrid = comp.selectedLayers[0];
var effA= layGrid.property("Effects").property("Grid").property(1); // anchor
var effW= layGrid.property("Effects").property("Grid").property(4); // width
var effH= layGrid.property("Effects").property("Grid").property(5); // height

var effX = effA.value[0]; // value of X anchor
var effY = effA.value[1]; // value of Y anchor
var effHor = effW.value; // value of Width
var effVer = effH.value; // value of Height

 

for (i = effX; i < 1920; i += effHor){

comp.addGuide(1, i);

}

for (i = effY; i < 1080; i += effVer){

comp.addGuide(0, i);

}
 
 
Any chance you can be generous enough to guide me on how to have "Visibility" working. Thank you in advance.

}
guidesVisButton.onClick = function(){
app.activeViewer.views[0].options.guidesVisibility;
}
Mathias Moehl
Community Expert
Mathias MoehlCommunity ExpertCorrect answer
Community Expert
June 23, 2022

you need to set the guides visibility to true to enable it:

app.activeViewer.views[0].options.guidesVisibility = true;

Or if you want to toggle it you can use

app.activeViewer.views[0].options.guidesVisibility = !app.activeViewer.views[0].options.guidesVisibility = true;

which sets it to true if it has been false before and vice versa.

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects