Skip to main content
Known Participant
June 23, 2022
Answered

AE scripting Grid to Guides

  • June 23, 2022
  • 9 replies
  • 2041 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.

 

9 replies

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;
}
Participant
March 15, 2025

The above lines to toggle on/off property work beautifully but is there any way to create the default state for example if I want to toggle on/off for the guides snap, the guides lock, and guides visibility how do I create a default that all of these values are for example off before I make the first click on the button. Thank you in advance.


You can set the values for Guides in this way:

var viewerOptions = app.activeViewer.views[0].options;
viewerOptions.guidesSnap = true;
viewerOptions.guidesLocked = false;
viewerOptions.guidesVisibility = true;

 

Here are all the available properties for the Viewer object:

// app.activeViewer
{
	"active": true,
	"activeViewIndex": 0,
	"maximized": false,
	"type": 7612,
	"views": [ // app.activeViewer.views[0]
		{
			"active": true,
			"options": { // app.activeViewer.views[0].options
				"channels": 7812, // 7812 = RGB (Default); 7813 = Red; 7814 = Green; 7815 = Blue; 7816 = Alpha; 7820 = RGB Straight;
				"checkerboards": false, // Transparency Grid
				"exposure": 0, // Reset Exposure
				"fastPreview": 8012, // 8012 = Off (Final Quality); 8012 = Adaptive Resolution; 8016 = Wireframe;
				"guidesLocked": false,
				"guidesSnap": true,
				"guidesVisibility": true,
				"rulers": false,
				"zoom": 0.5 // 0.5 = 100%; (100 / 200 = 0.5)
			}
		}
	]
}